ACH ダイレクトデビットによる支払いを受け付ける
カスタムの決済フォームを構築するか、Stripe Checkout を使用して、ACH ダイレクトデビットによる決済を受け付けます。
Web サイトでの ACH ダイレクトデビットによる決済の受け付けは、以下のように構成されます。
- 決済を追跡するためのオブジェクトを作成する
- Stripe Financial Connections によって有効化される即時確認を使用して、支払い方法の情報を収集する
- 決済を処理するために Stripe に送信する
- 顧客の銀行口座を確認する
注
ACH ダイレクトデビットは通知遅延型の支払い方法であるため、決済後すぐには売上が利用可能になりません。通常、決済金額がお客様のアカウントに入金されるまでに 4 営業日かかります。
Stripe では、Payment Intent (支払いインテント) と呼ばれる決済オブジェクトを使用して、決済が完了するまでの状態のすべてを追跡および処理します。
顧客を作成または取得する推奨サーバー側
ユーザーがビジネスでアカウントを作成する際に、Customer オブジェクトを作成するか、このユーザーに関連付けられた既存の Customer を取得します。この Customer オブジェクトの ID を、顧客を表す社内の内部表記と関連付けることで、保存されている支払い方法の詳細を後で取得して使用することができます。Financial Connections のリピートユーザーの最適化を有効にするには、Customer にメールアドレスを含めます。
PaymentIntent を作成するサーバー側
PaymentIntent (支払いインテント) は、顧客から支払いを回収する意図を表すオブジェクトで、決済プロセスのライフサイクルの各段階を追跡します。
サーバーで PaymentIntent を作成し、回収する金額と通貨 usd
を指定します。Payment Intents API を使用した実装がすでにある場合は、PaymentIntent の支払い方法タイプのリストに us_
を追加します。Customer の id を指定します。
将来その支払い方法を再利用する場合には、値を off_
に設定して setup_future_usage パラメーターを指定します。
デフォルトでは、銀行口座の支払い情報の収集では、手動の口座番号入力と少額入金の確認のフォールバックオプションを使用し、Financial Connections で顧客のアカウントを即時確認します。Financial Connections を設定し、ACH の実装を最適化するために追加の口座データにアクセスする方法については、Financial Connections に関するドキュメントをご覧ください。たとえば、Financial Connections を使用して、ACH 決済の開始前にアカウントの残高を確認できます。
注
顧客がアカウントを認証した後で、追加データにアクセスを拡張するには、権限を拡張してアカウントを再度関連付ける必要があります。
client secret を取得する
PaymentIntent には、client secret が含まれています。これは、支払いプロセスを安全に完了するためにクライアント側で使用されます。client secret をクライアント側に渡す際は、いくつかの方法を使用できます。
支払い方法の詳細を収集するクライアント側
顧客が ACH Direct Debitでの支払いをクリックしたときに、Stripe.js を使用してその支払いを Stripe に送信することをお勧めします。Stripe.js は、決済フローを構築するための Stripe の基本的な JavaScript ライブラリです。これにより、実装に関する複雑な処理が自動的に行われ、将来、他の決済手段にも対応できるように実装を簡単に拡張できます。
Stripe.js スクリプトを決済ページに含めるには、このスクリプトを HTML ファイルの head
に追加します。
<head> <title>Checkout</title> <script src="https://js.stripe.com/v3/"></script> </head>
決済ページで以下の JavaScript を使用して、Stripe.js のインスタンスを作成します。
// Set your publishable key. Remember to change this to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe(
);'pk_test_TYooMQauvdEDq54NiTphI7jx'
PaymentIntent オブジェクト全体をクライアントに送信する代わりに、前のステップからの client secret を使用します。これは、Stripe API リクエストを認証する API キーとは異なります。
client secret は支払いを完了できるため、慎重に取り扱う必要があります。記録したり、URL に埋め込んだり、当該の顧客以外に漏洩することがないようにしてください。
stripe.collectBankAccountForPayment を使用して、Financial Connections で銀行口座の詳細を収集し、PaymentMethod を作成して PaymentIntent に関連付けます。ACH ダイレクトデビットの PaymentMethod を作成するには、billing_
パラメーターに口座名義人を含める必要があります。
// Use the form that already exists on the web page. const paymentMethodForm = document.getElementById('payment-method-form'); const confirmationForm = document.getElementById('confirmation-form'); paymentMethodForm.addEventListener('submit', (ev) => { ev.preventDefault(); const accountHolderNameField = document.getElementById('account-holder-name-field'); const emailField = document.getElementById('email-field'); // Calling this method will open the instant verification dialog. stripe.collectBankAccountForPayment({ clientSecret: clientSecret, params: { payment_method_type: 'us_bank_account', payment_method_data: { billing_details: { name: accountHolderNameField.value, email: emailField.value, }, }, }, expand: ['payment_method'], }) .then(({paymentIntent, error}) => { if (error) { console.error(error.message); // PaymentMethod collection failed for some reason. } else if (paymentIntent.status === 'requires_payment_method') { // Customer canceled the hosted verification modal. Present them with other // payment method type options. } else if (paymentIntent.status === 'requires_confirmation') { // We collected an account - possibly instantly verified, but possibly // manually-entered. Display payment method details and mandate text // to the customer and confirm the intent once they accept // the mandate. confirmationForm.show(); } }); });
Financial Connections 認証フローでは、銀行口座の詳細の収集と確認を自動的に処理します。顧客が認証フローを完了すると、PaymentMethod が自動的に PaymentIntent に関連付けられ、Financial Connections アカウントが作成されます。
よくある間違い
手動入力と少額入金によって顧客が関連付けた銀行口座では、残高、所有権、取引などの追加の銀行口座データにアクセスできません。
すべてのデバイスで最適なユーザー体験を提供できるように、ビューポートの meta
タグを使用して、ページのビューポートの minimum-scale
を 1 に設定します。
<meta name="viewport" content="width=device-width, minimum-scale=1" />
同意書承認を収集し、決済を送信するクライアント側
支払いを開始する前に、顧客に同意書の規約を表示して、顧客から承認を得る必要があります。
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.
顧客が同意書の規約を承認する場合、PaymentIntent を確定する必要があります。顧客がフォームを送信したら、stripe.confirmUsBankAccountPayment を使用して支払いを完了します。
confirmationForm.addEventListener('submit', (ev) => { ev.preventDefault(); stripe.confirmUsBankAccountPayment(clientSecret) .then(({paymentIntent, error}) => { if (error) { console.error(error.message); // The payment failed for some reason. } else if (paymentIntent.status === "requires_payment_method") { // Confirmation failed. Attempt again with a different payment method. } else if (paymentIntent.status === "processing") { // Confirmation succeeded! The account will be debited. // Display a message to customer. } else if (paymentIntent.next_action?.type === "verify_with_microdeposits") { // The account needs to be verified through microdeposits. // Display a message to consumer with next steps (consumer waits for // microdeposits, then enters a statement descriptor code on a page sent to them through email). } }); });
注
stripe.confirmUsBankAccountPayment の完了には数秒かかる場合があります。この間、フォームが再送信されないように無効化し、待機中のインジケーター (スピナーなど) を表示します。エラーが発生した場合は、それを顧客に表示し、フォームを再度有効化し、待機中のインジケーターを非表示にします。
成功した場合、Stripe から以下のいずれかのステータスで PaymentIntent オブジェクトが返されます。
ステータス | 説明 | 次のステップ |
---|---|---|
requires_ | 銀行口座の確認を完了するには、追加のアクションが必要です。 | Step 6: Verifying bank accounts with microdeposits |
processing | 銀行口座が即座に確認されたか、確認が必要ありません。 | Step 7: Confirm the PaymentIntent succeeded |
After successfully confirming the PaymentIntent, 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 営業日かかります。
- 明細書表記コード。SM で始まる一意の 6 桁の
descriptor_
を指定して、0.01 USD の 1 件の少額入金を顧客の銀行口座に送金します。顧客は、この文字列を使用して、銀行口座を確認します。code - 金額。Stripe は、
ACCTVERIFY
という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は、この入金額を使用して銀行口座を確認します。
前のステップの stripe.confirmUsBankAccountPayment メソッドの呼び出しの結果として、requires_
状態の PaymentIntent が返されます。この PaymentIntent には、確認を完了するための有益な情報を含む next_
フィールドが含まれています。
next_action: { type: "verify_with_microdeposits", verify_with_microdeposits: { arrival_date: 1647586800, hosted_verification_url: "https://payments.stripe.com/…", microdeposit_type: "descriptor_code" } }
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 は新しい支払い方法の詳細を要求する状態に戻ります。少額入金とは何か、どのように使用されるのかを顧客に明確に伝えることで、確認に関する問題を回避できます。
オプション: カスタムのメール通知を送信する
Optionally, you can 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 がオンラインで提供する確認ページを使用しない場合、ご自身のサイトにフォームを作成します。顧客はこのフォームを使用して少額入金の金額を伝え、Stripe.js を使用して、銀行口座を確認します。
- 確認のために、少なくとも 6 桁のストリングの
descriptor code
パラメーターを処理するフォームを設定します。 - また、Stripe は、フォームで
amounts
パラメーターを処理するように設定することもお勧めします。顧客が利用する一部の銀行で必要になる場合があるためです。
組み込みは、
descriptor_
「または」code amounts
でのみ渡されます。組み込みでどちらが使用されているかを判断するには、next_
オブジェクトのaction verify_
の値を確認します。with_ microdeposits[microdeposit_ type] - 確認のために、少なくとも 6 桁のストリングの
stripe.verifyMicrodepositsForPayment(clientSecret, { // Provide either a descriptor_code OR amounts, not both descriptor_code: 'SMT86W', amounts: [32, 45], });
銀行口座の確認に成功すると、Stripe は PaymentIntent オブジェクトを processing
の status
で返し、payment_intent.processing Webhook イベントを送信します。
確認が失敗する原因はいくつか存在します。失敗は直接的なエラー応答で同期的に発生することも、payment_intent.payment_failed Webhook イベントを通じて非同期で発生することもあります (以下の例を参照してください)。
エラーコード | 同期または非同期 | メッセージ | ステータスの変化 |
---|---|---|---|
payment_ | 同期、または Webhook イベントを通じて非同期で発生 | 少額入金に失敗しました。指定した銀行口座、金融機関、支店の番号を確認してください | status は requires_ で、last_ が設定されます。 |
payment_ | 同期 | 指定された金額が銀行口座に送金された金額と一致しません。確認試行の残り回数は {attempts_remaining} 回です。 | 変化なし |
payment_ | 同期、または Webhook イベントを通じて非同期で発生 | 許容された確認の試行回数を超えました | status は requires_ で、last_ が設定されます。 |
payment_ | Webhook イベントを通じて非同期で発生 | 少額入金がタイムアウトになりました。顧客は要求された 10 日の期間内に銀行口座を確認しませんでした。 | status は requires_ で、last_ が設定されます。 |
PaymentIntent の成功を確認するサーバー側
ACH ダイレクトデビットは、通知遅延型の支払い方法です。このため、顧客の口座から引き落としを開始してから、決済の成功または失敗の通知を受けるまでに最大で 4 営業日かかります。
PaymentIntent を作成すると、その初期ステータスは processing
となります。決済が成功すると、PaymentIntent のステータスは processing
から succeeded
に更新されます。
Webhook を使用して決済が成功したことを確認し、顧客に決済完了を通知することをお勧めします。Stripe ダッシュボードでイベントを表示することもできます。
組み込みをテストする
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.
If your domain is “example.com,” use an email format such as info+testing@example.com for testing non-card payments. You can replace “info” with a standard local term such as “support.” This format ensures emails are routed correctly.
よくある間違い
You need to activate your Stripe account before you can trigger these emails while testing.
テスト用口座番号
Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。
口座番号 | トークン | 金融番号 | 動作 |
---|---|---|---|
000123456789 | pm_ | 110000000 | 支払いは成功します。 |
000111111113 | pm_ | 110000000 | 口座が解約済みであるため、支払いは失敗します。 |
000000004954 | pm_ | 110000000 | この支払いは、不正利用のリスクが高いため、Radar によってブロックされています。 |
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.