# Aufrufe der Stripe-App für die Salesforce-Plattform

Dieser Leitfaden enthält umsetzbare Code-Beispiele, die Sie durch wichtige Aufgaben wie das Erstellen von Stripe-Kundinnen und -Kunden, das Initiieren von Bezahlvorgängen und das Auflisten bestehender Kundinnen und Kunden führen – alles direkt in Salesforce. Diese Beispiele richten sich an Salesforce-Administratoren, -Entwickler/innen und alle, die an nahtlosen Stripe-Salesforce-Integrationen interessiert sind. Hierbei werden nutzerdefinierte Apex-Klassen für klassenbasierte Aufrufe unter Verwendung von Stripe-API-Aufrufen verwendet. Unabhängig davon, ob Sie eine neue E-Commerce-Lösung entwickeln oder Ihre Zahlungsabläufe aktualisieren, finden Sie in diesem Leitfaden alle Tools, die Sie für effiziente Stripe-Vorgänge in Salesforce benötigen.

## Einen Kunden/eine Kundin in Stripe erstellen

> #### Verwenden Sie die Accounts&nbsp;v2 API zum Darstellen von Kundinnen und Kunden
> 
> Die Accounts v2 API ist allgemein für Connect-Nutzer/innen verfügbar und für andere Stripe-Nutzer/innen in der öffentlichen Vorschau. Wenn Sie an der Accounts v2 Vorschau teilnehmen, müssen Sie eine [Vorschauversion](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning) in Ihrem Code angeben.
> 
> Um der Vorschau von Accounts v2 beizutreten, gehen Sie zu [Kontovorschauen und -funktionen](https://dashboard.stripe.com/settings/previews) in Ihrem Dashboard und aktivieren Sie **wiederverwendbare Zahlungsmethoden für Global Payouts**.
> 
> Für die meisten Anwendungsfälle empfehlen wir, [Ihre Kundinnen und Kunden als vom Kunden bzw. von der Kundin konfigurierte Account-Objekte abzubilden](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md), anstatt [Customer](https://docs.stripe.com/api/customers.md)-Objekte zu verwenden.

Mit dem folgenden Codebeispiel wird ein/e Stripe-[Kundin/Kunde](https://docs.stripe.com/api/customers.md) erstellt, für den/die ein `name`, eine `email` und `metadata` festgelegt sind.

#### Java

```java
// Step 1: Initialize an instance of the stripeGC.v01_CreateCustomers.V1 class
stripeGC.CreateCustomers.V1 params = new stripeGC.CreateCustomers.V1();
      List<stripeGC.CreateCustomers.V1> paramsCollection = new List<stripeGC.CreateCustomers.V1>{
          params
      };
// Step 2: Set the accountRecordId parameter to the record ID of the Stripe Account you wish to connect to
params.accountRecordId = 'a028B0000029RhlQAE';

// Step 3: Set the metadata field
stripeGC.Metadata metadata = new stripeGC.Metadata();
metadata.listAdditionalStringField = new List<stripeGC.AdditionalString>{
   new stripeGC.AdditionalString('AccountID', 'abc123')
};
params.metadata = metadata;

// Step 4: Set the name field
params.name = 'Tim Smith';

// Step 5: Set the email field
params.email = 'example@example.com';

// Step 6: Call the stripeGC.v01_PostCustomers.postCustomers_2022_11_15 method
List<stripeGC.Customer> customers = stripeGC.v01_CreateCustomers.createCustomers_2022_11_15(paramsCollection);
```

## Checkout-Sitzung erstellen

Das folgende Codebeispiel erstellt eine Checkout-Sitzung in Stripe:

#### Java

```java
// Step 1: Initialize an instance of the stripeGC.v01_CreateCheckoutSessions.V1 class
stripeGC.CreateCheckoutSessions.V1 params = new stripeGC.CreateCheckoutSessions.V1();
      List<stripeGC.CreateCheckoutSessions.V1> paramsCollection = new List<stripeGC.CreateCheckoutSessions.V1>{
          params
      };
// Step 2: Set the accountRecordId parameter to the record ID of the Stripe Account you wish to connect to
params.accountRecordId = 'a028B0000029RhlQAE';

// Step 3: Set the checkout line items
stripeGC.CreateCheckoutSessionsReqLineItem cliparams = new stripeGC.CreateCheckoutSessionsReqLineItem();
cliparams.price = 'price_1NhcVkBSPQ8HL343ZNsBp'; //price id from Stripe.
cliparams.quantity = 1;
List<stripeGC.CreateCheckoutSessionsReqLineItem> cliparamlist = new List<stripeGC.CreateCheckoutSessionsReqLineItem>();
cliparamlist.add(cliparams);
params.lineItems = cliparamlist;

// Step 4: Set mode,successurl,client ref fields
params.mode = 'payment';
params.successUrl = 'https://stripe.com';
params.clientReferenceId = 'abcd123';

// Step 5: Call the stripeGC.v01_CreateCheckoutSessions.CreateCheckoutSessions_2022_11_15 method
List<stripeGC.CheckoutSession> results = stripeGC.v01_CreateCheckoutSessions.createCheckoutSessions_2022_11_15(paramsCollection);

```

### Kundinnen/Kunden auflisten

Mit dem folgenden Codebeispiel werden Ihre sämtlichen Kundinnen/Kunden aufgelistet, die in Stripe gespeichert sind:

```java
// Step 1: Initialize an instance of the stripeGC.v01_ListCustomers.V1 class
stripeGC.ListCustomers.V1 params = new stripeGC.ListCustomers.V1();
List<stripeGC.ListCustomers.V1> paramsCollection = new List<stripeGC.ListCustomers.V1>{
   params
};

// Step 2: Set the accountRecordId parameter to the record ID of the Stripe Account you wish to connect to
params.accountRecordId = 'a028B0000029RhlQAE';

// Step 3: Call the stripeGC.v01_ListCustomers.listCustomers_2022_11_15 method
List<stripeGC.CustomerResourceCustomerList > results = stripeGC.v01_ListCustomers.listCustomers_2022_11_15(paramsCollection);
System.debug(results[0]);

```

## See also

- [Installationsleitfaden](https://docs.stripe.com/use-stripe-apps/stripe-app-for-salesforce/installation-guide.md)
- [Aktivierungsvideos](https://docs.stripe.com/use-stripe-apps/stripe-app-for-salesforce/training.md)
- [Ereignisse konfigurieren](https://docs.stripe.com/use-stripe-apps/stripe-app-for-salesforce/configure-events.md)
