ACH ダイレクトデビットによる将来の支払いに備えて詳細を保存する
将来の ACH ダイレクトデビットによる支払いに備えて支払い方法の詳細を保存する方法を紹介します。
You can use the Setup Intents API to collect payment method details in advance, with the final amount or payment date determined later. This is useful for:
- Saving payment methods to a wallet to streamline future purchases
- Collecting surcharges after fulfilling a service
- Starting a free trial for a subscription
注
ACH Direct Debit is a delayed notification payment method, which means that funds aren’t immediately available after payment. A payment typically takes 4 business days to arrive in your account.
Stripe Android SDK はオープンソースであり、詳細なドキュメントが提供されています。
To install the SDK, add stripe-android
and financial-connections
to the dependencies
block of your app/build.gradle file:
注
SDK の最新リリースおよび過去バージョンの詳細については、GitHub の Releases ページをご覧ください。新しいリリースの公開時に通知を受け取るには、リポジトリのリリースを確認してください。
Stripe の公開可能キーを使用して SDK を設定し、 Application
サブクラスなどで、Stripe API へのリクエストを実行できるようにします。
顧客を作成または取得する推奨サーバー側
ユーザーがビジネスでアカウントを作成する際に、Customer オブジェクトを作成するか、このユーザーに関連付けられた既存の Customer を取得します。この Customer オブジェクトの ID を、顧客を表す社内の内部表記と関連付けることで、保存されている支払い方法の詳細を後で取得して使用することができます。Financial Connections のリピートユーザーの最適化を有効にするには、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 us_bank_account and specify the Customer’s id.
デフォルトでは、銀行口座の支払い情報の収集では、手動の口座番号入力と少額入金の確認のフォールバックオプションを使用し、Financial Connections で顧客のアカウントを即時確認します。Financial Connections を設定し、ACH の実装を最適化するために追加の口座データにアクセスする方法については、Financial Connections に関するドキュメントをご覧ください。たとえば、Financial Connections を使用して、ACH 決済の開始前にアカウントの残高を確認できます。
注
顧客がアカウントを認証した後で、追加データにアクセスを拡張するには、権限を拡張してアカウントを再度関連付ける必要があります。
クライアント側
返された SetupIntent には、client secret が含まれています。これは、SetupIntent オブジェクト全体を渡すことなく安全に設定を完了するために、クライアント側で使用されます。client secret をクライアント側に渡す際は、いくつかの方法を使用できます。
支払い方法の詳細を収集するクライアント側
ACH ダイレクトデビットで決済を成功させるには、顧客の氏名と (オプションで) メールアドレスが必要です。アプリで、必要な請求詳細を顧客から収集します。
- 顧客の氏名 (姓と名)
- 顧客のメールアドレス
CollectBankAccountConfiguration.
を使用し、presentWithSetupIntent
を呼び出すために必要なパラメーターを作成します。
決済アクティビティーの onCreate 内で CollectBankAccountLauncher インスタンスを初期化して、結果を処理するためのメソッドを渡します。次に、presentWithSetupIntent
を呼び出して銀行口座情報を収集し、PaymentMethod を作成して SetupIntent に関連付けます。
This loads a modal UI that handles bank account details collection and verification. When it completes, the PaymentMethod automatically attaches to the SetupIntent.
同意書承認を収集し送信するクライアント側
SetupIntent を完了して顧客の支払い方法の詳細を保存する前に、同意書の規約を表示して支払いに対する承認を得る必要があります。
To be compliant with Nacha rules, you must obtain authorization from your customer before you can initiate payment by displaying mandate terms for them to accept. For more information on mandates, see Mandates.
顧客が同意書の規約を承認する際、Setup を確定する必要があります。顧客がフォームを送信したら、confirm
を使用して決済を完了します。
注
confirm
が完了するまでには数秒かかる場合があります。この間、フォームが再送信されないように無効化し、待機中のインジケーター (スピナーなど) を表示します。エラーが発生した場合には顧客に表示して、フォームを再度有効化し、待機中のインジケーターを非表示にします。
成功した場合、Stripe から以下のいずれかのステータスで SetupIntent オブジェクトが返されます。
ステータス | 説明 | 次のステップ |
---|---|---|
succeeded | 銀行口座が即座に確認されたか、確認が不要でした。 | アクションは不要です |
requires_ | 銀行口座の確認を完了するには、追加のアクションが必要です。 | Step 6: Verifying bank accounts with microdeposits |
After successfully confirming the Setup, an email confirmation of the mandate and collected bank account details must be sent to your customer. Stripe handles these by default, but you can choose to send custom notifications if you prefer.
少額入金で銀行口座を確認するクライアント側
すべての顧客が銀行口座を即時に確認できるわけではありません。このステップは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。
このような場合、Stripe は descriptor_
による少額入金を送金し、銀行口座の確認でさらに問題が発生した場合には、amount
による少額入金に戻る場合があります。これらの入金が顧客のオンライン明細書に表示されるには 1 ~ 2 営業日かかります。
- 明細書表記コード。Stripe は、SM で始まる一意の 6 桁の
descriptor_
を使用し、0.01 USD の 1 件の少額入金を顧客の銀行口座に送金します。顧客は、この文字列を使用して銀行口座を確認します。code - 金額。Stripe は、
ACCTVERIFY
という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は、この入金額を使用して銀行口座を確認します。
The result of the confirmSetupIntent
method call in the previous step is a SetupIntent in the requires_
state. The SetupIntent contains a next_action field that contains some useful information for completing the verification.
If you supplied a billing email, Stripe notifies your customer through this email when the deposits are expected to arrive. The email includes a link to a Stripe-hosted verification page where they can confirm the amounts of the deposits and complete verification.
警告
確認の失敗は、明細書表記ベースの少額入金の場合は 10 回、金額ベースの少額入金の場合は 3 回までです。この上限を超えると、Stripe は銀行口座を確認できなくなります。また、少額入金の確認は 10 日経過するとタイムアウトになります。この期間内に少額入金を確認できなかった場合、PaymentIntent は新しい支払い方法の詳細を要求する状態に戻ります。少額入金とは何か、どのように使用されるのかを顧客に明確に伝えることで、確認に関する問題を回避できます。
オプション: カスタムのメール通知を送信する
You can also send custom email notifications to your customer. After you set up custom emails, you need to specify how the customer responds to the verification email. To do so, choose one of the following:
Use the Stripe-hosted verification page. To do this, use the
verify_
URL in the next_action object to direct your customer to complete the verification process.with_ microdeposits[hosted_ verification_ url] Stripe がオンラインで提供する確認ページを使用しない場合には、ご自身のアプリにフォームを作成します。顧客はこのフォームを使用して少額入金の金額を伝え、Android SDK を使用して銀行口座を確認します。
- 少なくとも
descriptor code
パラメーター (確認のための 6 桁の文字列) を処理するフォームを設定します。 - また Stripe では、
amounts
パラメーターも処理するようにフォームを設定することをお勧めします。これはこのパラメーターが、顧客が利用する一部の銀行で必要とされることがあるためです。
組み込みは、
descriptor_
「または」code amounts
のみを渡します。組み込みでどちらが使用されるかを判断するには、next_
オブジェクトのaction verify_
の値を確認します。with_ microdeposits[microdeposit_ type] - 少なくとも
銀行口座の確認が成功すると、Stripe は、succeeded
の status
の SetupIntent オブジェクトを返します。
確認が失敗する理由はいくつかあります。失敗は、直接的なエラー応答として同期的に発生します。
{ "error": { "code": "payment_method_microdeposit_verification_amounts_mismatch", "message": "The amounts provided do not match the amounts that were sent to the bank account. You have {attempts_remaining} verification attempts remaining.", "type": "invalid_request_error" } }
エラーコード | メッセージ | ステータスの変化 |
---|---|---|
payment_ | 少額入金に失敗しました。指定した銀行口座、金融機関、支店の番号を確認してください。 | status は requires_ で、last_ が設定されます。 |
payment_ | 指定された金額が銀行口座に送金された金額と一致しません。確認試行の残り回数はあと {attempts_remaining} 回です。 | 変化なし |
payment_ | 許容された確認の試行回数を超えました。 | status は requires_ で、last_ が設定されます。 |
組み込みをテストする
Financial Connections を使用して即時確認を行うシナリオをテストする方法をご紹介します。
Send transaction emails in a sandbox
After you collect the bank account details and accept a mandate, send the mandate confirmation and microdeposit verification emails in a sandbox. To do this, provide an email in the payment_
field in the form of {any-prefix}+test_
when you collect the payment method details.
よくある間違い
You need to activate your Stripe account before you can trigger these emails while testing.
テスト用口座番号
Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。
口座番号 | トークン | 金融番号 | 動作 |
---|---|---|---|
000123456789 | pm_ | 110000000 | 支払いは成功します。 |
000111111113 | pm_ | 110000000 | 口座が解約済みであるため、支払いは失敗します。 |
000111111116 | pm_ | 110000000 | 口座が見つからないため、支払いは失敗します。 |
000222222227 | pm_ | 110000000 | 残高不足のため、支払いは失敗します。 |
000333333335 | pm_ | 110000000 | 引き落としがオーソリされていないため、支払いは失敗します。 |
000444444440 | pm_ | 110000000 | 通貨が無効であるため、支払いは失敗します。 |
000666666661 | pm_ | 110000000 | 支払いで少額入金の送金が失敗します。 |
000555555559 | pm_ | 110000000 | 支払いによって不審請求の申請が開始されています。 |
000000000009 | pm_ | 110000000 | 支払いは無期限に処理中のままになります。これは PaymentIntent のキャンセルをテストするのに便利です。 |
000777777771 | pm_ | 110000000 | The payment fails due to payment amount causing the account to exceed its weekly payment volume limit. |
テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。
少額入金の金額と明細書表記コードをテストする
さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。
少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ |
---|---|---|
32 および 45 | SM11AA | アカウントの確認をシミュレーションします。 |
10 および 11 | SM33CC | 許容された確認回数の超過をシミュレーションします。 |
40 および 41 | SM44DD | 少額入金のタイムアウトをシミュレーションします。 |
Test settlement behavior
Test transactions settle instantly and are added to your available test balance. This behavior differs from livemode, where transactions can take multiple days to settle in your available balance.
将来の決済を受け付けるサーバー側
When the SetupIntent succeeds, it will create a new PaymentMethod attached to a Customer. These can be used to initiate future payments without having to prompt the customer for their bank account a second time.