Customer Sheet を導入する
顧客が保存済みの支払い方法を管理できる事前構築済みの UI を提供します。
The Customer Sheet is a prebuilt UI component that lets your customers manage their saved payment methods. You can use the Customer Sheet UI outside of a checkout flow, and the appearance and styling is customizable to match the appearance and aesthetic of your app. Customers can add and remove payment methods, which get saved to the customer object, and set their default payment method stored locally on the device. Use both the Mobile Payment Element and the Customer Sheet to provide customers a consistent end-to-end solution for saved payment methods.
CustomerAdapter は Customer Ephemeral Keys (顧客の一時キー) を使用することで、レガシープロダクトのユーザーがよりスピーディに CustomerSheet を導入できるようにサポートします。新しい実装を開始する場合は、顧客の一時キーよりも CustomerSession を採用することをお勧めします。
Stripe を設定する
まず、Stripe アカウントが必要です。今すぐご登録ください。
Stripe iOS SDK はオープンソースです。詳細なドキュメントが提供されており、iOS 13 以降をサポートするアプリと互換性があります。
注
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
アプリの起動時に Stripe 公開可能キーを使用して SDK を設定します。これにより、アプリが Stripe API にリクエストを送信できるようになります。
支払い方法を有効にする
支払い方法の設定を表示して、サポートする支払い方法を有効にします。SetupIntent を作成するには、少なくとも 1 つは支払い方法を有効にする必要があります。
By default, Stripe enables cards and other prevalent payment methods that can help you reach more customers, but we recommend turning on additional payment methods that are relevant for your business and customers. See Payment method support for product and payment method support, and our pricing page for fees.
注
現時点では、CustomerSheet はカードとアメリカの銀行口座のみに対応しています。
Customer エンドポイントを追加するサーバー側
Create two endpoints on your server: one for fetching a Customer’s ephemeral key, and one to create a SetupIntent for saving a new payment method to the Customer.
- Create an endpoint to return a Customer ID and an associated ephemeral key. You can view the API version used by the SDK here.
- Create an endpoint to return a SetupIntent configured with the Customer ID.
If you only plan to use the payment method for future payments when your customer is present during the checkout flow, set the usage parameter to on_session to improve authorization rates.
Customer アダプターを作成するクライアント側
A StripeCustomerAdapter
enables a CustomerSheet
to communicate with Stripe. On the client, configure a StripeCustomerAdapter
with providers that make requests to these endpoints on your server.
import StripePaymentSheet let customerAdapter = StripeCustomerAdapter(customerEphemeralKeyProvider: { let json = await myBackend.getCustomerEphemeralKey() return CustomerEphemeralKey(customerId: json["customerId"]!, ephemeralKeySecret: json["ephemeralKeySecret"]!) }, setupIntentClientSecretProvider: { let json = await myBackend.getSetupIntentForCustomer() return json["setupIntentClientSecret"]! })
画面を設定する
Next, configure the Customer Sheet with your StripeCustomerAdapter
and a CustomerSheet.Configuration.
var configuration = CustomerSheet.Configuration() // Configure settings for the CustomerSheet here. For example: configuration.headerTextForSelectionScreen = "Manage your payment method" let customerSheet = CustomerSheet(configuration: configuration, customer: customerAdapter)