将来の Cash App Pay による支払いを設定する
Cash App Pay の詳細を保存し、後で顧客に請求する方法をご紹介します。
You can use the Setup Intents API to collect payment method details in advance, and determine the final amount or payment date later. Use it to:
- 支払い方法をウォレットに保存して、以降の購入を効率化する
- サービスの提供後に追加料金を回収する
- Start a free trial for a subscription
このガイドでは、最初に Setup Intents API を使用して支払い方法の詳細を保存し、Payment Intents API を使用して保存した支払い方法に後で請求する方法を説明します。
Stripe を設定するサーバ側クライアント側
まず、Stripe アカウントが必要です。今すぐ登録してください。
サーバ側
この組み込みには、サーバ上に Stripe API と通信するエンドポイントが必要です。サーバから Stripe API にアクセスするには、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 にリクエストを送信できるようになります。
Customer を作成または取得するサーバー側
今後の支払いに備えて Cash App Pay の支払い方法を保存するには、これを Customer に関連付ける必要があります。
お客様のビジネスで顧客がアカウントを作成するときに、Customer オブジェクトを作成します。この Customer オブジェクトの ID を、顧客を表す独自の内部表記と関連付けてください。あるいは、Customer オブジェクトを作成してから、今後の支払いのために支払い方法を保存することもできます。
新しい Customer を作成するには、サーバー側で以下のコードを含めます。
SetupIntent を作成するサーバー側
A SetupIntent is an object that represents your intent to set up a customer’s payment method for future payments. The SetupIntent tracks the steps of this set-up process. Create a SetupIntent on your server with payment_method_types set to cashapp
and specify the Customer’s ID and usage=off_session or usage=on_
.
決済フォームに承認に関する条件を提示するクライアント側
Save your customer’s Cash App Pay credentials($Cashtag) to charge their account for future, off-session payments. Your custom payment form must present a written notice of authorization before confirming the PaymentIntent or SetupIntent.
承認に関する条件は、顧客の $Cashtag を初めて保存するときにのみ表示する必要があります。
カスタムの決済フォームでは以下のテキストを使用することをお勧めします。
続行すると、Rocket Rides の利用規約に従って、この許可が取り消されない限り、お客様は今回の支払いおよび今後の支払いを、Cash App のアカウントから引き落とすことを Rocket Rides に許可したものとみなされます。これは、Cash App の設定でいつでも変更できます。
Stripe に支払いを送信するクライアント側
作成した SetupIntent から client secret を取得し、STPPaymentHandler confirmSetupIntent を呼び出します。これにより WebView が表示され、顧客はそこから Cash App で支払いを完了できます。その後、支払い結果とともに、完了ブロックが呼び出されます。
保存された支払い方法を使用して PaymentIntent を作成するサーバー側
After you create a PaymentMethod, you can accept future Cash App Pay payments by creating and confirming a PaymentIntent. When confirming a PaymentIntent, use the same payment method ID from the previous SetupIntent or PaymentIntent object. The off_
value must also be set to true if the customer isn’t in a checkout flow for this PaymentIntent.
再利用可能な決済手段の取り消しを処理する
There are two ways to revoke a reusable payment method:
- A customer can deactivate a reusable payment method in the Cash App mobile application. In this case, Stripe sends a mandate.updated event. Subscribe to webhook events, and call detach PaymentMethod to deactivate it.
- A customer can also deactivate a reusable payment method on your UI, if supported. In this case, your server can call detach PaymentMethod to deactivate it.
In both cases, after you call the detach PaymentMethod, a payment_method.detached event is sent to you.