# Beispiel für die Stripe-App fur Salesforce-Plattform AgnosticInvocable – Beispiel Dieser Leitfaden enthält umsetzbare Code-Beispiele, die Schritt für Schritt zeigen, wie Stripe-Kundinnen und -Kunden und PaymentIntents direkt in Salesforce erstellt werden können. Wenn Sie ein Salesforce-Administrator oder eine/e Entwickler/in sind oder einfach Stripe und Salesforce verbinden möchten, um einen reibungslosen Datenfluss und eine reibungslose Transaktionsabwicklung zu gewährleisten, sind Sie hier genau richtig. Bei den hier aufgeführten Beispielen werden nutzerdefinierte Apex-Klassen genutzt, um generische, agnostische Aufrufe der RESTful API von Stripe zu ermöglichen. Diese Beispiele sind praktisch, wenn Sie eine Abstraktionsebene zwischen Ihrer Salesforce-Plattform und der Stripe-API erstellen möchten, um Ihr System flexibler und einfacher zu verwalten. ## Einen Kunden/eine Kundin in Stripe erstellen > #### Verwenden Sie die Accounts 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 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 Zugriff auf die Accounts v2 Vorschau anzufordern, {% collect-email modal=true modal_link_text=“sign up.” list=“payin-payout-reuse-waitlist@stripe.com” send_direct_email=true intro_text=“Sind Sie am frühzeitigen Zugang zur Vorschau der Accounts v2 API interessiert?" body_text=“Wir sind gerade dabei, die Vorschau von Accounts v2 bereitzustellen. Um Zugang zu beantragen, geben Sie unten Ihre E-Mail-Adresse ein.” form_cta_text=“Registrieren” success_text=“Danke! Wir melden uns bald.” show_email_confirmation=wahr /%} > > 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: Create an instance of the stripeGC.RawInvocableParameters class. This class is used to set the parameters for the Stripe API call. stripeGC.RawInvocableParameters parameters = new stripeGC.RawInvocableParameters(); // Step 2: Set the HTTP method to 'POST' as you are creating a new customer. parameters.method = 'POST'; // Step 3: Set the endpoint to '/v1/customers'. This is the Stripe API endpoint for creating a new customer. parameters.endpoint = '/v1/customers'; //Step 4: Set the Stripe Account ID from Salesforce and set it to the accountId field of the parameters object. parameters.accountId = 'a028B0000029RhlQAE'; //Step 5: Set the request body with the customer details. List postCustomerParameters = new List{ 'email=' + 'customerEmail@example.com', 'name=' + 'Tim Smith', 'metadata[AccountId]=' + 'abc123' }; parameters.requestBody = String.join(postCustomerParameters, '&'); //Step 6: Add the parameters object to a list and call the callStripeEndpoint method of the stripeGC.AgnosticInvocable class. List paramsCollection = new List{ parameters }; List results = stripeGC.AgnosticInvocable.callStripeEndpoint(paramsCollection); //Step 7: The callStripeEndpoint method will return a list of strings. If the customer was created successfully, the first string in the list will be the ID of the new customer. System.debug(results[0]); ``` ### Einen PaymentIntent erstellen Mit diesem Codebeispiel wird ein paymentIntent in Stripe erstellt. #### Java ```java public class stripePayment { @AuraEnabled(cacheable=true) public static String paymentIntent(String StripeAccountID, String amount, String stripecurrency, String orderID, String onBehalfOf, String customerId) { // Create Call for invocable stripeGC.RawInvocableParameters parameters = new stripeGC.RawInvocableParameters(); // Add HTTP Method parameters.method = 'POST'; // Add endpoint parameters.endpoint = '/v1/payment_intents'; // Get the Stripe Account ID from Salesforce // This assumes you already have the Stripe Account ID and will pass it in as a parameter // Alternately, you could use a SOQL query to obtain the Stripe Account ID as per previous examples parameters.accountId = StripeAccountID; parameters.connectAccount = onBehalfOf; // Prepare the request body List postPaymentIntentParameters = new List{ 'amount=' + amount, // Pass in the amount to be charged for this PaymentIntent in the minimum currency unit (for example, cents for USD) 'currency=' + stripecurrency, // Pass in the currency for this PaymentIntent (for example, 'usd' for USD) 'customer=' + customerId, // Pass in customer to PaymentIntent 'automatic_payment_methods[enabled]=true', //Turning on automatic payment methods 'metadata[order_id]=' + orderID }; parameters.requestBody = String.join(postPaymentIntentParameters, '&'); List paramsCollection = new List{ parameters }; List results = stripeGC.AgnosticInvocable.callStripeEndpoint(paramsCollection); return (results != null && results.size() > 0) ? results[0] : null; } } ``` ## See also - [Installationsanleitung](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)