# Stripe app for Salesforce Platform の呼び出し

このガイドではすぐに使用できるコード例を用いて、Stripe の顧客の作成、Checkout セッションの開始、既存の顧客のリッスンといった重要な作業をすべて Salesforce から直接実行する手順を説明します。Salesforce の管理者、開発者、そして Stripe と Salesforce のシームレスな連携に関心をお持ちの方を対象としています。これらの例では、Stripe API コールを使用したクラスベースの呼び出しに、カスタム Apex クラスを用いています。新たな EC ストアソリューションを構築している場合でも、決済ワークフローを構築している場合でも、このガイドは Salesforce での効率的な Stripe 操作に必要なツールを提供します。

## Stripe で顧客を作成する

> #### Accounts v2 API を使用した顧客の表現
> 
> Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。
> 
> Accounts v2 のプレビューに参加するには、ダッシュボードの [Account previews and features](https://dashboard.stripe.com/settings/previews) に移動して、**Global Payouts の再利用可能な決済手段**を有効にします。
> 
> ほとんどのユースケースでは、[Customer](https://docs.stripe.com/api/customers.md) オブジェクトを使用するのではなく、[顧客を顧客設定済みの Account オブジェクトとしてモデル化する](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md)ことをお勧めします。

次のコード例では、`name`、`email`、`metadata` を設定して Stripe の[顧客](https://docs.stripe.com/api/customers.md)を作成します。

#### 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 セッションを作成する

次のコード例は Stripe で Checkout セッションを作成します。

#### 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);

```

### 顧客をリストに表示する

次のコード例は、Stripe に保存されているすべての顧客をリストに表示します。

```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

- [インストールガイド](https://docs.stripe.com/use-stripe-apps/stripe-app-for-salesforce/installation-guide.md)
- [イネーブルメントビデオ](https://docs.stripe.com/use-stripe-apps/stripe-app-for-salesforce/training.md)
- [イベントを設定](https://docs.stripe.com/use-stripe-apps/stripe-app-for-salesforce/configure-events.md)
