# ACH ダイレクトデビットによる支払いを受け付ける カスタムの決済フォームを構築するか、Stripe Checkout を使用して、ACH ダイレクトデビットによる決済を受け付けます。 # Checkout > This is a Checkout for when payment-ui is checkout. View the full page at https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=checkout. > Stripe は、通貨、支払い方法の制限、その他のパラメーターを評価することで、適切な支払い方法を顧客に自動的に提示できます。 > > - [決済の受け付け](https://docs.stripe.com/payments/accept-a-payment.md?payment-ui=checkout&ui=stripe-hosted)ガイドに従って、[動的な決済手段](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md)を使用するチェックアウトの統合機能を構築します。 - 動的な決済手段を使用しない場合は、チェックアウトの導入で、決済方法を手動で設定するために以下のステップに従ってください。 アメリカの Stripe ユーザーは、支払いモードで Checkout を使用して、ACH ダイレクトデビットによる決済を受け付けることができます。 Checkout Session は、顧客の購買意図の詳細を表すものです。お客様は、顧客が何らかに対する支払いを行おうとしたときに Session を作成します。顧客が Checkout セッションにリダイレクトされると、Stripe は決済フォームを表示し、顧客はそこで購入を完了できます。顧客が購入を完了すると、元のサイトにリダイレクトされます。 Checkout を使用すると、支払い方法タイプとして `us_bank_account` を指定して Checkout セッションを作成し、決済が完了するまでそのステータスを追跡ならびに処理できます。 > ACH ダイレクトデビットは[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法であるため、決済後すぐには売上が利用可能になりません。通常、決済金額がお客様のアカウントに入金されるまでに 4 営業日かかります。 ## 互換性を判断する **サポート対象のビジネスの所在地**: US **対応可能な通貨**: `usd` **取引通貨**: `usd` **支払いモード**: Yes **セットアップモード**: Yes **サブスクリプションモード**: Yes ACH Direct Debit 支払いをサポートするには、すべての明細項目で *Prices* (Prices define how much and how often to charge for products. This includes how much the product costs, what currency to use, and the interval if the price is for subscriptions) を米ドル (通貨コード `usd` で表記するようにしてください。 ## 顧客を作成または取得する [推奨] [サーバー側] > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. #### Accounts v2 ユーザーがあなたのビジネスでアカウントを作成したときに、顧客が設定する [Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer) オブジェクトを作成するか、このユーザーに関連付けられた既存の `Account` を取得します。`Account` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Account` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "{{CUSTOMER_EMAIL}}" }' ``` #### Customers v1 ユーザーがあなたのビジネスでアカウントを作成したときに、*Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments)オブジェクトを作成するか、このユーザーに関連付けられた既存の `Customer` を取得します。`Customer` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Customer` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d email={{CUSTOMER_EMAIL}} ``` ## 決済を受け付ける > このガイドを使用する前に、まず Checkout で[決済を受け付ける](https://docs.stripe.com/payments/accept-a-payment.md?integration=checkout)実装を構築します。 このガイドでは、ACH Direct Debit を有効にする方法について手順を追って説明し、動的な決済手段を使用して決済を受け付ける場合と決済手段を手動で設定する場合の違いを示します。 ### 支払い方法として ACH ダイレクトデビットを有効にする 新しい [Checkout セッション](https://docs.stripe.com/api/checkout/sessions.md)を作成する際は、以下を行う必要があります。 1. `us_bank_account` を `payment_method_types` のリストに追加します。 1. すべての `line_items` が `usd` 通貨を使用していることを確認します。 #### Stripe がオンラインで提供するページ #### Accounts v2 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ --data-urlencode "success_url=https://example.com/success" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ --data-urlencode "success_url=https://example.com/success" ``` #### 完全埋め込みページ #### Accounts v2 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ --data-urlencode "return_url=https://example.com/return" \ -d ui_mode=embedded_page ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ --data-urlencode "return_url=https://example.com/return" \ -d ui_mode=embedded_page ``` Financial Connections 手数料の詳細については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 デフォルトでは、銀行口座の支払い情報の収集では、手動の口座番号入力と少額入金の確認のフォールバックオプションを使用し、[Financial Connections](https://docs.stripe.com/financial-connections.md) で顧客のアカウントを即時確認します。Financial Connections を設定し、ACH の実装を最適化するために追加の口座データにアクセスする方法については、[Financial Connections に関するドキュメント](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md)をご覧ください。たとえば、Financial Connections を使用して、ACH 決済の開始前にアカウントの残高を確認できます。 > 顧客がアカウントを認証した後で、追加データにアクセスを拡張するには、権限を拡張してアカウントを再度関連付ける必要があります。 顧客が Financial Connections ではなく少額入金による確認を選択した場合、Stripe は指定された銀行口座に 2 件の少額入金を送金します。この入金が顧客のオンライン銀行明細書に表示されるまでには 1 ~ 2 営業日かかります。入金の到着予定日に、入金額の確認と Stripe での銀行口座確認を行うためのリンクが記載されたメールが顧客に届きます。確認が完了すると、決済の処理が開始されます。 ACH Direct Debit の支払いモードのセッションを作成する際には、`off_session` の値を指定して [payment_intent_data.setup_future_usage](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-setup_future_usage) パラメーターを含めることをお勧めします。それにより[決済手段の詳細を保存](https://docs.stripe.com/payments/accept-a-payment.md?payment-ui=checkout&ui=stripe-hosted#save-payment-method-details)できます。 ### 注文のフルフィルメントを実行する 決済の受け付け後に、[注文のフルフィルメントを履行](https://docs.stripe.com/checkout/fulfillment.md)する方法を説明します。 ## 連携をテストする [Financial Connections](https://docs.stripe.com/financial-connections/testing.md#web-how-to-use-test-accounts) を使用して即時確認を行うシナリオをテストする方法をご紹介します。 ### サンドボックスで取引メールを送信する 銀行口座の詳細を収集し、同意書を受け付けたら、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で同意書の確認メールと少額入金の確認メールを送信します。 ドメインが **{domain}** で、ユーザー名が **{username}** の場合、メール形式 **{username}+test\_email@{domain}** を使用してテスト取引メールを送信します。 たとえば、ドメインが **example.com** でユーザー名が **info** の場合、ACH Direct Debit 決済のテストには **info+test\_email@example.com** という形式を使用します。この形式により、メールが正しくルーティングされます。**+test\_email** サフィックスを含めない場合、メールは送信されません。 > テスト中にこれらのメールをトリガーする前に、Stripe [アカウントを設定](https://docs.stripe.com/get-started/account/set-up.md)する必要があります。 ### テスト用口座番号 Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。 | 口座番号 | トークン | 金融番号 | 動作 | | -------------- | -------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------- | | `000123456789` | `pm_usBankAccount_success` | `110000000` | 支払いは成功します。 | | `000111111113` | `pm_usBankAccount_accountClosed` | `110000000` | 口座が解約済みであるため、支払いは失敗します。 | | `000000004954` | `pm_usBankAccount_riskLevelHighest` | `110000000` | この支払いは、[不正利用のリスクが高い](https://docs.stripe.com/radar/risk-evaluation.md#high-risk)ため、Radar によってブロックされています。 | | `000111111116` | `pm_usBankAccount_noAccount` | `110000000` | 口座が見つからないため、支払いは失敗します。 | | `000222222227` | `pm_usBankAccount_insufficientFunds` | `110000000` | 残高不足のため、支払いは失敗します。 | | `000333333335` | `pm_usBankAccount_debitNotAuthorized` | `110000000` | 引き落としがオーソリされていないため、支払いは失敗します。 | | `000444444440` | `pm_usBankAccount_invalidCurrency` | `110000000` | 通貨が無効であるため、支払いは失敗します。 | | `000666666661` | `pm_usBankAccount_failMicrodeposits` | `110000000` | 支払いで少額入金の送金が失敗します。 | | `000555555559` | `pm_usBankAccount_dispute` | `110000000` | 支払いによって不審請求の申請が開始されています。 | | `000000000009` | `pm_usBankAccount_processing` | `110000000` | 支払いは無期限に処理中のままになります。 [PaymentIntent キャンセル](https://docs.stripe.com/api/payment_intents/cancel.md) をテストするのに役立ちます。 | | `000777777771` | `pm_usBankAccount_weeklyLimitExceeded` | `110000000` | 支払い額がアカウントの週次支払い額の上限を超えているため、支払いが失敗しました。 | | `000888888885` | | `110000000` | [トークン化されたアカウント番号](https://docs.stripe.com/financial-connections/tokenized-account-numbers.md)が無効化されると決済が失敗します。 | テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。 ### 少額入金の金額と明細書表記コードをテストする さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。 | 少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ | | ------------- | --------------- | ------------------------- | | `32` および `45` | SM11AA | アカウントの確認をシミュレーションします。 | | `10` および `11` | SM33CC | 許容された確認回数の超過をシミュレーションします。 | | `40` および `41` | SM44DD | 少額入金のタイムアウトをシミュレーションします。 | ### 売上処理の動作をテストする テスト取引は即座に売上として処理され、利用可能なテスト残高に追加されます。この動作は、利用可能な残高で取引が売上として処理されるまでに[数日](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#timing)かかることがある、本番環境とは異なります。 ## その他の考慮事項 ### 少額入金確認の失敗 銀行口座で少額入金による確認が進行中のときに、顧客は次の 3 つの理由で確認に失敗することがあります。 - 少額入金を顧客の銀行口座に送金できなかった (これは通常、銀行口座が解約済みまたは使用不可であるか、銀行口座番号が不正確である場合に発生します)。 - 顧客が口座の確認に 10 回失敗した。この試行回数の上限を超えると、その銀行口座は確認することも、再利用することもできなくなります。 - 顧客が 10 日以内に銀行口座を確認しなかった。 これらのいずれかの理由で銀行口座の確認に失敗した場合、[`checkout.session.async_payment_failed` イベントを処理](https://docs.stripe.com/api/events/types.md?event_types-invoice.payment_succeeded=#event_types-checkout.session.async_payment_failed)して、新たに注文を行うよう顧客に連絡できます。 ## Optional: 即時の確認のみ デフォルトでは、ACH Direct Debit 決済により、顧客は銀行口座の即時確認または少額入金を利用できます。オプションとして、Checkout Session を作成するときに `payment_method_options[us_bank_account][verification_method]` パラメータを使用して、銀行口座の即時確認を必須にすることもできます。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d mode=payment \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][0]=payment_method" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][quantity]=1" \ --data-urlencode "success_url=https://example.com/success" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d mode=payment \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][0]=payment_method" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][quantity]=1" \ --data-urlencode "success_url=https://example.com/success" ``` ## Optional: Financial Connections 銀行口座のデータにアクセスする PaymentIntent の作成時に、追加の[データ権限](https://docs.stripe.com/financial-connections/fundamentals.md#data-permissions)をリクエストする場合にのみ、Financial Connections データにアクセスできます。 顧客が決済フローを完了すると、返される `us_bank_account` PaymentMethod には、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)を指す [financial_connections_account](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-us_bank_account-financial_connections_account) ID が含まれます。この ID を使用して口座データにアクセスします。 > 顧客が手動入力および少額入金によって関連付けた銀行口座には、Payment Method の `financial_connections_account` ID がありません。 Financial Connections アカウント ID を特定するには、Checkout セッションを取得して `payment_intent.payment_method` 属性を拡張します。 ```curl curl -G https://api.stripe.com/v1/checkout/sessions/{{CHECKOUTSESSION_ID}} \ -u "<>:" \ -d "expand[]=payment_intent.payment_method" ``` ```json { "id": "{{CHECKOUT_SESSION_ID}}", "object": "checkout.session", // ... "payment_intent": { "id": "{{PAYMENT_INTENT_ID}}", "object": "payment_intent", // ... "payment_method": { "id": "{{PAYMENT_METHOD_ID}}", // ... "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK","financial_connections_account": "{{FINANCIAL_CONNECTIONS_ACCOUNT_ID}}", "fingerprint": "q9qchffggRjlX2tb", "last4": "6789", "routing_number": "110000000" } } // ... } } ``` 追加の口座データを使用して、[Financial Connections](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md#optimize) で ACH の実装を最適化する方法をご紹介します。 ## Optional: 不審請求の申請を解決する [サーバー側] 一般的に、顧客は銀行を通じて、個人口座では引き落とし後 60 日以内、事業用口座では 2 営業日以内に [ACH Direct Debit 決済に対する不審請求の申し立て](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#resolving-disputes)を行うことができます。まれなケースとして、この申し立て期限を過ぎてからでも、引き落としに対して不審請求の申し立てを行える場合があります。 顧客が決済に対して不審請求を申請すると、Stripe は [charge.dispute.closed](https://docs.stripe.com/api/events/types.md#event_types-charge.dispute.closed) Webhook イベントを送信し、PaymentMethod のオーソリは取り消されます。 まれに、PaymentIntent が `succeeded` に変わった後に、Stripe が銀行から ACH の失敗を受け取ることがあります。この場合、Stripe は以下の `reason` で不審請求の申請を作成します。 - `insufficient_funds` - `incorrect_account_details` - `bank_can't_process` この場合、Stripe は失敗の手数料を請求します。 この PaymentMethod を再利用する今後の決済では、次のエラーが返されます。 ```javascript { "error": { "message": "This PaymentIntent requires a mandate, but no existing mandate was found. Collect mandate acceptance from the customer and try again, providing acceptance data in the mandate_data parameter.", "payment_intent": { ... } "type": "invalid_request_error" } } ``` このエラーには、`requires_confirmation` の状態の PaymentIntent が含まれています。決済を続けるには、以下を行う必要があります。 1. 今後の決済で不審請求の申し立てが認められないように、顧客との不審請求の申し立てを解決します。 1. 顧客からの承認をもう一度確認します。 支払いの承認を確認するには、[Stripe.js を使用してオンラインで顧客から同意書の承認を収集する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md?platform=web#web-collect-mandate-and-submit)か、Stripe API を使用してオフラインで確認します。 > 顧客が同じ銀行口座からの複数の支払いに対して不審請求を申請する場合、Stripe は該当の銀行口座をブロックします。解決策については、[Stripe サポート](https://support.stripe.com/?contact=true)にお問い合わせください。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}}/confirm \ -u "<>:" \ -d "mandate_data[customer_acceptance][type]=offline" ``` ## Optional: 支払いの参照情報 支払い参照番号は銀行で生成され、これを使用して銀行口座の所有者は銀行で資金を確認できます。支払いが成功すると、ダッシュボードと [Charge オブジェクト](https://docs.stripe.com/api/charges/object.md)内に支払い参照番号が表示されます。 | 支払いの状態 | 支払いの参照値 | | ------ | ------------------------- | | 保留中 | 利用不可 | | 失敗 | 利用不可 | | 成功 | 利用可能 (091000015001234 など) | また、`charge.succeeded` Webhook を受け取ったら、`payment_method_details` の内容を確認して、[payment_reference](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-us_bank_account-payment_reference) を見つけます。 次のイベントの例は、成功した ACH 支払いと支払い参照番号を示しています。 #### charge-succeeded ```json { "id": "{{EVENT_ID}}", "object": "event", // omitted some fields in the example "type": "charge.succeeded", "data": { "object": { "id": "{{PAYMENT_ID}}", "object": "charge", //... "paid": true, "payment_intent": "{{PAYMENT_INTENT_ID}}", "payment_method": "{{PAYMENT_METHOD_ID}}", "payment_method_details": { "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK", "fingerprint": "Ih3foEnRvLXShyfB", "last4": "1000","payment_reference": "091000015001234", "routing_number": "110000000" } } // ... } } } ``` `destination_details` の内容を表示して、返金された ACH 支払いに関連付けられた [refund reference](https://docs.stripe.com/api/refunds/object.md#refund_object-destination_details-us_bank_transfer-reference) を見つけます。 次のイベントの例は、返金参照番号が指定された、成功した ACH 返金のレンダリングを示しています。 [返金](https://docs.stripe.com/refunds.md) の詳細をご覧ください。 #### charge-refund-updated ```json { "id": "{{EVENT_ID}}", "object": "event", "type": "charge.refund.updated", "data": { "object": { "id": "{{REFUND_ID}}", "object": "refund", //... "payment_intent": "{{PAYMENT_INTENT_ID}}", "destination_details": { "type": "us_bank_transfer", "us_bank_transfer": {"reference": "091000015001111", "reference_status": "available" } } // ... } } } ``` ## Optional: 顧客の振替日を設定する [サーバー側] Stripe が顧客の銀行口座から引き落としを行う日付は、[ターゲット日](https://docs.stripe.com/API/Checkout/Sessions/object.md#Checkout_session_object-%E6%94%AF%E6%89%95%E3%81%84_method_options-us_bank_account-target_date) を使用して制御できます。ターゲット日は、現在の日付から 3 日以上、15 日以内である必要があります。 目標日は、顧客のアカウントから離脱するための資金をスケジュールします。 次のいずれかの基準を満たす目標日は、引き落としを翌営業日まで延期します。 - 週末、祝日、またはその他の非営業日に当たる予定期日。 - 3 営業日以内に到来する予定期日。 このパラメーターは、ベストエフォート方式で機能します。顧客の銀行は、祝日の関係やその他の理由により、異なる日付に引き落としを処理する場合があります。 > [ 認証方法 ](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-payment_method_options-us_bank_account-verification_method)として `マイクロデポジット` を使用している場合、[ ターゲット日 ](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-payment_method_options-us_bank_account-target_date) を設定することはできません。これは、認証プロセスにターゲット日より長い時間がかかる可能性があり、その結果、支払いが予定より遅れて到着する恐れがあるためです。 ## See also - [将来の決済に備えて ACH ダイレクトデビットのプリオーソリデビットの詳細を保存する](https://docs.stripe.com/payments/ach-direct-debit/set-up-payment.md) # Checkout Sessions API > This is a Checkout Sessions API for when payment-ui is elements and api-integration is checkout. View the full page at https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=elements&api-integration=checkout. ビジネス ニーズに合った API を判断するには、[比較ガイド](https://docs.stripe.com/payments/checkout-sessions-and-payment-intents-comparison.md) を参照してください。 [Payment Element](https://docs.stripe.com/payments/payment-element.md) を使用して、ウェブサイトまたはアプリケーションにカスタムの Stripe 決済フォームを埋め込み、顧客に決済手段を提供します。高度な設定とカスタマイズについては、[決済の受け付け](https://docs.stripe.com/payments/accept-a-payment.md)に関する導入ガイドをご覧ください。 支払い Element の導入で ACH Direct Debit を使用する前に、ACH Direct Debit に関する次の考慮事項をご確認ください。 - [同意書の収集](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#mandate-collection)についてご紹介します。 - [銀行口座の確認](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#bank-verification)方法を選択します。 > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. ### 同意書の収集 ACH 決済を受け付ける際は、同意書について理解する必要があります。 API を直接実装しない限り、Stripe が会社に代わり同意書の収集と保存を処理します。これにより、規制要件の遵守が保証されます。支払いプロセス中に顧客が同意書に同意すると、Stripe はこの情報を自動的に保存して、ダッシュボードからアクセスできるようにします。 ## サーバーを設定する [サーバー側] アプリケーションから API にアクセスするには、公式の Stripe ライブラリを使用します。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## Checkout セッションを作成する [サーバー側] [Checkout セッション](https://docs.stripe.com/api/checkout/sessions/create.md)を作成してその [Client Secret](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-client_secret) をフロントエンドに返すエンドポイントを、サーバーに追加します。Checkout セッションは、顧客が 1 回限りの購入またはサブスクリプションの支払いを行う際のセッションを表します。Checkout セッションは作成後 24 時間で期限切れとなります。 [動的支払い方法](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md) を使用して、各顧客に最も関連性の高い支払い方法を動的に表示し、コンバージョンを最大化することをお勧めします。[支払い方法を手動でリスト](https://docs.stripe.com/payments/payment-methods/integration-options.md#listing-payment-methods-manually) して、動的支払い方法を無効にすることもできます。 #### ダッシュボードで決済手段を管理する #### TypeScript ```javascript import express, {Express} from 'express'; const app: Express = express(); app.post('/create-checkout-session', async (req: Express.Request, res: Express.Response) => { const session = await stripe.checkout.sessions.create({ line_items: [ { price_data: { currency: 'usd', product_data: { name: 'T-shirt', }, unit_amount: 2000, }, quantity: 1, }, ], mode: 'payment',ui_mode: 'elements', // The URL of your payment completion page return_url: 'https://example.com/return?session_id={CHECKOUT_SESSION_ID}' }); res.json({checkoutSessionClientSecret: session.client_secret}); }); app.listen(3000, () => { console.log('Running on port 3000'); }); ``` #### 決済手段を手動でリストする 支払い方法を手動で一覧表示するには、[決済セッション](https://docs.stripe.com/api/checkout/sessions.md) の作成時に [payment_method_types](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-payment_method_types) に指定します。異なる通貨の `line_items` がある場合は、決済 Sessions を別途作成する必要があります。 #### TypeScript ```javascript import express, {Express} from 'express'; const app: Express = express(); app.post('/create-checkout-session', async (req: Express.Request, res: Express.Response) => { const session = await stripe.checkout.sessions.create({ line_items: [ { price_data: { currency: 'usd', product_data: { name: 'T-shirt', }, unit_amount: 1099, }, quantity: 1, }, ], mode: 'payment', ui_mode: 'elements', payment_method_types: ['us_bank_account'], return_url: 'https://example.com/return?session_id={CHECKOUT_SESSION_ID}' }); res.json({checkoutSessionClientSecret: session.client_secret}); }); app.listen(3000, () => { console.log('Running on port 3000'); }); ``` ## フロントエンドを設定する [クライアント側] #### HTML + JS Stripe.js スクリプトをチェックアウトページに含めるには、このスクリプトを HTML ファイルの `head` に追加します。常に js.stripe.com から Stripe.js を直接読み込むことにより、PCI への準拠が維持されます。スクリプトをバンドルに含めたり、そのコピーを自身でホストしたりしないでください。 スクリプトタグ `` を読み込んで最新の Stripe.js バージョンをご利用になっていることをご確認ください。Stripe.js のバージョン管理について詳しくは[こちら](https://docs.stripe.com/sdks/stripejs-versioning.md)をご覧ください。 ```html Checkout ``` > Stripe は、Stripe.js をモジュールとして読み込むために使用できる npm パッケージを提供しています。[GitHub のプロジェクト](https://github.com/stripe/stripe-js)をご覧ください。バージョン [7.0.0](https://www.npmjs.com/package/%40stripe/stripe-js/v/7.0.0) 以降が必要です。 stripe.js を初期化します。 ```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( '<>', ); ``` #### React npm のパブリックレジストリーから [React Stripe.js](https://www.npmjs.com/package/@stripe/react-stripe-js) と [Stripe.js ローダー](https://www.npmjs.com/package/@stripe/stripe-js)をインストールします。少なくとも、バージョン 5.0.0 以上の React Stripe.js と、バージョン 8.0.0 以上の Stripe.js ローダーが必要になります。 ```bash npm install --save @stripe/react-stripe-js@^5.0.0 @stripe/stripe-js@^8.0.0 ``` 公開可能キーを使用して、フロントエンドの `stripe` インスタンスを初期化します。 ```javascript import {loadStripe} from '@stripe/stripe-js'; const stripe = loadStripe("<>"); ``` ## Checkout を初期化する [クライアント側] #### HTML + JS [initCheckoutElementsSdk](https://docs.stripe.com/js/custom_checkout/init) を呼び出し、`clientSecret` を渡します。 `initCheckoutElementsSdk` は、Checkout Session のデータとそれを更新するメソッドを含む [Checkout](https://docs.stripe.com/js/custom_checkout) オブジェクトを返します。 [actions.getSession()](https://docs.stripe.com/js/custom_checkout/session) から `total` と `lineItems` を読み取り、UI に表示します。これにより、コードの変更を最小限に抑えて新機能を有効にできます。たとえば、[手動通貨価格](https://docs.stripe.com/payments/custom/localize-prices/manual-currency-prices.md)を追加する場合、`total` を表示すれば UI を変更する必要はありません。 ```html
``` ```javascript const clientSecret = fetch('/create-checkout-session', {method: 'POST'}) .then((response) => response.json()) .then((json) => json.client_secret); const checkout = stripe.initCheckoutElementsSdk({clientSecret}); const loadActionsResult = await checkout.loadActions(); if (loadActionsResult.type === 'success') { const session = loadActionsResult.actions.getSession(); const checkoutContainer = document.getElementById('checkout-container'); checkoutContainer.append(JSON.stringify(session.lineItems, null, 2)); checkoutContainer.append(document.createElement('br')); checkoutContainer.append(`Total: ${session.total.total.amount}`); } ``` #### React [CheckoutElementsProvider](https://docs.stripe.com/js/react_stripe_js/checkout/checkout_provider) コンポーネントでアプリケーションをラップし、`clientSecret` と `stripe` インスタンスを渡します。 ```jsx import React from 'react'; import {CheckoutElementsProvider} from '@stripe/react-stripe-js/checkout'; import CheckoutForm from './CheckoutForm'; const clientSecret = fetch('/create-checkout-session', {method: 'POST'}) .then((response) => response.json()) .then((json) => json.client_secret); const App = () => { return ( ); }; export default App; ``` Access the [Checkout](https://docs.stripe.com/js/custom_checkout) object in your checkout form component by using the `useCheckoutElements()` hook. The `Checkout` object contains data from the Checkout Session and methods to update it. `Checkout` オブジェクトから `lineItems` と `lineItems` を読み取り、UI に表示します。これにより、コードの変更を最小限に抑えて機能を有効にできます。たとえば、[手動通貨価格](https://docs.stripe.com/payments/custom/localize-prices/manual-currency-prices.md)を追加する場合、`total` を表示すると UI を変更する必要はありません。 ```jsx import React from 'react'; import {useCheckoutElements} from '@stripe/react-stripe-js/checkout'; const CheckoutForm = () => {const checkoutState = useCheckoutElements(); if (checkoutState.type === 'loading') { return (
Loading...
); } if (checkoutState.type === 'error') { return (
Error: {checkoutState.error.message}
); } return (
{JSON.stringify(checkoutState.checkout.lineItems, null, 2)} {/* A formatted total amount */} Total: {checkoutState.checkout.total.total.amount}
); }; ``` ## 顧客のメールアドレスを収集する [クライアント側] #### HTML + JS Checkout Session を完了するには、有効な顧客のメールアドレスを指定する必要があります。 これらの手順では、メールアドレス入力欄を作成し、`Checkout` オブジェクトの [updateEmail](https://docs.stripe.com/js/custom_checkout/update_email) を使用します。 または、以下を実行してください。 - Checkout Session の作成時に、[customer_email](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer_email)、[customer_account](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer_account) (顧客設定の `Account` オブジェクトとして表される顧客の場合)、または [customer](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer) (`Customer` オブジェクトとして表される顧客の場合) を渡します。Stripe はこの方法で提供されたメールアドレスを検証します。 - [checkout.confirm](https://docs.stripe.com/js/custom_checkout/confirm) で既に検証済みのメールアドレスを渡します。 ```html
``` ```javascript const checkout = stripe.initCheckoutElementsSdk({clientSecret}); const loadActionsResult = await checkout.loadActions(); if (loadActionsResult.type === 'success') { const {actions} = loadActionsResult; const emailInput = document.getElementById('email'); const emailErrors = document.getElementById('email-errors'); emailInput.addEventListener('input', () => { // Clear any validation errors emailErrors.textContent = ''; }); emailInput.addEventListener('blur', () => { const newEmail = emailInput.value;actions.updateEmail(newEmail).then((result) => { if (result.error) { emailErrors.textContent = result.error.message; } }); }); } ``` #### React Checkout Session を完了するには、有効な顧客のメールアドレスを指定する必要があります。 これらの手順では、メールアドレス入力欄を作成し、`Checkout` オブジェクトの [updateEmail](https://docs.stripe.com/js/react_stripe_js/checkout/update_email) を使用します。 または、以下を実行してください。 - Checkout Session の作成時に、[customer_email](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer_email)、[customer_account](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer_account) (顧客設定の `Account` オブジェクトとして表される顧客の場合)、または [customer](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-customer) (`Customer` オブジェクトとして表される顧客の場合) を渡します。Stripe はこの方法で提供されたメールアドレスを検証します。 - [confirm](https://docs.stripe.com/js/react_stripe_js/checkout/confirm) で既に検証済みのメールアドレスを渡します。 ```jsx import React from 'react'; import {useCheckoutElements} from '@stripe/react-stripe-js/checkout'; const EmailInput = () => { const checkoutState = useCheckoutElements(); const [email, setEmail] = React.useState(''); const [error, setError] = React.useState(null); if (checkoutState.type === 'loading') { return (
Loading...
); } else if (checkoutState.type === 'error') { return (
Error: {checkoutState.error.message}
); } const handleBlur = () => {checkoutState.checkout.updateEmail(email).then((result) => { if (result.type === 'error') { setError(result.error); } }) }; const handleChange = (e) => { setError(null); setEmail(e.target.value); }; return (
{error &&
{error.message}
}
); }; export default EmailInput; ``` ## 支払い情報を収集する [クライアント側] [Payment Element](https://docs.stripe.com/payments/payment-element.md) を使用して、クライアントで支払い情報を収集します。Payment Element は、さまざまな決済手段で支払い情報の収集を簡略化する事前構築済みの UI コンポーネントです。 Payment Element には、HTTPS 接続を介して支払い情報を Stripe に安全に送信する iframe が含まれています。一部の支払い方法では、支払いを確定するために別のページにリダイレクトする必要があるため、Payment Element を別の iframe 内に配置しないでください。 iframe を使用して Apple Pay または Google Pay を受け付けたい場合は、iframe の [allow](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-allowpaymentrequest) 属性を `"payment *"` と等しく設定する必要があります。 構築済みのシステムを機能させるには、決済ページのアドレスの先頭を `http://` ではなく `https://` にする必要があります。HTTPS を使用しなくてもシステムをテストできますが、本番環境で決済を受け付ける準備が整ったら、必ず、HTTPS を[有効](https://docs.stripe.com/security/guide.md#tls)にしてください。 #### HTML + JS まず、コンテナーの DOM 要素を作成して、[Payment Element](https://docs.stripe.com/payments/payment-element.md) をマウントします。次に、[checkout.createPaymentElement](https://docs.stripe.com/js/custom_checkout/create_payment_element) を使用して `Payment Element` のインスタンスを作成し、[element.mount](https://docs.stripe.com/js/element/mount) を呼び出してマウントし、CSS セレクターまたはコンテナーの DOM 要素を指定します。 ```html
``` ```javascript const paymentElement = checkout.createPaymentElement(); paymentElement.mount('#payment-element'); ``` 対応しているオプションについては、[Stripe.js のドキュメント](https://docs.stripe.com/js/custom_checkout/create_payment_element#custom_checkout_create_payment_element-options) をご覧ください。 フロントエンドで Checkout を初期化するときに [elementsOptions.appearance](https://docs.stripe.com/js/custom_checkout/init#custom_checkout_init-options-elementsOptions-appearance) を渡すことで、すべての Elements の[デザインをカスタマイズ](https://docs.stripe.com/payments/checkout/customization/appearance.md)できるようになります。 #### React [CheckoutElementsProvider](https://docs.stripe.com/js/react_stripe_js/checkout/checkout_provider) 内に [Payment Element](https://docs.stripe.com/payments/payment-element.md) コンポーネントをマウントします。 ```jsx import React from 'react';import {PaymentElement, useCheckoutElements} from '@stripe/react-stripe-js/checkout'; const CheckoutForm = () => { const checkoutState = useCheckoutElements(); if (checkoutState.type === 'loading') { return (
Loading...
); } if (checkoutState.type === 'error') { return (
Error: {checkoutState.error.message}
); } return (
{JSON.stringify(checkoutState.checkout.lineItems, null, 2)} {/* A formatted total amount */} Total: {checkoutState.checkout.total.total.amount} ); }; export default CheckoutForm; ``` 対応しているオプションについては、[Stripe.js のドキュメント](https://docs.stripe.com/js/custom_checkout/create_payment_element#custom_checkout_create_payment_element-options) をご覧ください。 [elementsOptions.appearance](https://docs.stripe.com/js/react_stripe_js/checkout/checkout_provider#react_checkout_provider-options-elementsOptions-appearance) を [CheckoutElementsProvider](https://docs.stripe.com/js/react_stripe_js/checkout/checkout_provider) に渡すことで、すべての Elements の[外観をカスタマイズ](https://docs.stripe.com/payments/checkout/customization/appearance.md)できます。 ## 銀行口座を確認する #### Item 1 Financial Connections の手数料については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 銀行口座確認では、自動確認を使用して、デフォルトで [Financial Connections](https://docs.stripe.com/financial-connections.md) から支払い情報を収集します。使用に際して変更は必要ありません。決済セッションの作成時に `payment_method_options[us_bank_account][verification_method]` を `即時` に設定して、すべてのユーザーが Financial Connections`スキップする` ことで、確認方法を変更できます。Financial Connections を設定し、支払いを開始する前にアカウントの残高を確認するなど、追加の口座データにアクセスする方法については、[Financial Connections](https://docs.stripe.com/financial-connections.md) をご覧ください。 #### 自動 (デフォルト) デフォルトでは、銀行口座決済情報の収集では、[Financial Connections](https://docs.stripe.com/financial-connections.md) を使用して顧客の口座を即時確認します。即時の確認が不可能な場合は、手動の口座番号入力と少額入金による確認に戻ります。 > 顧客が口座を認証した後で追加データにアクセスを拡張するには、顧客は権限を拡張して口座を再度関連付ける必要があります。この認証は顧客ごとに 1 回行われ、付与された権限は再利用可能です。 **少額入金による確認** すべての顧客が銀行口座を即座に確認できるわけではありません。このセクションは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。このような場合、Stripe は確認のために、顧客の銀行口座に 1 ~ 2 回の少額入金を送金します。これらの入金が顧客のオンライン明細書に表示されるまでに 1 ~ 2 営業日かかります。 少額入金には 2 つのタイプがあります。 - **明細書表記コード** (デフォルト):Stripe は、SM で始まる一意の 6 桁の `descriptor_code` を使用し、0.01 USD の少額入金を顧客の銀行口座に送金します。顧客はこのコードを使用して銀行口座を確認します。 - **金額**:Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は入金額を使用して銀行口座を確認します。 **少額入金による確認の失敗** 銀行口座で少額入金による確認が進行中のときに、確認が失敗する原因がいくつか考えられます。 - 少額入金が顧客の銀行口座に届きません (これは通常、銀行口座が解約済みまたは使用不可であるか、銀行口座番号が不正確である場合に発生します)。 - 顧客はアカウントの本人確認で試行回数の上限を超えています。この上限を超えると、その銀行口座は確認することも、再利用することもできなくなります。 - 顧客は 10 日以内に確認を完了しませんでした。 #### 即時 即時の確認を使用すると、すべての顧客に Financial Connections による銀行口座の確認を実行できます。 即時確認を使用するには、決済セッションの作成時に `payment_method_options[us_bank_account][verification_method]` パラメータを `instant` に設定します。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d ui_mode=elements \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][0]=payment_method" \ --data-urlencode "return_url=https://example.com/return?session_id={CHECKOUT_SESSION_ID}" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d ui_mode=elements \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][0]=payment_method" \ --data-urlencode "return_url=https://example.com/return?session_id={CHECKOUT_SESSION_ID}" ``` クライアント側では、`payment.createPaymentElement()` によって作成された支払い Element は、決済セッションで設定された確認方法を自動的に使用します。追加の設定は必要ありません。 #### Item 2 Financial Connections の手数料については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 銀行口座確認では、自動確認を使用して、デフォルトで [Financial Connections](https://docs.stripe.com/financial-connections.md) から支払い情報を収集します。使用に際して変更は必要ありません。決済セッションの作成時に `payment_method_options[us_bank_account][verification_method]` を `即時` に設定して、すべてのユーザーが Financial Connections`スキップする` ことで、確認方法を変更できます。Financial Connections を設定し、支払いを開始する前にアカウントの残高を確認するなど、追加の口座データにアクセスする方法については、[Financial Connections](https://docs.stripe.com/financial-connections.md) をご覧ください。 #### 自動 (デフォルト) デフォルトでは、銀行口座決済情報の収集では、[Financial Connections](https://docs.stripe.com/financial-connections.md) を使用して顧客の口座を即時確認します。即時の確認が不可能な場合は、手動の口座番号入力と少額入金による確認に戻ります。 > 顧客が口座を認証した後で追加データにアクセスを拡張するには、顧客は権限を拡張して口座を再度関連付ける必要があります。この認証は顧客ごとに 1 回行われ、付与された権限は再利用可能です。 **少額入金による確認** すべての顧客が銀行口座を即座に確認できるわけではありません。このセクションは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。このような場合、Stripe は確認のために、顧客の銀行口座に 1 ~ 2 回の少額入金を送金します。これらの入金が顧客のオンライン明細書に表示されるまでに 1 ~ 2 営業日かかります。 少額入金には 2 つのタイプがあります。 - **明細書表記コード** (デフォルト):Stripe は、SM で始まる一意の 6 桁の `descriptor_code` を使用し、0.01 USD の少額入金を顧客の銀行口座に送金します。顧客はこのコードを使用して銀行口座を確認します。 - **金額**:Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は入金額を使用して銀行口座を確認します。 **少額入金による確認の失敗** 銀行口座で少額入金による確認が進行中のときに、確認が失敗する原因がいくつか考えられます。 - 少額入金が顧客の銀行口座に届きません (これは通常、銀行口座が解約済みまたは使用不可であるか、銀行口座番号が不正確である場合に発生します)。 - 顧客はアカウントの本人確認で試行回数の上限を超えています。この上限を超えると、その銀行口座は確認することも、再利用することもできなくなります。 - 顧客は 10 日以内に確認を完了しませんでした。 #### 即時 即時の確認を使用すると、すべての顧客に Financial Connections による銀行口座の確認を実行できます。 即時確認を使用するには、決済セッションの作成時に `payment_method_options[us_bank_account][verification_method]` パラメータを `instant` に設定します。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d ui_mode=elements \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][0]=payment_method" \ --data-urlencode "return_url=https://example.com/return?session_id={CHECKOUT_SESSION_ID}" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "customer={{CUSTOMER_ID}}" \ -d "line_items[0][price_data][currency]=usd" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=2000" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d ui_mode=elements \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][0]=payment_method" \ --data-urlencode "return_url=https://example.com/return?session_id={CHECKOUT_SESSION_ID}" ``` クライアント側では、`payment.createPaymentElement()` によって作成された支払い Element は、決済セッションで設定された確認方法を自動的に使用します。追加の設定は必要ありません。 ## 決済を送信 [クライアント側] #### HTML + JS `Checkout` インスタンスから [確定](https://docs.stripe.com/js/custom_checkout/confirm) を呼び出す**支払う** ボタンをレンダリングして、決済を送信します。 ```html
``` ```js const checkout = stripe.initCheckoutElementsSdk({clientSecret}); checkout.on('change', (session) => { document.getElementById('pay-button').disabled = !session.canConfirm; }); const loadActionsResult = await checkout.loadActions(); if (loadActionsResult.type === 'success') { const {actions} = loadActionsResult; const button = document.getElementById('pay-button'); const errors = document.getElementById('confirm-errors'); button.addEventListener('click', () => { // Clear any validation errors errors.textContent = ''; actions.confirm().then((result) => { if (result.type === 'error') { errors.textContent = result.error.message; } }); }); } ``` #### React Render a **Pay** button that calls [confirm](https://docs.stripe.com/js/custom_checkout/confirm) from [useCheckoutElements](https://docs.stripe.com/js/react_stripe_js/checkout/use_checkout_elements) to submit the payment. ```jsx import React from 'react'; import {useCheckoutElements} from '@stripe/react-stripe-js/checkout'; const PayButton = () => { const checkoutState = useCheckoutElements(); const [loading, setLoading] = React.useState(false); const [error, setError] = React.useState(null); if (checkoutState.type !== "success") { return null; } const handleClick = () => { setLoading(true);checkoutState.checkout.confirm().then((result) => { if (result.type === 'error') { setError(result.error) } setLoading(false); }) }; return (
{error &&
{error.message}
}
) }; export default PayButton; ``` ## 支払い後のイベントを処理する 支払いが完了すると、Stripe は [Checkout.session.async_payment_succeeded](https://docs.stripe.com/api/events/types.md#event_types-checkout.session.async_payment_succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) またはパートナーソリューションを使用して、これらのイベントを受信し、また顧客への注文確認メールの送信、データベースへの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 - **ダッシュボードでイベントを手動で処理する** ダッシュボードを使用して、テスト決済を[ダッシュボードで表示](https://dashboard.stripe.com/test/payments)したり、メール領収書を送信したり、入金を処理したり、失敗した決済を再試行したりできます。 - **Custom Webhook を構築する** [カスタム webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) ハンドラを構築して、イベントをリッスンし、カスタムの非同期決済フローを構築できます。Stripe CLI を使用すると、ローカルで webhook 連携をテストしてデバッグできます。 - **構築済みアプリを導入する** パートナーアプリケーションを統合することで、[自動化](https://stripe.partners/?f_category=automation)や[マーケティング/セールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを処理します。 ## 連携をテストする [Financial Connections](https://docs.stripe.com/financial-connections/testing.md#web-how-to-use-test-accounts) を使用して即時確認を行うシナリオをテストする方法をご紹介します。 ### サンドボックスで取引メールを送信する 銀行口座の詳細を収集し、同意書を受け付けたら、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で同意書の確認メールと少額入金の確認メールを送信します。 ドメインが **{domain}** で、ユーザー名が **{username}** の場合、メール形式 **{username}+test\_email@{domain}** を使用してテスト取引メールを送信します。 たとえば、ドメインが **example.com** でユーザー名が **info** の場合、ACH Direct Debit 決済のテストには **info+test\_email@example.com** という形式を使用します。この形式により、メールが正しくルーティングされます。**+test\_email** サフィックスを含めない場合、メールは送信されません。 > テスト中にこれらのメールをトリガーする前に、Stripe [アカウントを設定](https://docs.stripe.com/get-started/account/set-up.md)する必要があります。 ### テスト用口座番号 Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。 | 口座番号 | トークン | 金融番号 | 動作 | | -------------- | -------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------- | | `000123456789` | `pm_usBankAccount_success` | `110000000` | 支払いは成功します。 | | `000111111113` | `pm_usBankAccount_accountClosed` | `110000000` | 口座が解約済みであるため、支払いは失敗します。 | | `000000004954` | `pm_usBankAccount_riskLevelHighest` | `110000000` | この支払いは、[不正利用のリスクが高い](https://docs.stripe.com/radar/risk-evaluation.md#high-risk)ため、Radar によってブロックされています。 | | `000111111116` | `pm_usBankAccount_noAccount` | `110000000` | 口座が見つからないため、支払いは失敗します。 | | `000222222227` | `pm_usBankAccount_insufficientFunds` | `110000000` | 残高不足のため、支払いは失敗します。 | | `000333333335` | `pm_usBankAccount_debitNotAuthorized` | `110000000` | 引き落としがオーソリされていないため、支払いは失敗します。 | | `000444444440` | `pm_usBankAccount_invalidCurrency` | `110000000` | 通貨が無効であるため、支払いは失敗します。 | | `000666666661` | `pm_usBankAccount_failMicrodeposits` | `110000000` | 支払いで少額入金の送金が失敗します。 | | `000555555559` | `pm_usBankAccount_dispute` | `110000000` | 支払いによって不審請求の申請が開始されています。 | | `000000000009` | `pm_usBankAccount_processing` | `110000000` | 支払いは無期限に処理中のままになります。 [PaymentIntent キャンセル](https://docs.stripe.com/api/payment_intents/cancel.md) をテストするのに役立ちます。 | | `000777777771` | `pm_usBankAccount_weeklyLimitExceeded` | `110000000` | 支払い額がアカウントの週次支払い額の上限を超えているため、支払いが失敗しました。 | | `000888888885` | | `110000000` | [トークン化されたアカウント番号](https://docs.stripe.com/financial-connections/tokenized-account-numbers.md)が無効化されると決済が失敗します。 | テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。 ### 少額入金の金額と明細書表記コードをテストする さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。 | 少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ | | ------------- | --------------- | ------------------------- | | `32` および `45` | SM11AA | アカウントの確認をシミュレーションします。 | | `10` および `11` | SM33CC | 許容された確認回数の超過をシミュレーションします。 | | `40` および `41` | SM44DD | 少額入金のタイムアウトをシミュレーションします。 | ### 売上処理の動作をテストする テスト取引は即座に売上として処理され、利用可能なテスト残高に追加されます。この動作は、利用可能な残高で取引が売上として処理されるまでに[数日](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#timing)かかることがある、本番環境とは異なります。 ## Optional: Financial Connections 銀行口座のデータにアクセスする PaymentIntent の作成時に、追加の[データ権限](https://docs.stripe.com/financial-connections/fundamentals.md#data-permissions)をリクエストする場合にのみ、Financial Connections データにアクセスできます。 顧客が決済フローを完了すると、返される `us_bank_account` PaymentMethod には、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)を指す [financial_connections_account](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-us_bank_account-financial_connections_account) ID が含まれます。この ID を使用して口座データにアクセスします。 > 顧客が手動入力および少額入金によって関連付けた銀行口座には、Payment Method の `financial_connections_account` ID がありません。 Financial Connections アカウント ID を特定するには、Checkout セッションを取得して `payment_intent.payment_method` 属性を拡張します。 ```curl curl -G https://api.stripe.com/v1/checkout/sessions/{{CHECKOUTSESSION_ID}} \ -u "<>:" \ -d "expand[]=payment_intent.payment_method" ``` ```json { "id": "{{CHECKOUT_SESSION_ID}}", "object": "checkout.session", // ... "payment_intent": { "id": "{{PAYMENT_INTENT_ID}}", "object": "payment_intent", // ... "payment_method": { "id": "{{PAYMENT_METHOD_ID}}", // ... "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK","financial_connections_account": "{{FINANCIAL_CONNECTIONS_ACCOUNT_ID}}", "fingerprint": "q9qchffggRjlX2tb", "last4": "6789", "routing_number": "110000000" } } // ... } } ``` 追加の口座データを使用して、[Financial Connections](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md#optimize) で ACH の実装を最適化する方法をご紹介します。 ## Optional: 不審請求の申請を解決する [サーバー側] 一般的に、顧客は銀行を通じて、個人口座では引き落とし後 60 日以内、事業用口座では 2 営業日以内に [ACH Direct Debit 決済に対する不審請求の申し立て](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#resolving-disputes)を行うことができます。まれなケースとして、この申し立て期限を過ぎてからでも、引き落としに対して不審請求の申し立てを行える場合があります。 顧客が決済に対して不審請求を申請すると、Stripe は [charge.dispute.closed](https://docs.stripe.com/api/events/types.md#event_types-charge.dispute.closed) Webhook イベントを送信し、PaymentMethod のオーソリは取り消されます。 まれに、PaymentIntent が `succeeded` に変わった後に、Stripe が銀行から ACH の失敗を受け取ることがあります。この場合、Stripe は以下の `reason` で不審請求の申請を作成します。 - `insufficient_funds` - `incorrect_account_details` - `bank_can't_process` この場合、Stripe は失敗の手数料を請求します。 この PaymentMethod を再利用する今後の決済では、次のエラーが返されます。 ```javascript { "error": { "message": "This PaymentIntent requires a mandate, but no existing mandate was found. Collect mandate acceptance from the customer and try again, providing acceptance data in the mandate_data parameter.", "payment_intent": { ... } "type": "invalid_request_error" } } ``` このエラーには、`requires_confirmation` の状態の PaymentIntent が含まれています。決済を続けるには、以下を行う必要があります。 1. 今後の決済で不審請求の申し立てが認められないように、顧客との不審請求の申し立てを解決します。 1. 顧客からの承認をもう一度確認します。 支払いの承認を確認するには、[Stripe.js を使用してオンラインで顧客から同意書の承認を収集する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md?platform=web#web-collect-mandate-and-submit)か、Stripe API を使用してオフラインで確認します。 > 顧客が同じ銀行口座からの複数の支払いに対して不審請求を申請する場合、Stripe は該当の銀行口座をブロックします。解決策については、[Stripe サポート](https://support.stripe.com/?contact=true)にお問い合わせください。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}}/confirm \ -u "<>:" \ -d "mandate_data[customer_acceptance][type]=offline" ``` ## Optional: 支払いの参照情報 支払い参照番号は銀行で生成され、これを使用して銀行口座の所有者は銀行で資金を確認できます。支払いが成功すると、ダッシュボードと [Charge オブジェクト](https://docs.stripe.com/api/charges/object.md)内に支払い参照番号が表示されます。 | 支払いの状態 | 支払いの参照値 | | ------ | ------------------------- | | 保留中 | 利用不可 | | 失敗 | 利用不可 | | 成功 | 利用可能 (091000015001234 など) | また、`charge.succeeded` Webhook を受け取ったら、`payment_method_details` の内容を確認して、[payment_reference](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-us_bank_account-payment_reference) を見つけます。 次のイベントの例は、成功した ACH 支払いと支払い参照番号を示しています。 #### charge-succeeded ```json { "id": "{{EVENT_ID}}", "object": "event", // omitted some fields in the example "type": "charge.succeeded", "data": { "object": { "id": "{{PAYMENT_ID}}", "object": "charge", //... "paid": true, "payment_intent": "{{PAYMENT_INTENT_ID}}", "payment_method": "{{PAYMENT_METHOD_ID}}", "payment_method_details": { "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK", "fingerprint": "Ih3foEnRvLXShyfB", "last4": "1000","payment_reference": "091000015001234", "routing_number": "110000000" } } // ... } } } ``` `destination_details` の内容を表示して、返金された ACH 支払いに関連付けられた [refund reference](https://docs.stripe.com/api/refunds/object.md#refund_object-destination_details-us_bank_transfer-reference) を見つけます。 次のイベントの例は、返金参照番号が指定された、成功した ACH 返金のレンダリングを示しています。 [返金](https://docs.stripe.com/refunds.md) の詳細をご覧ください。 #### charge-refund-updated ```json { "id": "{{EVENT_ID}}", "object": "event", "type": "charge.refund.updated", "data": { "object": { "id": "{{REFUND_ID}}", "object": "refund", //... "payment_intent": "{{PAYMENT_INTENT_ID}}", "destination_details": { "type": "us_bank_transfer", "us_bank_transfer": {"reference": "091000015001111", "reference_status": "available" } } // ... } } } ``` ## Optional: 顧客の振替日を設定する [サーバー側] Stripe が顧客の銀行口座から引き落としを行う日付は、[ターゲット日](https://docs.stripe.com/API/Checkout/Sessions/object.md#Checkout_session_object-%E6%94%AF%E6%89%95%E3%81%84_method_options-us_bank_account-target_date) を使用して制御できます。ターゲット日は、現在の日付から 3 日以上、15 日以内である必要があります。 目標日は、顧客のアカウントから離脱するための資金をスケジュールします。 次のいずれかの基準を満たす目標日は、引き落としを翌営業日まで延期します。 - 週末、祝日、またはその他の非営業日に当たる予定期日。 - 3 営業日以内に到来する予定期日。 このパラメーターは、ベストエフォート方式で機能します。顧客の銀行は、祝日の関係やその他の理由により、異なる日付に引き落としを処理する場合があります。 > [ 認証方法 ](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-payment_method_options-us_bank_account-verification_method)として `マイクロデポジット` を使用している場合、[ ターゲット日 ](https://docs.stripe.com/api/checkout/sessions/object.md#checkout_session_object-payment_method_options-us_bank_account-target_date) を設定することはできません。これは、認証プロセスにターゲット日より長い時間がかかる可能性があり、その結果、支払いが予定より遅れて到着する恐れがあるためです。 # Payment Intents API > This is a Payment Intents API for when payment-ui is elements and api-integration is paymentintents. View the full page at https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=elements&api-integration=paymentintents. ビジネス ニーズに合った API を判断するには、[比較ガイド](https://docs.stripe.com/payments/checkout-sessions-and-payment-intents-comparison.md) を参照してください。 [Payment Element](https://docs.stripe.com/payments/payment-element.md) を使用して、ウェブサイトまたはアプリケーションにカスタムの Stripe 決済フォームを埋め込み、顧客に決済手段を提供します。高度な設定とカスタマイズについては、[決済の受け付け](https://docs.stripe.com/payments/accept-a-payment.md)に関する導入ガイドをご覧ください。 Payment Element の実装で ACH Direct Debit を使用する前に、以下の ACH Direct Debit 固有の考慮事項についてご確認ください。 - [同意書の収集](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#mandate-collection)についてご紹介します。 - [銀行口座の確認](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#bank-verification)方法を選択します。 ### 同意書の収集 ACH 決済を受け付ける際は、同意書について理解する必要があります。 API を直接実装しない限り、Stripe が会社に代わり同意書の収集と保存を処理します。これにより、規制要件の遵守が保証されます。支払いプロセス中に顧客が同意書に同意すると、Stripe はこの情報を自動的に保存して、ダッシュボードからアクセスできるようにします。 ## Stripe を設定する [サーバー側] 開始するには、[Stripe アカウントを作成](https://dashboard.stripe.com/register)を作成します。 アプリケーションから Stripe APIにアクセスするには、公式ライブラリを使用してください。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ## 支払い情報を収集する [クライアント側] Payment Element を使用して、クライアントで支払い情報を収集します。Payment Element は、さまざまな決済手段の支払い情報の収集を簡略化する事前構築済みの UI コンポーネントです。 Payment Element には、HTTPS 接続を介して支払い情報を Stripe に安全に送信する iframe が含まれています。決済手段によっては、支払い確認のために別のページにリダイレクトする必要があるため、Payment Element を別の iframe 内に配置しないでください。 実装を機能させるには、決済ページのアドレスの先頭を `http://` ではなく `https://` にする必要があります。HTTPS を使用せずに実装をテストすることはできますが、本番環境で支払いを受け付ける準備が整ったら、忘れずに[有効にしてください](https://docs.stripe.com/security/guide.md#tls)。 #### HTML + JS ### Stripe.js を設定する Payment Element は Stripe.js の機能として自動的に利用可能になります。Stripe.js スクリプトをチェックアウトページに含めるには、このスクリプトを HTML ファイルの `head` に追加します。常に js.stripe.com から Stripe.js を直接読み込むことにより、PCI への準拠が維持されます。スクリプトをバンドルに含めたり、そのコピーを自身にホストしたりしないでください。 ```html Checkout ``` 決済ページで次の JavaScript を使用して Stripe のインスタンスを作成します。 ```javascript // 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('<>'); ``` ### 決済ページに Payment Element を追加する 決済ページに Payment Element を追加するには、支払いフォームに一意の ID を持つ空の DOM ノード (コンテナー) を作成します。 ```html
``` 決済手段をダッシュボードで管理したり、利用可能にする決済手段を [Payment Element](https://docs.stripe.com/js/elements_object/create_without_intent) の作成時に手動でリストしたりすることができます。 #### ダッシュボードで決済手段を管理する ```javascript const options = {mode: 'payment', amount: 1099, currency: 'usd', // Fully customizable with appearance API. appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in checkout formconst elements = stripe.elements(options); // Create and mount the Payment Element const paymentElementOptions = { layout: 'accordion'}; const paymentElement = elements.create('payment', paymentElementOptions); paymentElement.mount('#payment-element'); ``` #### 決済手段を手動でリストする 決済手段を手動でリストするには、[Payment Element](https://docs.stripe.com/js/elements_object/create_without_intent) の作成時に各決済手段を `options` の `PaymentMethodTypes` 属性に追加します。 ```javascript const options = {mode: 'payment', amount: 1099, currency: 'usd', paymentMethodTypes: ['us_bank_account'], // Fully customizable with appearance API. appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in checkout formconst elements = stripe.elements(options); // Create and mount the Payment Element const paymentElementOptions = { layout: 'accordion'}; const paymentElement = elements.create('payment', paymentElementOptions); paymentElement.mount('#payment-element'); ``` #### React ### Stripe.js を設定する [npm パブリックレジストリ](https://www.npmjs.com/package/@stripe/react-stripe-js)から React Stripe.js ローダーと Stripe.js ローダーをインストールします。 ```bash npm install --save @stripe/react-stripe-js @stripe/stripe-js ``` ### Elements プロバイダーを決済ページに追加して設定する Payment Element コンポーネントを使用するには、決済ページのコンポーネントを [Elements プロバイダー](https://docs.stripe.com/sdks/stripejs-react.md#elements-provider)でラップします。公開可能キーを使用して `loadStripe` を呼び出し、返された `Promise` を `Elements` プロバイダーに渡します。 決済手段をダッシュボードで管理したり、利用可能にする決済手段を [Payment Element](https://docs.stripe.com/js/elements_object/create_without_intent) の作成時に手動でリストしたりすることができます。 #### ダッシュボードで決済手段を管理する ```jsx import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import CheckoutForm from './CheckoutForm'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); function App() { const options = {mode: 'payment', amount: 1099, currency: 'usd', // Fully customizable with appearance API. appearance: {/*...*/}, }; return ( ); }; ReactDOM.render(, document.getElementById('root')); ``` #### 決済手段を手動でリストする 決済手段を手動でリストするには、[Payment Element](https://docs.stripe.com/js/elements_object/create_without_intent) の作成時に各決済手段を `payment_method_types` 属性に追加します。 ```jsx import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import CheckoutForm from './CheckoutForm'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); function App() { const options = {mode: 'payment', amount: 1099, currency: 'usd', paymentMethodTypes: ['us_bank_account'], // Fully customizable with appearance API. appearance: {/*...*/}, }; return ( ); }; ReactDOM.render(, document.getElementById('root')); ``` ### Payment Element コンポーネントを追加する `PaymentElement` コンポーネントを使用してフォームを作成します。 ```jsx import React from 'react'; import {PaymentElement} from '@stripe/react-stripe-js'; const CheckoutForm = () => { return (
); }; export default CheckoutForm; ``` `Elements` プロバイダーの作成時に [Appearance オブジェクト](https://docs.stripe.com/elements/appearance-api.md) を `options` に渡すことで、サイトのデザインに合わせて Payment Element をカスタマイズできるようになります。 ### 住所を収集 デフォルトでは、Payment Element は必要な請求住所の詳細のみを収集します。[税金の計算](https://docs.stripe.com/api/tax/calculations/create.md)、配送先情報を入力するなどの一部の動作では、顧客の完全な住所が必要です。次のように対応できます。 - [Address Element](https://docs.stripe.com/elements/address-element.md) を使用して、オートコンプリートとローカリゼーションの機能を利用して、顧客の完全な住所を収集します。これにより、最も正確な税金計算が可能になります。 - 独自のカスタムフォームを使用して住所の詳細を収集する。 ## 銀行口座を確認する #### Item 1 Financial Connections の手数料については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 銀行口座確認では、自動確認を使用して、デフォルトで [Financial Connections](https://docs.stripe.com/financial-connections.md) から支払い情報を収集します。使用に際して変更は必要ありません。[verification_method](https://docs.stripe.com/js/elements_object/create_without_intent#stripe_elements_no_intent-options-paymentMethodOptions-us_bank_account-verification_method) は、すべてのユーザーが Financial Connections で銀行口座を確認 するように`即時に` 変更することも、確認を完全に `スキップする` ように変更することもできます。Financial Connections を設定し、支払いを開始する前にアカウントの残高を確認するなど、その他のアカウントデータにアクセスする方法については、[Financial Connections](https://docs.stripe.com/financial-connections.md) をご覧ください。 #### 自動 (デフォルト) デフォルトでは、銀行口座決済情報の収集では、[Financial Connections](https://docs.stripe.com/financial-connections.md) を使用して顧客の口座を即時確認します。即時の確認が不可能な場合は、手動の口座番号入力と少額入金による確認に戻ります。 > 顧客が口座を認証した後で追加データにアクセスを拡張するには、顧客は権限を拡張して口座を再度関連付ける必要があります。この認証は顧客ごとに 1 回行われ、付与された権限は再利用可能です。 **少額入金による確認** すべての顧客が銀行口座を即座に確認できるわけではありません。このセクションは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。このような場合、Stripe は確認のために、顧客の銀行口座に 1 ~ 2 回の少額入金を送金します。これらの入金が顧客のオンライン明細書に表示されるまでに 1 ~ 2 営業日かかります。 少額入金には 2 つのタイプがあります。 - **明細書表記コード** (デフォルト):Stripe は、SM で始まる一意の 6 桁の `descriptor_code` を使用し、0.01 USD の少額入金を顧客の銀行口座に送金します。顧客はこのコードを使用して銀行口座を確認します。 - **金額**:Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は入金額を使用して銀行口座を確認します。 **少額入金による確認の失敗** 銀行口座で少額入金による確認が進行中のときに、確認が失敗する原因がいくつか考えられます。 - 少額入金が顧客の銀行口座に届きません (これは通常、銀行口座が解約済みまたは使用不可であるか、銀行口座番号が不正確である場合に発生します)。 - 顧客はアカウントの本人確認で試行回数の上限を超えています。この上限を超えると、その銀行口座は確認することも、再利用することもできなくなります。 - 顧客は 10 日以内に確認を完了しませんでした。 #### 即時 即時の確認を使用すると、すべての顧客に Financial Connections による銀行口座の確認を実行できます。 即時確認を使用するには、[支払い Element](https://docs.stripe.com/js/elements_object/create_without_intent) の作成時に [verification_method](https://docs.stripe.com/js/elements_object/create_without_intent#stripe_elements_no_intent-options-paymentMethodOptions-us_bank_account-verification_method) パラメータを `instant` に設定します。 #### HTML + JS ```js const options = { mode: 'payment', amount: 1099, currency: 'usd',paymentMethodOptions: { us_bank_account: { verification_method: "instant" } } appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in checkout form const elements = stripe.elements(options); // Create and mount the Payment Element const paymentElement = elements.create('payment'); paymentElement.mount('#payment-element'); ``` #### React ```jsx import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import CheckoutForm from './CheckoutForm'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); function App() { const options = { mode: 'payment', amount: 1099, currency: 'usd',paymentMethodOptions: { us_bank_account: { verification_method: "instant" } } // Fully customizable with appearance API. appearance: {/*...*/}, }; return ( ); }; ReactDOM.render(, document.getElementById('root')); ``` ### Payment Element コンポーネントを追加する `PaymentElement` コンポーネントを使用してフォームを作成します。 ```jsx import React from 'react'; import {PaymentElement} from '@stripe/react-stripe-js'; const CheckoutForm = () => { return (
); }; export default CheckoutForm; ``` #### Item 2 Financial Connections の手数料については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 銀行口座確認では、自動確認を使用して、デフォルトで [Financial Connections](https://docs.stripe.com/financial-connections.md) から支払い情報を収集します。使用に際して変更は必要ありません。[verification_method](https://docs.stripe.com/js/elements_object/create_without_intent#stripe_elements_no_intent-options-paymentMethodOptions-us_bank_account-verification_method) は、すべてのユーザーが Financial Connections で銀行口座を確認 するように`即時に` 変更することも、確認を完全に `スキップする` ように変更することもできます。Financial Connections を設定し、支払いを開始する前にアカウントの残高を確認するなど、その他のアカウントデータにアクセスする方法については、[Financial Connections](https://docs.stripe.com/financial-connections.md) をご覧ください。 #### 自動 (デフォルト) デフォルトでは、銀行口座決済情報の収集では、[Financial Connections](https://docs.stripe.com/financial-connections.md) を使用して顧客の口座を即時確認します。即時の確認が不可能な場合は、手動の口座番号入力と少額入金による確認に戻ります。 > 顧客が口座を認証した後で追加データにアクセスを拡張するには、顧客は権限を拡張して口座を再度関連付ける必要があります。この認証は顧客ごとに 1 回行われ、付与された権限は再利用可能です。 **少額入金による確認** すべての顧客が銀行口座を即座に確認できるわけではありません。このセクションは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。このような場合、Stripe は確認のために、顧客の銀行口座に 1 ~ 2 回の少額入金を送金します。これらの入金が顧客のオンライン明細書に表示されるまでに 1 ~ 2 営業日かかります。 少額入金には 2 つのタイプがあります。 - **明細書表記コード** (デフォルト):Stripe は、SM で始まる一意の 6 桁の `descriptor_code` を使用し、0.01 USD の少額入金を顧客の銀行口座に送金します。顧客はこのコードを使用して銀行口座を確認します。 - **金額**:Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は入金額を使用して銀行口座を確認します。 **少額入金による確認の失敗** 銀行口座で少額入金による確認が進行中のときに、確認が失敗する原因がいくつか考えられます。 - 少額入金が顧客の銀行口座に届きません (これは通常、銀行口座が解約済みまたは使用不可であるか、銀行口座番号が不正確である場合に発生します)。 - 顧客はアカウントの本人確認で試行回数の上限を超えています。この上限を超えると、その銀行口座は確認することも、再利用することもできなくなります。 - 顧客は 10 日以内に確認を完了しませんでした。 #### 即時 即時の確認を使用すると、すべての顧客に Financial Connections による銀行口座の確認を実行できます。 即時確認を使用するには、[支払い Element](https://docs.stripe.com/js/elements_object/create_without_intent) の作成時に [verification_method](https://docs.stripe.com/js/elements_object/create_without_intent#stripe_elements_no_intent-options-paymentMethodOptions-us_bank_account-verification_method) パラメータを `instant` に設定します。 #### HTML + JS ```js const options = { mode: 'payment', amount: 1099, payment_method_types: ["card", "us_bank_account"], currency: 'usd',paymentMethodOptions: { us_bank_account: { verification_method: "instant" } } appearance: {/*...*/}, }; // Set up Stripe.js and Elements to use in checkout form const elements = stripe.elements(options); // Create and mount the Payment Element const paymentElement = elements.create('payment'); paymentElement.mount('#payment-element'); ``` #### React ```jsx import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import CheckoutForm from './CheckoutForm'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe('<>'); function App() { const options = { mode: 'payment', amount: 1099, currency: 'usd', payment_method_types: `us_bank_account`,paymentMethodOptions: { us_bank_account: { verification_method: "instant" } } // Fully customizable with appearance API. appearance: {/*...*/}, }; return ( ); }; ReactDOM.render(, document.getElementById('root')); ``` ### Payment Element コンポーネントを追加する `PaymentElement` コンポーネントを使用してフォームを作成します。 ```jsx import React from 'react'; import {PaymentElement} from '@stripe/react-stripe-js'; const CheckoutForm = () => { return (
); }; export default CheckoutForm; ``` ## PaymentIntent を作成する [サーバー側] > #### 支払い確定の直前にカスタムのビジネスロジックを実行する > > 支払いの確定ガイドの[ステップ 5](https://docs.stripe.com/payments/finalize-payments-on-the-server.md?platform=web&type=payment#submit-payment) に移動して、支払い確定の直前にカスタムのビジネスロジックを実行します。または、以下のステップに従って既存のシステムをシンプルにします。ここでは、クライアント側で `stripe.confirmPayment` を使用して、支払いの確定と次のアクションの処理の両方を行います。 #### ダッシュボードから決済手段を管理する 顧客が支払いフォームを送信したら、*PaymentIntent* (The Payment Intents API tracks the lifecycle of a customer checkout flow and triggers additional authentication steps when required by regulatory mandates, custom Radar fraud rules, or redirect-based payment methods) を使用して確認と支払いのプロセスを適切に管理します。`amount` と `currency` を指定してサーバー側で PaymentIntent を作成します。悪意のある顧客が独自の価格を選択できないように、請求金額はクライアント側ではなく、常にサーバー側 (信頼できる環境) で決定してください。 `PaymentIntent` には、*client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。Stripe.js がこの値を使用して決済プロセスを安全に完了できるように、この値をクライアントに返します。 #### Accounts v2 #### Ruby ```ruby require 'stripe' # Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. client = Stripe::StripeClient.new('<>') post '/create-intent' do intent = client.v1.payment_intents.create({ # To allow saving and retrieving payment methods, provide the customer's Account ID. customer_account: "{{CUSTOMER_ACCOUNT_ID}}", amount: 1099, currency: 'usd', }) {client_secret: intent.client_secret}.to_json end ``` #### Customers v1 #### Ruby ```ruby require 'stripe' # Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. client = Stripe::StripeClient.new('<>') post '/create-intent' do intent = client.v1.payment_intents.create({ # To allow saving and retrieving payment methods, provide the Customer ID. customer: customer.id, amount: 1099, currency: 'usd', }) {client_secret: intent.client_secret}.to_json end ``` #### 支払い方法を手動で一覧表示する 顧客が決済フォームを送信したら、*PaymentIntent* (The Payment Intents API tracks the lifecycle of a customer checkout flow and triggers additional authentication steps when required by regulatory mandates, custom Radar fraud rules, or redirect-based payment methods) を使用して確認と決済のプロセスがスムーズに進むようにします。`amount`、`currency`、および `payment_method_types` で 1 つ以上の決済手段を指定して、サーバーで PaymentIntent を作成します。悪意のある顧客が価格を操作できないように、請求金額はクライアント側ではなく、常にサーバー側 (信頼できる環境) で決定してください。 PaymentIntent には、*client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。 この値をクライアントに返し、Stripe.js がこれを使用して支払いプロセスを安全に完了できるようにします。 #### Accounts v2 #### Ruby ```ruby require 'stripe' # Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. client = Stripe::StripeClient.new('<>') post '/create-intent' do intent = client.v1.payment_intents.create({ # To allow saving and retrieving payment methods, provide the customer's Account ID. customer_account: customer_account.id, amount: 1099, currency: 'usd', payment_method_types: ['us_bank_account'], }) {client_secret: intent.client_secret}.to_json end ``` #### Customers v1 #### Ruby ```ruby require 'stripe' # Don't put any keys in code. See https://docs.stripe.com/keys-best-practices. client = Stripe::StripeClient.new('<>') post '/create-intent' do intent = client.v1.payment_intents.create({ # To allow saving and retrieving payment methods, provide the Customer ID. customer: customer.id, amount: 1099, currency: 'usd', payment_method_types: ['us_bank_account'], }) {client_secret: intent.client_secret}.to_json end ``` ## Stripe に支払いを送信する [クライアント側] [stripe.confirmPayment](https://docs.stripe.com/js/payment_intents/confirm_payment) を使用して、Payment Element の詳細を使って支払いを完了します。 この関数に [return_url](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-return_url) を指定して、支払い完了後に Stripe がユーザーをリダイレクトする場所を示します。ユーザーは、最初に銀行の認証ページなどの中間サイトにリダイレクトされてから、`return_url` にリダイレクトされる場合があります。カード支払いでは、支払いが成功するとすぐに `return_url` にリダイレクトされます。 支払い完了後にカード支払いのリダイレクトを行わない場合は、[redirect](https://docs.stripe.com/js/payment_intents/confirm_payment#confirm_payment_intent-options-redirect) を `if_required` に設定できます。これにより、リダイレクトベースの決済手段で購入した顧客のみがリダイレクトされます。 #### HTML + JS ```javascript const form = document.getElementById('payment-form'); const submitBtn = document.getElementById('submit'); const handleError = (error) => { const messageContainer = document.querySelector('#error-message'); messageContainer.textContent = error.message; submitBtn.disabled = false; } form.addEventListener('submit', async (event) => { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); // Prevent multiple form submissions if (submitBtn.disabled) { return; } // Disable form submission while loading submitBtn.disabled = true; // Trigger form validation and wallet collection const {error: submitError} = await elements.submit(); if (submitError) { handleError(submitError); return; } // Create the PaymentIntent and obtain clientSecret const res = await fetch("/create-intent", { method: "POST", }); const {client_secret: clientSecret} = await res.json(); // Confirm the PaymentIntent using the details collected by the Payment Element const {error} = await stripe.confirmPayment({ elements, clientSecret, confirmParams: { return_url: 'https://example.com/order/123/complete', }, }); if (error) { // This point is only reached if there's an immediate error when // confirming the payment. Show the error to your customer (for example, payment details incomplete) handleError(error); } else { // Your customer is redirected to your `return_url`. For some payment // methods like iDEAL, your customer is redirected to an intermediate // site first to authorize the payment, then redirected to the `return_url`. } }); ``` #### React ```jsx import React, {useState} from 'react'; import {useStripe, useElements, PaymentElement} from '@stripe/react-stripe-js'; export default function CheckoutForm() { const stripe = useStripe(); const elements = useElements(); const [errorMessage, setErrorMessage] = useState(); const [loading, setLoading] = useState(false); const handleError = (error) => { setLoading(false); setErrorMessage(error.message); } const handleSubmit = async (event) => { // We don't want to let default form submission happen here, // which would refresh the page. event.preventDefault(); if (!stripe) { // Stripe.js hasn't yet loaded. // Make sure to disable form submission until Stripe.js has loaded. return; } setLoading(true); // Trigger form validation and wallet collection const {error: submitError} = await elements.submit(); if (submitError) { handleError(submitError); return; } // Create the PaymentIntent and obtain clientSecret const res = await fetch("/create-intent", { method: "POST", }); const {client_secret: clientSecret} = await res.json(); // Confirm the PaymentIntent using the details collected by the Payment Element const {error} = await stripe.confirmPayment({ elements, clientSecret, confirmParams: { return_url: 'https://example.com/order/123/complete', }, }); if (error) { // This point is only reached if there's an immediate error when // confirming the payment. Show the error to your customer (for example, payment details incomplete) handleError(error); } else { // Your customer is redirected to your `return_url`. For some payment // methods like iDEAL, your customer is redirected to an intermediate // site first to authorize the payment, then redirected to the `return_url`. } }; return (
{errorMessage &&
{errorMessage}
} ); } ``` ## Optional: 支払い後のイベントを処理する 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 - **ダッシュボードでイベントを手動で処理する** ダッシュボードを使用して、テスト決済を[ダッシュボードで表示](https://dashboard.stripe.com/test/payments)したり、メール領収書を送信したり、入金を処理したり、失敗した決済を再試行したりできます。 - **Custom Webhook を構築する** [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - **構築済みアプリを導入する** パートナーアプリケーションを統合することで、[自動化](https://stripe.partners/?f_category=automation)や[マーケティング/セールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを処理します。 ## 連携をテストする [Financial Connections](https://docs.stripe.com/financial-connections/testing.md#web-how-to-use-test-accounts) を使用して即時確認を行うシナリオをテストする方法をご紹介します。 ### サンドボックスで取引メールを送信する 銀行口座の詳細を収集し、同意書を受け付けたら、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で同意書の確認メールと少額入金の確認メールを送信します。 ドメインが **{domain}** で、ユーザー名が **{username}** の場合、メール形式 **{username}+test\_email@{domain}** を使用してテスト取引メールを送信します。 たとえば、ドメインが **example.com** でユーザー名が **info** の場合、ACH Direct Debit 決済のテストには **info+test\_email@example.com** という形式を使用します。この形式により、メールが正しくルーティングされます。**+test\_email** サフィックスを含めない場合、メールは送信されません。 > テスト中にこれらのメールをトリガーする前に、Stripe [アカウントを設定](https://docs.stripe.com/get-started/account/set-up.md)する必要があります。 ### テスト用口座番号 Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。 | 口座番号 | トークン | 金融番号 | 動作 | | -------------- | -------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------- | | `000123456789` | `pm_usBankAccount_success` | `110000000` | 支払いは成功します。 | | `000111111113` | `pm_usBankAccount_accountClosed` | `110000000` | 口座が解約済みであるため、支払いは失敗します。 | | `000000004954` | `pm_usBankAccount_riskLevelHighest` | `110000000` | この支払いは、[不正利用のリスクが高い](https://docs.stripe.com/radar/risk-evaluation.md#high-risk)ため、Radar によってブロックされています。 | | `000111111116` | `pm_usBankAccount_noAccount` | `110000000` | 口座が見つからないため、支払いは失敗します。 | | `000222222227` | `pm_usBankAccount_insufficientFunds` | `110000000` | 残高不足のため、支払いは失敗します。 | | `000333333335` | `pm_usBankAccount_debitNotAuthorized` | `110000000` | 引き落としがオーソリされていないため、支払いは失敗します。 | | `000444444440` | `pm_usBankAccount_invalidCurrency` | `110000000` | 通貨が無効であるため、支払いは失敗します。 | | `000666666661` | `pm_usBankAccount_failMicrodeposits` | `110000000` | 支払いで少額入金の送金が失敗します。 | | `000555555559` | `pm_usBankAccount_dispute` | `110000000` | 支払いによって不審請求の申請が開始されています。 | | `000000000009` | `pm_usBankAccount_processing` | `110000000` | 支払いは無期限に処理中のままになります。 [PaymentIntent キャンセル](https://docs.stripe.com/api/payment_intents/cancel.md) をテストするのに役立ちます。 | | `000777777771` | `pm_usBankAccount_weeklyLimitExceeded` | `110000000` | 支払い額がアカウントの週次支払い額の上限を超えているため、支払いが失敗しました。 | | `000888888885` | | `110000000` | [トークン化されたアカウント番号](https://docs.stripe.com/financial-connections/tokenized-account-numbers.md)が無効化されると決済が失敗します。 | テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。 ### 少額入金の金額と明細書表記コードをテストする さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。 | 少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ | | ------------- | --------------- | ------------------------- | | `32` および `45` | SM11AA | アカウントの確認をシミュレーションします。 | | `10` および `11` | SM33CC | 許容された確認回数の超過をシミュレーションします。 | | `40` および `41` | SM44DD | 少額入金のタイムアウトをシミュレーションします。 | ### 売上処理の動作をテストする テスト取引は即座に売上として処理され、利用可能なテスト残高に追加されます。この動作は、利用可能な残高で取引が売上として処理されるまでに[数日](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#timing)かかることがある、本番環境とは異なります。 ## エラーコード 次の表に、一般的なエラーコードと推奨される対応の詳細を示します。 | エラーコード | 推奨される対応 | | --------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `payment_intent_invalid_currency` | 対応している通貨を入力してください。 | | `missing_required_parameter` | 必須パラメーターの詳細については、エラーメッセージをご確認ください。 | | `payment_intent_payment_attempt_failed` | このコードは、PaymentIntent の [last_payment_error.code](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-last_payment_error-code) フィールドに表示されることがあります。エラーメッセージで、エラーの詳細な理由とエラー処理に関する提案を確認してください。 | | `payment_intent_authentication_failure` | このコードは、PaymentIntent の[last_payment_error.code](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-last_payment_error-code) フィールドに表示されることがあります。エラーメッセージで、詳細な失敗理由とエラー処理に関する推奨事項を確認してください。このエラーは、統合のテスト時に失敗を手動でトリガーした場合に発生します。 | | `payment_intent_redirect_confirmation_without_return_url` | PaymentIntent を確定する際は、`return_url` を指定します。 | ## Optional: Financial Connections 銀行口座のデータにアクセスする Financial Connections の手数料については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 支払いインテントの作成時に追加の[データ権限](https://docs.stripe.com/financial-connections/fundamentals.md#data-permissions)をリクエストした場合にのみ、[Financial Connections](https://docs.stripe.com/financial-connections.md) データにアクセスできます。 顧客が [Stripe Financial Connections の認証フロー](https://docs.stripe.com/financial-connections/fundamentals.md#authentication-flow)を正常に完了したときに返される `us_bank_account` PaymentMethod には、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)を指す [financial_connections_account](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-us_bank_account-financial_connections_account) ID が含まれます。この ID を使用して、アカウントデータにアクセスします。 > 顧客が手動入力と少額入金によって関連付ける銀行口座は、決済手段に `financial_connections_account` ID を持ちません。 Financial Connections のアカウント ID を確認するには、Payment Intent を取得して `payment_intent.payment_method` 属性を展開します。 ```curl curl -G https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}} \ -u "<>:" \ -d "expand[]=payment_method" ``` ```json { "payment_intent": { "id": "{{PAYMENT_INTENT_ID}}", "object": "payment_intent", // ... "payment_method": { "id": "{{PAYMENT_METHOD_ID}}", // ... "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK","financial_connections_account": "{{FINANCIAL_CONNECTIONS_ACCOUNT_ID}}", "fingerprint": "q9qchffggRjlX2tb", "last4": "6789", "routing_number": "110000000" } } // ... } } ``` ## Optional: 不審請求の申請を解決する [サーバー側] 一般的に、顧客は銀行を通じて、個人口座では引き落とし後 60 日以内、事業用口座では 2 営業日以内に [ACH Direct Debit 決済に対する不審請求の申し立て](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#resolving-disputes)を行うことができます。まれなケースとして、この申し立て期限を過ぎてからでも、引き落としに対して不審請求の申し立てを行える場合があります。 顧客が決済に対して不審請求を申請すると、Stripe は [charge.dispute.closed](https://docs.stripe.com/api/events/types.md#event_types-charge.dispute.closed) Webhook イベントを送信し、PaymentMethod のオーソリは取り消されます。 まれに、PaymentIntent が `succeeded` に変わった後に、Stripe が銀行から ACH の失敗を受け取ることがあります。この場合、Stripe は以下の `reason` で不審請求の申請を作成します。 - `insufficient_funds` - `incorrect_account_details` - `bank_can't_process` この場合、Stripe は失敗の手数料を請求します。 この PaymentMethod を再利用する今後の決済では、次のエラーが返されます。 ```javascript { "error": { "message": "This PaymentIntent requires a mandate, but no existing mandate was found. Collect mandate acceptance from the customer and try again, providing acceptance data in the mandate_data parameter.", "payment_intent": { ... } "type": "invalid_request_error" } } ``` このエラーには、`requires_confirmation` の状態の PaymentIntent が含まれています。決済を続けるには、以下を行う必要があります。 1. 今後の決済で不審請求の申し立てが認められないように、顧客との不審請求の申し立てを解決します。 1. 顧客からの承認をもう一度確認します。 支払いの承認を確認するには、[Stripe.js を使用してオンラインで顧客から同意書の承認を収集する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md?platform=web#web-collect-mandate-and-submit)か、Stripe API を使用してオフラインで確認します。 > 顧客が同じ銀行口座からの複数の支払いに対して不審請求を申請する場合、Stripe は該当の銀行口座をブロックします。解決策については、[Stripe サポート](https://support.stripe.com/?contact=true)にお問い合わせください。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}}/confirm \ -u "<>:" \ -d "mandate_data[customer_acceptance][type]=offline" ``` ## Optional: 支払いの参照情報 支払い参照番号は銀行で生成され、これを使用して銀行口座の所有者は銀行で資金を確認できます。支払いが成功すると、ダッシュボードと [Charge オブジェクト](https://docs.stripe.com/api/charges/object.md)内に支払い参照番号が表示されます。 | 支払いの状態 | 支払いの参照値 | | ------ | ------------------------- | | 保留中 | 利用不可 | | 失敗 | 利用不可 | | 成功 | 利用可能 (091000015001234 など) | また、`charge.succeeded` Webhook を受け取ったら、`payment_method_details` の内容を確認して、[payment_reference](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-us_bank_account-payment_reference) を見つけます。 次のイベントの例は、成功した ACH 支払いと支払い参照番号を示しています。 #### charge-succeeded ```json { "id": "{{EVENT_ID}}", "object": "event", // omitted some fields in the example "type": "charge.succeeded", "data": { "object": { "id": "{{PAYMENT_ID}}", "object": "charge", //... "paid": true, "payment_intent": "{{PAYMENT_INTENT_ID}}", "payment_method": "{{PAYMENT_METHOD_ID}}", "payment_method_details": { "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK", "fingerprint": "Ih3foEnRvLXShyfB", "last4": "1000","payment_reference": "091000015001234", "routing_number": "110000000" } } // ... } } } ``` `destination_details` の内容を表示して、返金された ACH 支払いに関連付けられた [refund reference](https://docs.stripe.com/api/refunds/object.md#refund_object-destination_details-us_bank_transfer-reference) を見つけます。 次のイベントの例は、返金参照番号が指定された、成功した ACH 返金のレンダリングを示しています。 [返金](https://docs.stripe.com/refunds.md) の詳細をご覧ください。 #### charge-refund-updated ```json { "id": "{{EVENT_ID}}", "object": "event", "type": "charge.refund.updated", "data": { "object": { "id": "{{REFUND_ID}}", "object": "refund", //... "payment_intent": "{{PAYMENT_INTENT_ID}}", "destination_details": { "type": "us_bank_transfer", "us_bank_transfer": {"reference": "091000015001111", "reference_status": "available" } } // ... } } } ``` ## Optional: 顧客の振替日を設定する [サーバー側] [予定期日](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-payment_method_options-us_bank_account-target_date)を指定して、Stripe が顧客の銀行口座から引き落としを行う日付を制御できます。予定期日は、現在の日付から 3~15 日以内の日付に指定しなければなりません。 目標期日は、売上が顧客の口座を離れる日を期日指定します。設定日の 3 営業日前までの目標期日を設定された [PaymentIntent をキャンセル](https://docs.stripe.com/api/payment_intents/cancel.md)できます。 次のいずれかの条件を満たす予定期日は、翌営業日まで引き落としが延期されます。 - 週末、祝日、またはその他の非営業日に当たる予定期日。 - 3 営業日以内に到来する予定期日。 このパラメーターは、ベストエフォート方式で機能します。顧客の銀行は、祝日の関係やその他の理由により、異なる日付に引き落としを処理する場合があります。 > [target date (目標期日)](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-payment_method_options-us_bank_account-target_date) を使用する場合は、[認証方法](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-payment_method_options-us_bank_account-verification_method)を `microdeposits` に設定することはできません。これは、確認プロセスが目標期日よりも長くなり、支払いの到着が予定よりも遅れる可能性があるためです。 # ダイレクト API > This is a ダイレクト API for when payment-ui is direct-api. View the full page at https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=direct-api. Web サイトでの ACH ダイレクトデビットによる決済の受け付けは、以下のように構成されます。 - 決済を追跡するためのオブジェクトを作成する - [Stripe Financial Connections](https://docs.stripe.com/financial-connections.md) によって有効化される即時確認を使用して、支払い方法の情報を収集する - 決済を処理するために Stripe に送信する - 顧客の銀行口座を確認する ACH ダイレクトデビットは[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法であるため、決済後すぐには売上が利用可能になりません。通常、決済金額がお客様のアカウントに入金されるまでに 4 営業日かかります。 Stripe では、[Payment Intent (支払いインテント)](https://docs.stripe.com/payments/payment-intents.md) と呼ばれる決済オブジェクトを使用して、決済が完了するまでの状態のすべてを追跡および処理します。 > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. ## Stripe を設定する [サーバー側] まず、Stripe アカウントが必要です。[今すぐ登録](https://dashboard.stripe.com/register)してください。 アプリケーションから Stripe API にアクセスするには、Stripe の公式ライブラリを使用します。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem '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 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. #### Accounts v2 ユーザーがあなたのビジネスでアカウントを作成したときに、顧客が設定する [Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer) オブジェクトを作成するか、このユーザーに関連付けられた既存の `Account` を取得します。`Account` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Account` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "{{CUSTOMER_EMAIL}}" }' ``` #### Customers v1 ユーザーがあなたのビジネスでアカウントを作成したときに、*Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments)オブジェクトを作成するか、このユーザーに関連付けられた既存の `Customer` を取得します。`Customer` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Customer` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d email={{CUSTOMER_EMAIL}} ``` ## PaymentIntent を作成する [サーバー側] [PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents.md) は、顧客から支払いを回収する意図を表すオブジェクトで、決済プロセスのライフサイクルの各段階を追跡します。 サーバーで PaymentIntent を作成し、回収する金額と `usd` 通貨を指定します。すでに Payment Intents API を使用した連携がある場合は、PaymentIntent の `us_bank_account` を[決済手段タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)のリストに追加します。顧客の ID を指定します。 将来その支払い方法を再利用する場合には、値を `off_session` に設定して [setup_future_usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage) パラメーターを指定します。 Financial Connections 手数料の詳細については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 デフォルトでは、銀行口座の支払い情報の収集では、手動の口座番号入力と少額入金の確認のフォールバックオプションを使用し、[Financial Connections](https://docs.stripe.com/financial-connections.md) で顧客のアカウントを即時確認します。Financial Connections を設定し、ACH の実装を最適化するために追加の口座データにアクセスする方法については、[Financial Connections に関するドキュメント](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md)をご覧ください。たとえば、Financial Connections を使用して、ACH 決済の開始前にアカウントの残高を確認できます。 > 顧客がアカウントを認証した後で、追加データにアクセスを拡張するには、権限を拡張してアカウントを再度関連付ける必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` ### client secret を取得する PaymentIntent には、*client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これは、支払いプロセスを安全に完了するためにクライアント側で使用されます。client secret をクライアント側に渡す際は、いくつかの方法を使用できます。 #### 1 ページのアプリケーション ブラウザーの `fetch` 関数を使用して、サーバーのエンドポイントから client secret を取得します。この方法は、クライアント側が 1 ページのアプリケーションで、特に React などの最新のフロントエンドフレームワークで構築されている場合に最適です。client secret を処理するサーバーのエンドポイントを作成します。 #### Ruby ```ruby get '/secret' do intent = # ... Create or retrieve the PaymentIntent {client_secret: intent.client_secret}.to_json end ``` その後、クライアント側で JavaScript を使用して client secret を取得します。 ```javascript (async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })(); ``` #### サーバ側のレンダリング サーバーからクライアントに client secret を渡します。この方法は、アプリケーションがブラウザーへの送信前に静的なコンテンツをサーバーで生成する場合に最適です。 決済フォームに [client_secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) を追加します。サーバー側のコードで、PaymentIntent から client secret を取得します。 #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the PaymentIntent erb :checkout end ``` ## 支払い方法の詳細を収集する [クライアント側] 顧客が ACH Direct Debitでの支払いをクリックしたときに、Stripe.js を使用してその支払いを Stripe に送信することをお勧めします。[Stripe.js](https://docs.stripe.com/payments/elements.md) は、決済フローを構築するための Stripe の基本的な JavaScript ライブラリです。これにより、実装に関する複雑な処理が自動的に行われ、将来、他の決済手段にも対応できるように実装を簡単に拡張できます。 Stripe.js スクリプトを決済ページに含めるには、このスクリプトを HTML ファイルの `head` に追加します。 ```html Checkout ``` 決済ページで以下の JavaScript を使用して、Stripe.js のインスタンスを作成します。 ```javascript // 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('<>'); ``` PaymentIntent オブジェクト全体をクライアントに送信する代わりに、前のステップからの *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) を使用します。これは、Stripe API リクエストを認証する API キーとは異なります。 client secret は支払いを完了できるため、慎重に取り扱う必要があります。記録したり、URL に埋め込んだり、当該の顧客以外に漏洩することがないようにしてください。 [stripe.collectBankAccountForPayment](https://docs.stripe.com/js/payment_intents/collect_bank_account_for_payment) を使用して、[Financial Connections](https://docs.stripe.com/financial-connections.md) で銀行口座の詳細を収集し、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) を作成して PaymentIntent に関連付けます。ACH ダイレクトデビットの PaymentMethod を作成するには、`billing_details` パラメーターに口座名義人を含める必要があります。 ```javascript // 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 認証フロー](https://docs.stripe.com/financial-connections/fundamentals.md#authentication-flow)では、銀行口座の詳細の収集と確認を自動的に処理します。顧客が認証フローを完了すると、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) が自動的に PaymentIntent に関連付けられ、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)が作成されます。 > 手動入力と少額入金によって顧客が関連付けた銀行口座では、残高、所有権、取引などの追加の銀行口座データにアクセスできません。 すべてのデバイスで最適なユーザー体験を提供できるように、ビューポートの `meta` タグを使用して、ページのビューポートの `minimum-scale` を 1 に設定します。 ```html ``` ## Optional: Financial Connections 銀行口座のデータにアクセスする [サーバー側] PaymentIntent の作成時に、追加の[データ権限](https://docs.stripe.com/financial-connections/fundamentals.md#data-permissions)をリクエストする場合にのみ、Financial Connections データにアクセスできます。 顧客が[Stripe Financial Connections 認証フロー](https://docs.stripe.com/financial-connections/fundamentals.md#authentication-flow)を完了すると、返される `us_bank_account` PaymentMethod には、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)を指す [financial_connections_account](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-us_bank_account-financial_connections_account) ID が含まれます。この ID を使用して口座データにアクセスします。 > 顧客が手動入力および少額入金によって関連付けた銀行口座には、Payment Method の `financial_connections_account` ID がありません。 Financial Connections アカウント ID を特定するには、PaymentIntent を取得して `payment_method` 属性を拡張します。 ```curl curl -G https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}} \ -u "<>:" \ -d "expand[]=payment_method" ``` ```json { "id": "{{PAYMENT_INTENT_ID}}", "object": "payment_intent", // ... "payment_method": { "id": "{{PAYMENT_METHOD_ID}}", // ... "type": "us_bank_account" "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK","financial_connections_account": "{{FINANCIAL_CONNECTIONS_ACCOUNT_ID}}", "fingerprint": "q9qchffggRjlX2tb", "last4": "6789", "routing_number": "110000000" } } // ... } ``` `balances` 権限の取得を選択した場合、この段階で残高を確認して、支払いの確定前に十分な資金があることを確認することをお勧めします。 追加の口座データを使用して、[Financial Connections](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md#optimize) で ACH の実装を最適化する方法をご紹介します。 ## 同意書承認を収集し、決済を送信する [クライアント側] 支払いを開始する前に、顧客に同意書の規約を表示して、顧客から承認を得る必要があります。 Nacha の運営規則に準拠するため、決済を開始する前に、同意書の規約を表示して顧客から承認を得る必要があります。[同意書](https://docs.stripe.com/payments/ach-direct-debit.md#mandates)の詳細については、こちらの記事をご覧ください。 顧客が同意書の規約を承認する場合、PaymentIntent を確定する必要があります。顧客がフォームを送信したら、[stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) を使用して支払いを完了します。 ```javascript 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](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) の完了には数秒かかる場合があります。この間、フォームが再送信されないように無効化し、待機中のインジケーター (スピナーなど) を表示します。エラーが発生した場合は、それを顧客に表示し、フォームを再度有効化し、待機中のインジケーターを非表示にします。 成功した場合、Stripe から以下のいずれかのステータスで PaymentIntent オブジェクトが返されます。 | ステータス | 説明 | 次のステップ | | ----------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `requires_action` | 銀行口座の確認を完了するには、追加のアクションが必要です。 | ステップ 6: [少額入金で銀行口座を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#web-verify-with-microdeposits) | | `processing` | 銀行口座が即座に確認されたか、確認が必要ありません。 | ステップ 7: [PaymentIntent の成功を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#web-confirm-paymentintent-succeeded) | PaymentIntent の確定に成功した後、同意書の確認メールと収集した銀行口座情報を顧客に送信する必要があります。Stripe はデフォルトでこれらの処理を行いますが、ご希望に応じて[カスタム通知の送信](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を選択することもできます。 ## 少額入金で銀行口座を確認する [クライアント側] すべての顧客が銀行口座を即時に確認できるわけではありません。このステップは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。 このような場合、Stripe は `descriptor_code` による少額入金を送金し、銀行口座の確認でさらに問題が発生した場合には、`amount` による少額入金に戻る場合があります。これらの入金が顧客のオンライン明細書に表示されるには 1 ~ 2 営業日かかります。 - **明細書表記コード**。SM で始まる一意の 6 桁の `descriptor_code` を指定して、0.01 USD の 1 件の少額入金を顧客の銀行口座に送金します。顧客は、この文字列を使用して、銀行口座を確認します。 - **金額**。Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は、この入金額を使用して銀行口座を確認します。 前のステップの [stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) メソッドの呼び出しの結果として、`requires_action` 状態の PaymentIntent が返されます。この PaymentIntent には、確認を完了するための有益な情報を含む `next_action` フィールドが含まれています。 ```javascript next_action: { type: "verify_with_microdeposits", verify_with_microdeposits: { arrival_date: 1647586800, hosted_verification_url: "https://payments.stripe.com/…", microdeposit_type: "descriptor_code" } } ``` [請求書メール](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-billing_details-email)を指定した場合、Stripe はこのメールで入金の到着予定日を顧客に通知します。このメールには、Stripe がオンラインで提供する確認ページへのリンクが含まれ、顧客はそのページで入金額を確認して銀行口座の確認を完了することができます。 > 確認の失敗は、明細書表記ベースの少額入金の場合は 10 回、金額ベースの少額入金の場合は 3 回までです。この上限を超えると、Stripe は銀行口座を確認できなくなります。また、少額入金の確認は 10 日経過するとタイムアウトになります。この期間内に少額入金を確認できなかった場合、PaymentIntent は新しい支払い方法の詳細を要求する状態に戻ります。少額入金とは何か、どのように使用されるのかを顧客に明確に伝えることで、確認に関する問題を回避できます。 ### オプション: カスタムのメール通知を送信する 必要に応じて、顧客に[カスタムのメール通知](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を送信することができます。カスタムメールを設定した後は、顧客が確認メールに応答する方法を指定する必要があります。以下の方法のうち、いずれか _1 つ_を指定してください。 - Stripe 上のオンライン確認ページを使用します。これを行うには、[next_action](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-verify_with_microdeposits-hosted_verification_url) オブジェクトの `verify_with_microdeposits[hosted_verification_url]` URL を使用し、顧客に確認プロセスを完了するよう指示します。 - Stripe がオンラインで提供する確認ページを使用しない場合、ご自身のサイトにフォームを作成します。顧客はこのフォームを使用して少額入金の金額を伝え、[Stripe.js](https://docs.stripe.com/js/payment_intents/verify_microdeposits_for_payment) を使用して、銀行口座を確認します。 - 確認のために、少なくとも 6 桁のストリングの `descriptor code` パラメーターを処理するフォームを設定します。 - また Stripe では、`amounts` パラメーターも処理するようにフォームを設定することをお勧めします。これはこのパラメーターが、顧客が利用する一部の銀行で必要とされることがあるためです。 組み込みは、`descriptor_code` 「または」 `amounts` でのみ渡されます。組み込みでどちらが使用されているかを判断するには、`next_action` オブジェクトの `verify_with_microdeposits[microdeposit_type]` の値を確認します。 ```javascript 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](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.processing) *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) イベントを送信します。 確認が失敗する原因はいくつか存在します。失敗は直接的なエラー応答で同期的に発生することも、[payment_intent.payment_failed](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.failed) Webhook イベントを通じて非同期で発生することもあります (以下の例を参照してください)。 #### 同期エラー ```json { "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" } } ``` #### Webhook イベント ```javascript { "object": { "id": "pi_1234", "object": "payment_intent", "customer": "cus_0246", ... "last_payment_error": { "code": "payment_method_microdeposit_verification_attempts_exceeded", "message": "You have exceeded the number of allowed verification attempts.", }, ... "status": "requires_payment_method" } } ``` | エラーコード | 同期または非同期 | メッセージ | ステータスの変化 | | ------------------------------------------------------------ | ----------------------------- | ------------------------------------------------------------------ | -------------------------------------------------------------------- | | `payment_method_microdeposit_failed` | 同期、または Webhook イベントを通じて非同期で発生 | 少額入金に失敗しました。指定した銀行口座、金融機関、支店の番号を確認してください | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | | `payment_method_microdeposit_verification_amounts_mismatch` | 同期 | 指定された金額が銀行口座に送金された金額と一致しません。確認試行の残り回数はあと {attempts_remaining} 回です。 | 変化なし | | `payment_method_microdeposit_verification_attempts_exceeded` | 同期、または Webhook イベントを通じて非同期で発生 | 許容された確認の試行回数を超えました | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | | `payment_method_microdeposit_verification_timeout` | Webhook イベントを通じて非同期で発生 | 少額入金がタイムアウトになりました。顧客は要求された 10 日の期間内に銀行口座を確認しませんでした。 | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | ## PaymentIntent の成功を確認する [サーバー側] ACH ダイレクトデビットは、[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法です。このため、顧客の口座から引き落としを開始してから、決済の成功または失敗の通知を受けるまでに最大で 4 営業日かかります。 PaymentIntent を作成すると、その初期ステータスは `processing` となります。決済が成功すると、PaymentIntent のステータスは `processing` から `succeeded` に更新されます。 [Webhook](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks) を使用して決済が成功したことを*確認* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)し、顧客に決済完了を通知することをお勧めします。[Stripe ダッシュボード](https://dashboard.stripe.com/events)でイベントを表示することもできます。 #### PaymentIntent のイベント PaymentIntent のステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | | `payment_intent.processing` | 顧客の支払いは、Stripe に正常に送信されました。 | 開始された決済の成功または失敗の結果を待ちます。 | | `payment_intent.succeeded` | 顧客の支払いが成功しました。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `payment_intent.payment_failed` | 顧客の支払いは拒否されました。これは、少額入金確認の失敗に適用されることもあります。 | 顧客にメールまたはプッシュ通知で連絡し、別の決済手段をリクエストします。少額入金の確認に失敗して Webhook が送信された場合、ユーザーは銀行口座情報の再入力を求められ、その後、新しい少額入金が口座に入金されます。 | #### Charge のイベント 追加の Charge Webhook を使用して、支払いのステータスを追跡することもできます。`charge.updated` Webhook を受け取ると、支払いをキャンセルできなくなります。 支払いのステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------ | -------------------------------------------------------------------------- | -------------------------------------------------------- | | `charge.pending` | 顧客の支払いは正常に作成されました。 | 開始された決済が処理されるまで待ちます。 | | `charge.updated` | 顧客の支払いは更新されました。このイベントは、新しい取引残高が作成されたか、支払いの説明またはメタデータが更新されたときに出される可能性があります。 | 開始された決済の成功または失敗の結果を待ちます。 | | `charge.succeeded` | 顧客の支払いが成功して、残高で売上を利用できます。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `charge.failed` | 顧客の支払いは失敗しました。 | 支払いの failure_code と failure_message を確認して、次のアクションを判断します。 | ## 組み込みをテストする [Financial Connections](https://docs.stripe.com/financial-connections/testing.md#web-how-to-use-test-accounts) を使用して即時確認を行うシナリオをテストする方法をご紹介します。 ### サンドボックスで取引メールを送信する 銀行口座の詳細を収集し、同意書を受け付けたら、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で同意書の確認メールと少額入金の確認メールを送信します。 ドメインが **{domain}** で、ユーザー名が **{username}** の場合、メール形式 **{username}+test\_email@{domain}** を使用してテスト取引メールを送信します。 たとえば、ドメインが **example.com** でユーザー名が **info** の場合、ACH Direct Debit 決済のテストには **info+test\_email@example.com** という形式を使用します。この形式により、メールが正しくルーティングされます。**+test\_email** サフィックスを含めない場合、メールは送信されません。 > テスト中にこれらのメールをトリガーする前に、Stripe [アカウントを設定](https://docs.stripe.com/get-started/account/set-up.md)する必要があります。 ### テスト用口座番号 Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。 | 口座番号 | トークン | 金融番号 | 動作 | | -------------- | -------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------- | | `000123456789` | `pm_usBankAccount_success` | `110000000` | 支払いは成功します。 | | `000111111113` | `pm_usBankAccount_accountClosed` | `110000000` | 口座が解約済みであるため、支払いは失敗します。 | | `000000004954` | `pm_usBankAccount_riskLevelHighest` | `110000000` | この支払いは、[不正利用のリスクが高い](https://docs.stripe.com/radar/risk-evaluation.md#high-risk)ため、Radar によってブロックされています。 | | `000111111116` | `pm_usBankAccount_noAccount` | `110000000` | 口座が見つからないため、支払いは失敗します。 | | `000222222227` | `pm_usBankAccount_insufficientFunds` | `110000000` | 残高不足のため、支払いは失敗します。 | | `000333333335` | `pm_usBankAccount_debitNotAuthorized` | `110000000` | 引き落としがオーソリされていないため、支払いは失敗します。 | | `000444444440` | `pm_usBankAccount_invalidCurrency` | `110000000` | 通貨が無効であるため、支払いは失敗します。 | | `000666666661` | `pm_usBankAccount_failMicrodeposits` | `110000000` | 支払いで少額入金の送金が失敗します。 | | `000555555559` | `pm_usBankAccount_dispute` | `110000000` | 支払いによって不審請求の申請が開始されています。 | | `000000000009` | `pm_usBankAccount_processing` | `110000000` | 支払いは無期限に処理中のままになります。 [PaymentIntent キャンセル](https://docs.stripe.com/api/payment_intents/cancel.md) をテストするのに役立ちます。 | | `000777777771` | `pm_usBankAccount_weeklyLimitExceeded` | `110000000` | 支払い額がアカウントの週次支払い額の上限を超えているため、支払いが失敗しました。 | | `000888888885` | | `110000000` | [トークン化されたアカウント番号](https://docs.stripe.com/financial-connections/tokenized-account-numbers.md)が無効化されると決済が失敗します。 | テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。 ### 少額入金の金額と明細書表記コードをテストする さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。 | 少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ | | ------------- | --------------- | ------------------------- | | `32` および `45` | SM11AA | アカウントの確認をシミュレーションします。 | | `10` および `11` | SM33CC | 許容された確認回数の超過をシミュレーションします。 | | `40` および `41` | SM44DD | 少額入金のタイムアウトをシミュレーションします。 | ### 売上処理の動作をテストする テスト取引は即座に売上として処理され、利用可能なテスト残高に追加されます。この動作は、利用可能な残高で取引が売上として処理されるまでに[数日](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#timing)かかることがある、本番環境とは異なります。 ## Optional: 即時の確認のみ [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、銀行口座の即時確認のみを要求するように設定することもできます。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` これにより、少額入金の確認を処理する必要はなくなりますが、即時確認に失敗した場合は、PaymentIntent のステータスは、顧客の銀行口座の即時確認に失敗したことを示す `requires_payment_method` となります。 ## Optional: 少額入金のみによる確認 [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、少額入金による確認のみを要求するように設定することもできます。 > カスタムの決済フォームを使用している場合、自社の UI を構築して銀行口座の詳細を収集する必要があります。Stripe の少額入金に関するメールを無効にしている場合は、少額入金のコードまたは金額を確認するために顧客用の自社の UI を構築する必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` 自社のフォームで顧客の銀行口座を収集し、その詳細を使用して [stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) を呼び出し、PaymentIntent を完了する必要があります。 ```javascript var form = document.getElementById('payment-form'); var accountholderName = document.getElementById('accountholder-name'); var email = document.getElementById('email'); var accountNumber = document.getElementById('account-number'); var routingNumber = document.getElementById('routing-number'); var accountHolderType= document.getElementById('account-holder-type'); var submitButton = document.getElementById('submit-button'); var clientSecret = submitButton.dataset.secret; form.addEventListener('submit', function(event) { event.preventDefault(); stripe.confirmUsBankAccountPayment(clientSecret, { payment_method: { billing_details: { name: accountholderName.value, email: email.value, }, us_bank_account: { account_number: accountNumber.value, routing_number: routingNumber.value, account_holder_type: accountHolderType.value, // 'individual' or 'company' }, }, }) .then(({paymentIntent, error}) => { if (error) { // Inform the customer that there was an error. console.log(error.message); } else { // Handle next step based on the intent's status. console.log("PaymentIntent ID: " + paymentIntent.id); console.log("PaymentIntent status: " + paymentIntent.status); } }); }); ``` ## Optional: 不審請求の申請を解決する [サーバー側] 一般的に、顧客は銀行を通じて、個人口座では引き落とし後 60 日以内、事業用口座では 2 営業日以内に [ACH Direct Debit 決済に対する不審請求の申し立て](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#resolving-disputes)を行うことができます。まれなケースとして、この申し立て期限を過ぎてからでも、引き落としに対して不審請求の申し立てを行える場合があります。 顧客が決済に対して不審請求を申請すると、Stripe は [charge.dispute.closed](https://docs.stripe.com/api/events/types.md#event_types-charge.dispute.closed) Webhook イベントを送信し、PaymentMethod のオーソリは取り消されます。 まれに、PaymentIntent が `succeeded` に変わった後に、Stripe が銀行から ACH の失敗を受け取ることがあります。この場合、Stripe は以下の `reason` で不審請求の申請を作成します。 - `insufficient_funds` - `incorrect_account_details` - `bank_can't_process` この場合、Stripe は失敗の手数料を請求します。 この PaymentMethod を再利用する今後の決済では、次のエラーが返されます。 ```javascript { "error": { "message": "This PaymentIntent requires a mandate, but no existing mandate was found. Collect mandate acceptance from the customer and try again, providing acceptance data in the mandate_data parameter.", "payment_intent": { ... } "type": "invalid_request_error" } } ``` このエラーには、`requires_confirmation` の状態の PaymentIntent が含まれています。決済を続けるには、以下を行う必要があります。 1. 今後の決済で不審請求の申し立てが認められないように、顧客との不審請求の申し立てを解決します。 1. 顧客からの承認をもう一度確認します。 支払いの承認を確認するには、[Stripe.js を使用してオンラインで顧客から同意書の承認を収集する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md?platform=web#web-collect-mandate-and-submit)か、Stripe API を使用してオフラインで確認します。 > 顧客が同じ銀行口座からの複数の支払いに対して不審請求を申請する場合、Stripe は該当の銀行口座をブロックします。解決策については、[Stripe サポート](https://support.stripe.com/?contact=true)にお問い合わせください。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}}/confirm \ -u "<>:" \ -d "mandate_data[customer_acceptance][type]=offline" ``` ## Optional: 支払いの参照情報 支払い参照番号は銀行で生成され、これを使用して銀行口座の所有者は銀行で資金を確認できます。支払いが成功すると、ダッシュボードと [Charge オブジェクト](https://docs.stripe.com/api/charges/object.md)内に支払い参照番号が表示されます。 | 支払いの状態 | 支払いの参照値 | | ------ | ------------------------- | | 保留中 | 利用不可 | | 失敗 | 利用不可 | | 成功 | 利用可能 (091000015001234 など) | また、`charge.succeeded` Webhook を受け取ったら、`payment_method_details` の内容を確認して、[payment_reference](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-us_bank_account-payment_reference) を見つけます。 次のイベントの例は、成功した ACH 支払いと支払い参照番号を示しています。 #### charge-succeeded ```json { "id": "{{EVENT_ID}}", "object": "event", // omitted some fields in the example "type": "charge.succeeded", "data": { "object": { "id": "{{PAYMENT_ID}}", "object": "charge", //... "paid": true, "payment_intent": "{{PAYMENT_INTENT_ID}}", "payment_method": "{{PAYMENT_METHOD_ID}}", "payment_method_details": { "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK", "fingerprint": "Ih3foEnRvLXShyfB", "last4": "1000","payment_reference": "091000015001234", "routing_number": "110000000" } } // ... } } } ``` `destination_details` の内容を表示して、返金された ACH 支払いに関連付けられた [refund reference](https://docs.stripe.com/api/refunds/object.md#refund_object-destination_details-us_bank_transfer-reference) を見つけます。 次のイベントの例は、返金参照番号が指定された、成功した ACH 返金のレンダリングを示しています。 [返金](https://docs.stripe.com/refunds.md) の詳細をご覧ください。 #### charge-refund-updated ```json { "id": "{{EVENT_ID}}", "object": "event", "type": "charge.refund.updated", "data": { "object": { "id": "{{REFUND_ID}}", "object": "refund", //... "payment_intent": "{{PAYMENT_INTENT_ID}}", "destination_details": { "type": "us_bank_transfer", "us_bank_transfer": {"reference": "091000015001111", "reference_status": "available" } } // ... } } } ``` ## Optional: 顧客の振替日を設定する [サーバー側] [予定期日](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-payment_method_options-us_bank_account-target_date)を指定して、Stripe が顧客の銀行口座から引き落としを行う日付を制御できます。予定期日は、現在の日付から 3~15 日以内の日付に指定しなければなりません。 目標期日は、売上が顧客の口座を離れる日を期日指定します。設定日の 3 営業日前までの目標期日を設定された [PaymentIntent をキャンセル](https://docs.stripe.com/api/payment_intents/cancel.md)できます。 次のいずれかの条件を満たす予定期日は、翌営業日まで引き落としが延期されます。 - 週末、祝日、またはその他の非営業日に当たる予定期日。 - 3 営業日以内に到来する予定期日。 このパラメーターは、ベストエフォート方式で機能します。顧客の銀行は、祝日の関係やその他の理由により、異なる日付に引き落としを処理する場合があります。 ## See also - [今後の支払いに備えて ACH Direct Debit のプレオーソリデビットの詳細を保存する](https://docs.stripe.com/payments/ach-direct-debit/set-up-payment.md) # iOS > This is a iOS for when payment-ui is mobile and platform is ios. View the full page at https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=mobile&platform=ios. > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. アプリでの ACH ダイレクトデビットによる決済の受け付けは、以下のように構成されます。 - 決済を追跡するためのオブジェクトを作成する - [Stripe Financial Connections](https://docs.stripe.com/financial-connections.md) によって有効化される即時確認を使用して、支払い方法の情報を収集する - 決済を処理するために Stripe に送信する - 顧客の銀行口座を確認する > ACH ダイレクトデビットは[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法であるため、決済後すぐには売上が利用可能になりません。通常、決済金額がお客様のアカウントに入金されるまでに 4 営業日かかります。 Stripe では、[Payment Intent (支払いインテント)](https://docs.stripe.com/payments/payment-intents.md) と呼ばれる決済オブジェクトを使用して、決済が完了するまでの状態のすべてを追跡および処理します。 [iOS SDK](https://github.com/stripe/stripe-ios) はオープンソースです。[詳細なドキュメントが提供されており](https://stripe.dev/stripe-ios/index.html)、iOS 13 以降をサポートするアプリと互換性があります。 #### Swift Package Manager SDK をインストールするには、以下のステップに従います。 1. Xcode で、**File (ファイル)** > **Add Package Dependencies… (パッケージ依存関係を追加)** を選択し、リポジトリー URL として `https://github.com/stripe/stripe-ios-spm` を入力します。 1. [リリースページ](https://github.com/stripe/stripe-ios/releases)から最新のバージョン番号を選択します。 1. **StripePayments** と **StripeFinancialConnections** 製品を[アプリのターゲット](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app)に追加します。 #### CocoaPods 1. まだインストールしていない場合は、[CocoaPods](https://guides.cocoapods.org/using/getting-started.html) の最新バージョンをインストールします。 1. 既存の [Podfile](https://guides.cocoapods.org/syntax/podfile.html) がない場合は、以下のコマンドを実行して作成します。 ```bash pod init ``` 1. この行を `Podfile` に追加します。 ```podfile pod 'Stripe' pod 'StripeFinancialConnections' ``` 1. 以下のコマンドを実行します。 ```bash pod install ``` 1. これ以降は、Xcode でプロジェクトを開く際に、`.xcodeproj` ファイルではなく、必ず `.xcworkspace` ファイルを使用するということを忘れないでください。 1. 今後、SDK の最新バージョンに更新するには、以下を実行します。 ```bash pod update Stripe pod update StripeFinancialConnections ``` #### Carthage 1. まだインストールしていない場合は、[Carthage](https://github.com/Carthage/Carthage#installing-carthage) の最新バージョンをインストールします。 1. この行を `Cartfile` に追加します。 ```cartfile github "stripe/stripe-ios" ``` 1. [Carthage のインストール手順](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos)に従います。必ず、[こちら](https://github.com/stripe/stripe-ios#releases)にリストされている必要なフレームワークのすべてを埋め込んでください。 1. 上記のリンクで必要とされるフレームワークに加え、フレームワーク **StripeFinancialConnections** も忘れずに追加してください。 1. 今後、SDK の最新バージョンに更新するには、以下のコマンドを実行します。 ```bash carthage update stripe-ios --platform ios ``` #### 手動のフレームワーク 1. Stripe の [GitHub リリースページ](https://github.com/stripe/stripe-ios/releases/latest)に移動して、**Stripe.xcframework.zip** をダウンロードして解凍します。 1. **Stripe.xcframework** を、Xcode プロジェクトの **General (一般) ** 設定の **Embedded Binaries (埋め込みバイナリ)** セクションにドラッグします。**Copy items if needed (必要に応じてアイテムをコピーする)** を必ず選択してください。 1. **StripeFinancialConnections.xcframework** に対し、ステップ 2 を繰り返します。 1. [こちら](https://github.com/stripe/stripe-ios#releases)にリストされている必要なフレームワークのすべてに対して、ステップ 2 を繰り返します。 1. 今後、Stripe の SDK の最新バージョンに更新するには、ステップ 1 ~ 3 を繰り返します。 > 最新の SDK リリースと過去のバージョンの詳細については、GitHub の[リリース](https://github.com/stripe/stripe-ios/releases) ページをご覧ください。新しいリリースの公開時に通知を受け取るには、[リポジトリーのリリースを確認してください](https://help.github.com/en/articles/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository)。 アプリの起動時に Stripe [公開可能キー](https://dashboard.stripe.com/test/apikeys)を使用して SDK を設定します。これにより、アプリが Stripe API にリクエストを送信できるようになります。 #### Swift ```swift import UIKitimportStripeFinancialConnections @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {StripeAPI.defaultPublishableKey = "<>" // do any other necessary launch configuration return true } } ``` > テストおよび開発時には[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 Stripe では、顧客の銀行口座を即座に確認できます。口座に関する追加データを取得する場合は、[Stripe Financial Connections](https://docs.stripe.com/financial-connections.md) を使用して[データアクセスを登録](https://dashboard.stripe.com/financial-connections/application)します。 Stripe Financial Connections を使用すると、金融口座をビジネスに関連付けることで、顧客が財務データを安全に共有できます。Financial Connections を使用して、トークン化された口座番号と金融番号、残高データ、所有者の詳細、取引データなどの顧客に許可された財務データにアクセスします。 このデータにアクセスすることで、決済を開始する前に残高を確認するなどのアクションを実行し、残高不足による決済の失敗の可能性を減らすことができます。 Financial Connections を利用すると、ユーザーがより少ないステップで自身のアカウントをLinkに関連付け、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 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. #### Accounts v2 ユーザーがあなたのビジネスでアカウントを作成したときに、顧客が設定する [Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer) オブジェクトを作成するか、このユーザーに関連付けられた既存の `Account` を取得します。`Account` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Account` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "{{CUSTOMER_EMAIL}}" }' ``` #### Customers v1 ユーザーがあなたのビジネスでアカウントを作成したときに、*Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments)オブジェクトを作成するか、このユーザーに関連付けられた既存の `Customer` を取得します。`Customer` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Customer` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d email={{CUSTOMER_EMAIL}} ``` ## PaymentIntent を作成する [サーバー側] [クライアント側] [PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents.md) は、顧客から支払いを回収する意図を表すオブジェクトで、決済プロセスのライフサイクルの各段階を追跡します。 ### サーバー側 まず、サーバーで PaymentIntent を作成し、回収する金額と通貨 `usd` を指定します。Payment Intents API を使用した実装がすでにある場合は、PaymentIntent の[支払い方法タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)のリストに `us_bank_account` を追加します。オプションで、Customer の [ID](https://docs.stripe.com/api/customers/object.md#customer_object-id) を指定します。 将来その支払い方法を再利用する場合には、値を `off_session` に設定して [setup_future_usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage) パラメーターを指定します。 Financial Connections 手数料の詳細については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 デフォルトでは、銀行口座の支払い情報の収集では、手動の口座番号入力と少額入金の確認のフォールバックオプションを使用し、[Financial Connections](https://docs.stripe.com/financial-connections.md) で顧客のアカウントを即時確認します。Financial Connections を設定し、ACH の実装を最適化するために追加の口座データにアクセスする方法については、[Financial Connections に関するドキュメント](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md)をご覧ください。たとえば、Financial Connections を使用して、ACH 決済の開始前にアカウントの残高を確認できます。 > 顧客がアカウントを認証した後で、追加データにアクセスを拡張するには、権限を拡張してアカウントを再度関連付ける必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` ### クライアント側 返される PaymentIntent には *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これは、PaymentIntent オブジェクト全体を渡すことなく安全に決済を完了するために、クライアント側で使用されます。クライアント側で、サーバーに PaymentIntent をリクエストし、その client secret を保存します。 #### Swift ```swift import UIKit import StripePayments class CheckoutViewController: UIViewController { var paymentIntentClientSecret: String? func startCheckout() { // Request a PaymentIntent from your server and store its client secret } } ``` ## 戻り先 URL を設定する [クライアント側] 顧客はお客様のアプリから離れて、(Safari やバンキングアプリなどで) 認証する場合があります。ユーザーが認証後にアプリに自動的に戻れるようにするには、[カスタム URL スキームを構成](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app)し、URL を SDK に転送するようにアプリのデリゲートを設定します。Stripe は[ユニバーサルリンク](https://developer.apple.com/documentation/xcode/allowing-apps-and-websites-to-link-to-your-content)には対応していません。 > Stripe は、指定された戻り先 URL にパラメーターを追加する場合があります。パラメーターが追加された戻り先 URL がコードで拒否されないことを確認してください。 #### SceneDelegate #### Swift ```swift // This method handles opening custom URL schemes (for example, "your-app://stripe-redirect") func scene(_ scene: UIScene, openURLContexts URLContexts: Set) { guard let url = URLContexts.first?.url else { return } let stripeHandled = StripeAPI.handleURLCallback(with: url) if (!stripeHandled) { // This was not a Stripe url – handle the URL normally as you would } } ``` #### AppDelegate #### Swift ```swift // This method handles opening custom URL schemes (for example, "your-app://stripe-redirect") func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { let stripeHandled = StripeAPI.handleURLCallback(with: url) if (stripeHandled) { return true } else { // This was not a Stripe url – handle the URL normally as you would } return false } ``` #### SwiftUI #### Swift ```swift @main struct MyApp: App { var body: some Scene { WindowGroup { Text("Hello, world!").onOpenURL { incomingURL in let stripeHandled = StripeAPI.handleURLCallback(with: incomingURL) if (!stripeHandled) { // This was not a Stripe url – handle the URL normally as you would } } } } } ``` ## 支払い方法の詳細を収集する [クライアント側] ACH ダイレクトデビットで決済を成功させるには、顧客の氏名と (オプションで) メールアドレスが必要です。アプリで、必要な請求詳細を顧客から収集します。 - 顧客の氏名 (姓と名) - 顧客のメールアドレス `STPCollectBankAccountParams` でクラス関数 `collectUSBankAccountParams` を使用し、`collectBankAccountForPayment` を呼び出すために必要なパラメーターを作成します。ACH ダイレクトデビット PaymentMethod を作成するには、`billing_details` パラメーターに口座名義人を含める必要があります。 `STPBankAccountCollector` のインスタンスを作成して `collectBankAccountForPayment` を呼び出し、銀行口座情報を収集し、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) を作成し、その PaymentMethod を PaymentIntent に関連付けます。 #### Swift ```swift // Build params let collectParams = STPCollectBankAccountParams.collectUSBankAccountParams(with: name, email: email) // (optional) Configure the style let style: STPBankAccountCollectorUserInterfaceStyle = .alwaysLight let bankAccountCollector = STPBankAccountCollector(style: style) // Calling this method will display a modal for collecting bank account information bankAccountCollector.collectBankAccountForPayment(clientSecret: clientSecret, returnURL: "https://your-app-domain.com/stripe-redirect", params: collectParams, from: self) { intent, error in guard let intent = intent else { // handle error return } if case .requiresPaymentMethod = intent.status { // Customer canceled the Financial Connections modal. Present them with other // payment method type options. } else if case .requiresConfirmation = intent.status { // 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. } } ``` これにより、銀行口座の詳細の収集と銀行口座の確認を処理するモーダル UI が読み込まれます。処理が完了すると、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) が PaymentIntent に自動的に関連付けられます。 ## Optional: Financial Connections 銀行口座のデータにアクセスする [サーバー側] PaymentIntent の作成時に、追加の[データ権限](https://docs.stripe.com/financial-connections/fundamentals.md#data-permissions)をリクエストする場合にのみ、Financial Connections データにアクセスできます。 顧客が[Stripe Financial Connections 認証フロー](https://docs.stripe.com/financial-connections/fundamentals.md#authentication-flow)を完了すると、返される `us_bank_account` PaymentMethod には、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)を指す [financial_connections_account](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-us_bank_account-financial_connections_account) ID が含まれます。この ID を使用して口座データにアクセスします。 > 顧客が手動入力および少額入金によって関連付けた銀行口座には、Payment Method の `financial_connections_account` ID がありません。 Financial Connections アカウント ID を特定するには、PaymentIntent を取得して `payment_method` 属性を拡張します。 ```curl curl -G https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}} \ -u "<>:" \ -d "expand[]=payment_method" ``` ```json { "id": "{{PAYMENT_INTENT_ID}}", "object": "payment_intent", // ... "payment_method": { "id": "{{PAYMENT_METHOD_ID}}", // ... "type": "us_bank_account" "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK","financial_connections_account": "{{FINANCIAL_CONNECTIONS_ACCOUNT_ID}}", "fingerprint": "q9qchffggRjlX2tb", "last4": "6789", "routing_number": "110000000" } } // ... } ``` `balances` 権限の取得を選択した場合、この段階で残高を確認して、支払いの確定前に十分な資金があることを確認することをお勧めします。 追加の口座データを使用して、[Financial Connections](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md#optimize) で ACH の実装を最適化する方法をご紹介します。 ## 同意書承認を収集し、決済を送信する [クライアント側] 決済を開始する前に、同意書の規約を表示して顧客から承認を得る必要があります。 *Nacha* (Nacha is the governing body that oversees the ACH network) の運営規則に準拠するため、決済を開始する前に、同意書の規約を表示して顧客から承認を得る必要があります。[同意書](https://docs.stripe.com/payments/ach-direct-debit.md#mandates)の詳細については、こちらの記事をご覧ください。 顧客が同意書の規約を承認する際に、お客様は PaymentIntent を確定する必要があります。顧客がフォームを送信したら、`confirmPayment` を使用して、決済を完了します。 #### Swift ```swift let paymentIntentParams = STPPaymentIntentParams(clientSecret: clientSecret, paymentMethodType: .USBankAccount) STPPaymentHandler.shared().confirmPayment( paymentIntentParams, with: self ) { (status, intent, error) in switch status { case .failed: // Payment failed case .canceled: // Payment was canceled case .succeeded: // Payment succeeded @unknown default: fatalError() } } ``` > `confirmPayment` が完了するまでには数秒かかる場合があります。この間、フォームが再送信されないように無効化し、待機中のインジケーター (スピナーなど) を表示します。エラーが発生した場合は、それを顧客に表示し、フォームを再度有効化し、待機中のインジケーターを非表示にします。 成功した場合、Stripe から以下のいずれかのステータスで PaymentIntent オブジェクトが返されます。 | ステータス | 説明 | 次のステップ | | ----------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `requires_action` | 銀行口座の確認を完了するには、追加のアクションが必要です。 | ステップ 6: [少額入金で銀行口座を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#ios-verify-with-microdeposits) | | `processing` | 銀行口座が即座に確認されたか、確認が必要ありません。 | ステップ 7: [PaymentIntent の成功を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#ios-confirm-paymentintent-succeeded) | PaymentIntent の確定に成功した後、同意書の確認メールと収集した銀行口座情報を顧客に送信する必要があります。Stripe はデフォルトでこれらの処理を行いますが、ご希望に応じて[カスタム通知の送信](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を選択することもできます。 ## 少額入金で銀行口座を確認する [クライアント側] すべての顧客が銀行口座を即座に確認できるわけではありません。このステップは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。 このような場合、Stripe は `descriptor_code` による少額入金を送金し、銀行口座の確認でさらに問題が発生した場合には、`amount` による少額入金に戻る場合があります。これらの入金が顧客のオンライン明細書に表示されるには 1 ~ 2 営業日かかります。 - **明細書表記コード**。Stripe は、SM で始まる一意の 6 桁の `descriptor_code` を使用し、0.01 USD の 1 件の少額入金を顧客の銀行口座に送金します。顧客は、この文字列を使用して銀行口座を確認します。 - **金額**。Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は、この入金額を使用して銀行口座を確認します。 前のステップで行った `confirmPayment` メソッドの呼び出しの結果として、`requires_action` 状態のPaymentIntentが返されます。この PaymentIntent には、確認を完了するための有益な情報を含む [next_action](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-verify_with_microdeposits) フィールドが含まれています。 [請求書メール](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-billing_details-email)を指定した場合、Stripe はこのメールで入金の到着予定日を顧客に通知します。このメールには、Stripe がオンラインで提供する確認ページへのリンクが含まれ、顧客はそのページで入金額を確認して銀行口座の確認を完了することができます。 > 確認の失敗は、明細書表記ベースの少額入金の場合は 10 回、金額ベースの少額入金の場合は 3 回までです。この上限を超えると、Stripe は銀行口座を確認できなくなります。また、少額入金の確認は 10 日経過するとタイムアウトになります。この期間内に少額入金を確認できなかった場合、PaymentIntent は新しい支払い方法の詳細を要求する状態に戻ります。少額入金とは何か、どのように使用されるのかを顧客に明確に伝えることで、確認に関する問題を回避できます。 ### オプション: カスタムのメール通知を送信する また、顧客に[カスタムのメール通知](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を送信することもできます。カスタムメールを設定した後は、顧客が確認メールに応答する方法を指定する必要があります。以下の方法のうち、いずれか _1 つ_を指定してください。 - Stripe 上のオンライン確認ページを使用します。これを行うには、[next_action](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-verify_with_microdeposits-hosted_verification_url) オブジェクトの `verify_with_microdeposits[hosted_verification_url]` URL を使用し、顧客に確認プロセスを完了するよう指示します。 - Stripe がオンラインで提供する確認ページを使用しない場合には、ご自身のアプリにフォームを作成します。顧客はこのフォームを使用して少額入金の金額を伝え、iOS SDK を使用して銀行口座を確認します。 - 少なくとも `descriptor code` パラメーター (確認のための 6 桁の文字列) を処理するフォームを設定します。 - また Stripe では、`amounts` パラメーターも処理するようにフォームを設定することをお勧めします。これはこのパラメーターが、顧客が利用する一部の銀行で必要とされることがあるためです。 組み込みは、`descriptor_code` 「または」 `amounts` のみを渡します。組み込みでどちらが使用されるかを判断するには、`next_action` オブジェクトの `verify_with_microdeposits[microdeposit_type]` の値を確認します。 #### Swift ```swift // Use if you are using a descriptor code, do not use if you are using amounts STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(clientSecret: clientSecret, descriptorCode: descriptorCode, completion: { intent, error in }) // Use if you are using amounts, do not use if you are using descriptor code STPAPIClient.shared.verifyPaymentIntentWithMicrodeposits(clientSecret: clientSecret, firstAmount: firstAmount, secondAmount: secondAmount, completion: { intent, error in }) ``` 銀行口座の確認が成功すると、Stripe は、`processing` の `status` の PaymentIntent オブジェクトを返します。 確認が失敗する理由はいくつかあります。失敗は、直接的なエラー応答として同期的に発生します。 ```json { "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_method_microdeposit_failed` | 少額入金に失敗しました。指定した銀行口座、金融機関、支店の番号を確認してください。 | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | | `payment_method_microdeposit_verification_amounts_mismatch` | 指定された金額が銀行口座に送金された金額と一致しません。確認試行の残り回数はあと {attempts_remaining} 回です。 | 変化なし | | `payment_method_microdeposit_verification_attempts_exceeded` | 許容された確認の試行回数を超えました。 | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | ## PaymentIntent の成功を確認する [サーバー側] ACH ダイレクトデビットは、[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法です。このため、顧客の口座から引き落としを開始してから、決済の成功または失敗の通知を受けるまでに最大で 4 営業日かかります。 PaymentIntent を作成すると、その初期ステータスは `processing` となります。決済が成功すると、PaymentIntent のステータスは `processing` から `succeeded` に更新されます。 [Webhook](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks) を使用して決済が成功したことを*確認* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)し、顧客に決済完了を通知することをお勧めします。[Stripe ダッシュボード](https://dashboard.stripe.com/events)でイベントを表示することもできます。 #### PaymentIntent のイベント PaymentIntent のステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | | `payment_intent.processing` | 顧客の支払いは、Stripe に正常に送信されました。 | 開始された決済の成功または失敗の結果を待ちます。 | | `payment_intent.succeeded` | 顧客の支払いが成功しました。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `payment_intent.payment_failed` | 顧客の支払いは拒否されました。これは、少額入金確認の失敗に適用されることもあります。 | 顧客にメールまたはプッシュ通知で連絡し、別の決済手段をリクエストします。少額入金の確認に失敗して Webhook が送信された場合、ユーザーは銀行口座情報の再入力を求められ、その後、新しい少額入金が口座に入金されます。 | #### Charge のイベント 追加の Charge Webhook を使用して、支払いのステータスを追跡することもできます。`charge.updated` Webhook を受け取ると、支払いをキャンセルできなくなります。 支払いのステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------ | -------------------------------------------------------------------------- | -------------------------------------------------------- | | `charge.pending` | 顧客の支払いは正常に作成されました。 | 開始された決済が処理されるまで待ちます。 | | `charge.updated` | 顧客の支払いは更新されました。このイベントは、新しい取引残高が作成されたか、支払いの説明またはメタデータが更新されたときに出される可能性があります。 | 開始された決済の成功または失敗の結果を待ちます。 | | `charge.succeeded` | 顧客の支払いが成功して、残高で売上を利用できます。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `charge.failed` | 顧客の支払いは失敗しました。 | 支払いの failure_code と failure_message を確認して、次のアクションを判断します。 | ## 組み込みをテストする [Financial Connections](https://docs.stripe.com/financial-connections/testing.md#web-how-to-use-test-accounts) を使用して即時確認を行うシナリオをテストする方法をご紹介します。 ### サンドボックスで取引メールを送信する 銀行口座の詳細を収集し、同意書を受け付けたら、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で同意書の確認メールと少額入金の確認メールを送信します。 ドメインが **{domain}** で、ユーザー名が **{username}** の場合、メール形式 **{username}+test\_email@{domain}** を使用してテスト取引メールを送信します。 たとえば、ドメインが **example.com** でユーザー名が **info** の場合、ACH Direct Debit 決済のテストには **info+test\_email@example.com** という形式を使用します。この形式により、メールが正しくルーティングされます。**+test\_email** サフィックスを含めない場合、メールは送信されません。 > テスト中にこれらのメールをトリガーする前に、Stripe [アカウントを設定](https://docs.stripe.com/get-started/account/set-up.md)する必要があります。 ### テスト用口座番号 Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。 | 口座番号 | トークン | 金融番号 | 動作 | | -------------- | -------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------- | | `000123456789` | `pm_usBankAccount_success` | `110000000` | 支払いは成功します。 | | `000111111113` | `pm_usBankAccount_accountClosed` | `110000000` | 口座が解約済みであるため、支払いは失敗します。 | | `000000004954` | `pm_usBankAccount_riskLevelHighest` | `110000000` | この支払いは、[不正利用のリスクが高い](https://docs.stripe.com/radar/risk-evaluation.md#high-risk)ため、Radar によってブロックされています。 | | `000111111116` | `pm_usBankAccount_noAccount` | `110000000` | 口座が見つからないため、支払いは失敗します。 | | `000222222227` | `pm_usBankAccount_insufficientFunds` | `110000000` | 残高不足のため、支払いは失敗します。 | | `000333333335` | `pm_usBankAccount_debitNotAuthorized` | `110000000` | 引き落としがオーソリされていないため、支払いは失敗します。 | | `000444444440` | `pm_usBankAccount_invalidCurrency` | `110000000` | 通貨が無効であるため、支払いは失敗します。 | | `000666666661` | `pm_usBankAccount_failMicrodeposits` | `110000000` | 支払いで少額入金の送金が失敗します。 | | `000555555559` | `pm_usBankAccount_dispute` | `110000000` | 支払いによって不審請求の申請が開始されています。 | | `000000000009` | `pm_usBankAccount_processing` | `110000000` | 支払いは無期限に処理中のままになります。 [PaymentIntent キャンセル](https://docs.stripe.com/api/payment_intents/cancel.md) をテストするのに役立ちます。 | | `000777777771` | `pm_usBankAccount_weeklyLimitExceeded` | `110000000` | 支払い額がアカウントの週次支払い額の上限を超えているため、支払いが失敗しました。 | | `000888888885` | | `110000000` | [トークン化されたアカウント番号](https://docs.stripe.com/financial-connections/tokenized-account-numbers.md)が無効化されると決済が失敗します。 | テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。 ### 少額入金の金額と明細書表記コードをテストする さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。 | 少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ | | ------------- | --------------- | ------------------------- | | `32` および `45` | SM11AA | アカウントの確認をシミュレーションします。 | | `10` および `11` | SM33CC | 許容された確認回数の超過をシミュレーションします。 | | `40` および `41` | SM44DD | 少額入金のタイムアウトをシミュレーションします。 | ### 売上処理の動作をテストする テスト取引は即座に売上として処理され、利用可能なテスト残高に追加されます。この動作は、利用可能な残高で取引が売上として処理されるまでに[数日](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#timing)かかることがある、本番環境とは異なります。 ## Optional: 即時の確認のみ [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、銀行口座の即時確認のみを要求するように設定することもできます。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` これにより、少額入金の確認を処理する必要はなくなりますが、即時確認に失敗した場合は、PaymentIntent のステータスは、顧客の銀行口座の即時確認に失敗したことを示す `requires_payment_method` となります。 ## Optional: 少額入金のみによる確認 [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、少額入金による確認のみを要求するように設定することもできます。 > カスタムの決済フォームを使用している場合、自社の UI を構築して銀行口座の詳細を収集する必要があります。Stripe の少額入金に関するメールを無効にしている場合は、少額入金のコードまたは金額を確認するために顧客用の自社の UI を構築する必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` 自社のフォームで顧客の銀行口座を収集し、その詳細を使用して [stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) を呼び出し、PaymentIntent を完了する必要があります。 ```javascript var form = document.getElementById('payment-form'); var accountholderName = document.getElementById('accountholder-name'); var email = document.getElementById('email'); var accountNumber = document.getElementById('account-number'); var routingNumber = document.getElementById('routing-number'); var accountHolderType= document.getElementById('account-holder-type'); var submitButton = document.getElementById('submit-button'); var clientSecret = submitButton.dataset.secret; form.addEventListener('submit', function(event) { event.preventDefault(); stripe.confirmUsBankAccountPayment(clientSecret, { payment_method: { billing_details: { name: accountholderName.value, email: email.value, }, us_bank_account: { account_number: accountNumber.value, routing_number: routingNumber.value, account_holder_type: accountHolderType.value, // 'individual' or 'company' }, }, }) .then(({paymentIntent, error}) => { if (error) { // Inform the customer that there was an error. console.log(error.message); } else { // Handle next step based on the intent's status. console.log("PaymentIntent ID: " + paymentIntent.id); console.log("PaymentIntent status: " + paymentIntent.status); } }); }); ``` ## Optional: 支払いの参照情報 支払い参照番号は銀行で生成され、これを使用して銀行口座の所有者は銀行で資金を確認できます。支払いが成功すると、ダッシュボードと [Charge オブジェクト](https://docs.stripe.com/api/charges/object.md)内に支払い参照番号が表示されます。 | 支払いの状態 | 支払いの参照値 | | ------ | ------------------------- | | 保留中 | 利用不可 | | 失敗 | 利用不可 | | 成功 | 利用可能 (091000015001234 など) | また、`charge.succeeded` Webhook を受け取ったら、`payment_method_details` の内容を確認して、[payment_reference](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-us_bank_account-payment_reference) を見つけます。 次のイベントの例は、成功した ACH 支払いと支払い参照番号を示しています。 #### charge-succeeded ```json { "id": "{{EVENT_ID}}", "object": "event", // omitted some fields in the example "type": "charge.succeeded", "data": { "object": { "id": "{{PAYMENT_ID}}", "object": "charge", //... "paid": true, "payment_intent": "{{PAYMENT_INTENT_ID}}", "payment_method": "{{PAYMENT_METHOD_ID}}", "payment_method_details": { "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK", "fingerprint": "Ih3foEnRvLXShyfB", "last4": "1000","payment_reference": "091000015001234", "routing_number": "110000000" } } // ... } } } ``` `destination_details` の内容を表示して、返金された ACH 支払いに関連付けられた [refund reference](https://docs.stripe.com/api/refunds/object.md#refund_object-destination_details-us_bank_transfer-reference) を見つけます。 次のイベントの例は、返金参照番号が指定された、成功した ACH 返金のレンダリングを示しています。 [返金](https://docs.stripe.com/refunds.md) の詳細をご覧ください。 #### charge-refund-updated ```json { "id": "{{EVENT_ID}}", "object": "event", "type": "charge.refund.updated", "data": { "object": { "id": "{{REFUND_ID}}", "object": "refund", //... "payment_intent": "{{PAYMENT_INTENT_ID}}", "destination_details": { "type": "us_bank_transfer", "us_bank_transfer": {"reference": "091000015001111", "reference_status": "available" } } // ... } } } ``` ## See also - [今後の支払いに備えて ACH Direct Debit のプレオーソリデビットの詳細を保存する](https://docs.stripe.com/payments/ach-direct-debit/set-up-payment.md) # Android > This is a Android for when payment-ui is mobile and platform is android. View the full page at https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=mobile&platform=android. > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. アプリでの ACH ダイレクトデビットによる決済の受け付けは、以下のように構成されます。 - 支払いを追跡するためのオブジェクトを作成する - [Stripe Financial Connections](https://docs.stripe.com/financial-connections.md) によって有効化される即時確認を使用して、支払い方法の情報を収集する - 支払いを処理するために Stripe に送信する - 顧客の銀行口座を確認する > ACH ダイレクトデビットは[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法であるため、決済後すぐには売上が利用可能になりません。通常、決済金額がお客様のアカウントに入金されるまでに 4 営業日かかります。 Stripe では、[Payment Intent (支払いインテント)](https://docs.stripe.com/payments/payment-intents.md) と呼ばれる決済オブジェクトを使用して、決済が完了するまでの状態のすべてを追跡および処理します。 [Stripe Android SDK](https://github.com/stripe/stripe-android) はオープンソースであり、[詳細なドキュメントが提供されています](https://stripe.dev/stripe-android/)。 SDK をインストールするには、[app/build.gradle](https://developer.android.com/studio/build/dependencies) ファイルの `dependencies` ブロックに `stripe-android` および `financial-connections` を追加します。 #### Kotlin ```kotlin plugins { id("com.android.application") } android { ... } dependencies { // ... // Stripe Android SDK implementation("com.stripe:stripe-android:23.5.0") // Include the financial connections SDK to support US bank account as a payment method implementation("com.stripe:financial-connections:23.5.0") // Financial Connections SDK implementation("com.stripe:financial-connections:23.5.0") } ``` > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases](https://github.com/stripe/stripe-android/releases) ページをご覧ください。新しいリリースの公開時に通知を受け取るには、[リポジトリのリリースを確認](https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/configuring-notifications#configuring-your-watch-settings-for-an-individual-repository)してください。 Stripe の[公開可能キー](https://dashboard.stripe.com/apikeys)を使用して SDK を設定し、 `Application` サブクラスなどで、Stripe API へのリクエストを実行できるようにします。 #### Kotlin ```kotlin import com.stripe.android.PaymentConfiguration class MyApp : Application() { override fun onCreate() { super.onCreate() PaymentConfiguration.init( applicationContext, "<>" ) } } ``` > テストおよび開発時には[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 ## 顧客を作成または取得する [推奨] [サーバー側] > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. #### Accounts v2 ユーザーがあなたのビジネスでアカウントを作成したときに、顧客が設定する [Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer) オブジェクトを作成するか、このユーザーに関連付けられた既存の `Account` を取得します。`Account` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Account` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "{{CUSTOMER_EMAIL}}" }' ``` #### Customers v1 ユーザーがあなたのビジネスでアカウントを作成したときに、*Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments)オブジェクトを作成するか、このユーザーに関連付けられた既存の `Customer` を取得します。`Customer` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Customer` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d email={{CUSTOMER_EMAIL}} ``` ## PaymentIntent を作成する [サーバー側] [クライアント側] [PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents.md) は、顧客から支払いを回収する意図を表すオブジェクトで、決済プロセスのライフサイクルの各段階を追跡します。 ### サーバー側 まず、サーバーで PaymentIntent を作成し、回収する金額と通貨 `usd` を指定します。Payment Intents API を使用した実装がすでにある場合は、PaymentIntent の[支払い方法タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)のリストに `us_bank_account` を追加します。オプションで、Customer の [ID](https://docs.stripe.com/api/customers/object.md#customer_object-id) を指定します。 将来その支払い方法を再利用する場合には、値を `off_session` に設定して [setup_future_usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage) パラメーターを指定します。 Financial Connections 手数料の詳細については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 デフォルトでは、銀行口座の支払い情報の収集では、手動の口座番号入力と少額入金の確認のフォールバックオプションを使用し、[Financial Connections](https://docs.stripe.com/financial-connections.md) で顧客のアカウントを即時確認します。Financial Connections を設定し、ACH の実装を最適化するために追加の口座データにアクセスする方法については、[Financial Connections に関するドキュメント](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md)をご覧ください。たとえば、Financial Connections を使用して、ACH 決済の開始前にアカウントの残高を確認できます。 > 顧客がアカウントを認証した後で、追加データにアクセスを拡張するには、権限を拡張してアカウントを再度関連付ける必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` ### クライアント側 返される PaymentIntent には *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これは、PaymentIntent オブジェクト全体を渡すことなく安全に決済を完了するために、クライアント側で使用されます。クライアント側で、サーバーに PaymentIntent をリクエストし、その client secret を後続の API コールに使用します。 #### Kotlin ```kotlin import androidx.appcompat.app.AppCompatActivity class CheckoutActivity : AppCompatActivity() { private lateinit var paymentIntentClientSecret: String fun startCheckout() { // Request a PaymentIntent from your server and store its client secret } } ``` ## 支払い方法の詳細を収集する [クライアント側] ACH ダイレクトデビットで決済を成功させるには、顧客の氏名と (オプションで) メールアドレスが必要です。アプリで、必要な請求詳細を顧客から収集します。 - 顧客の氏名 (姓と名) - 顧客のメールアドレス `CollectBankAccountConfiguration.USBankAccount` を使用し、`presentWithPaymentIntent` を呼び出すために必要なパラメーターを作成します。 決済アクティビティーの onCreate 内で `CollectBankAccountLauncher` インスタンスを初期化して、結果を処理するためのメソッドを渡します。次に、`presentWithPaymentIntent` を呼び出して銀行口座情報を収集し、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) を作成して PaymentIntent に関連付けます。 #### Kotlin ```kotlin import androidx.appcompat.app.AppCompatActivity class CheckoutActivity : AppCompatActivity() { private lateinit var paymentIntentClientSecret: String private lateinit var collectBankAccountLauncher CollectBankAccountLauncher override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // Create collector collectBankAccountLauncher = CollectBankAccountLauncher.create( this ) { result: CollectBankAccountResult -> when (result) { is CollectBankAccountResult.Completed -> { val intent = result.response.intent if (intent.status === StripeIntent.Status.RequiresPaymentMethod) { // Customer canceled the Financial Connections modal. Present them with other // payment method type options. } else if (intent.status === StripeIntent.Status.RequiresConfirmation) { // 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. } } is CollectBankAccountResult.Cancelled -> { // handle cancellation } is CollectBankAccountResult.Failed -> { // handle error print("Error: ${result.error}") } } } } fun startCheckout() { // ... // Build params val configuration: CollectBankAccountConfiguration = CollectBankAccountConfiguration.USBankAccount( name, email ) // Calling this method will trigger the Financial Connections modal to be displayed collectBankAccountLauncher.presentWithPaymentIntent( publishableKey, paymentIntentClientSecret, collectParams ) } } ``` これにより、銀行口座の詳細の収集と銀行口座の確認を処理するモーダル UI が読み込まれます。処理が完了すると、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) が PaymentIntent に自動的に関連付けられます。 ## Optional: 画面をカスタマイズする [クライアント側] ### ダークモード `CollectBankAccountLauncher` は、デフォルトではユーザーのシステム全体の表示設定 (ライトモードとダークモード) に合わせて自動的に調整されます。これを変更するには、アプリでライトモードまたはダークモードを設定します。 #### Kotlin ```kotlin // force dark AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) // force light AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) ``` ## Optional: Financial Connections 銀行口座のデータにアクセスする [サーバー側] PaymentIntent の作成時に、追加の[データ権限](https://docs.stripe.com/financial-connections/fundamentals.md#data-permissions)をリクエストする場合にのみ、Financial Connections データにアクセスできます。 顧客が[Stripe Financial Connections 認証フロー](https://docs.stripe.com/financial-connections/fundamentals.md#authentication-flow)を完了すると、返される `us_bank_account` PaymentMethod には、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)を指す [financial_connections_account](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-us_bank_account-financial_connections_account) ID が含まれます。この ID を使用して口座データにアクセスします。 > 顧客が手動入力および少額入金によって関連付けた銀行口座には、Payment Method の `financial_connections_account` ID がありません。 Financial Connections アカウント ID を特定するには、PaymentIntent を取得して `payment_method` 属性を拡張します。 ```curl curl -G https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}} \ -u "<>:" \ -d "expand[]=payment_method" ``` ```json { "id": "{{PAYMENT_INTENT_ID}}", "object": "payment_intent", // ... "payment_method": { "id": "{{PAYMENT_METHOD_ID}}", // ... "type": "us_bank_account" "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK","financial_connections_account": "{{FINANCIAL_CONNECTIONS_ACCOUNT_ID}}", "fingerprint": "q9qchffggRjlX2tb", "last4": "6789", "routing_number": "110000000" } } // ... } ``` `balances` 権限の取得を選択した場合、この段階で残高を確認して、支払いの確定前に十分な資金があることを確認することをお勧めします。 追加の口座データを使用して、[Financial Connections](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md#optimize) で ACH の実装を最適化する方法をご紹介します。 ## 同意書承認を収集し、支払いを送信する [クライアント側] 決済を開始する前に、同意書の規約を表示して顧客から承認を得る必要があります。 *Nacha* (Nacha is the governing body that oversees the ACH network) の運営規則に準拠するため、決済を開始する前に、同意書の規約を表示して顧客から承認を得る必要があります。[同意書](https://docs.stripe.com/payments/ach-direct-debit.md#mandates)の詳細については、こちらの記事をご覧ください。 顧客が同意書の規約を承認する際、Payment を確定する必要があります。顧客がフォームを送信したら、`confirm` を使用して決済を完了します。 #### Kotlin ```kotlin class CheckoutActivity : AppCompatActivity() { // ... private lateinit var paymentIntentClientSecret: String private val paymentLauncher: PaymentLauncher by lazy { val paymentConfiguration = PaymentConfiguration.getInstance(applicationContext) PaymentLauncher.Companion.create( this, paymentConfiguration.publishableKey, paymentConfiguration.stripeAccountId, ::onPaymentResult ) } private fun startCheckout() { // ... val confirmParams = ConfirmPaymentIntentParams.create( clientSecret = paymentIntentClientSecret, paymentMethodType = PaymentMethod.Type.USBankAccount ) paymentLauncher.confirm(confirmParams) } private fun onPaymentResult(paymentResult: PaymentResult) { when (paymentResult) { is PaymentResult.Completed -> { // show success UI } is PaymentResult.Canceled -> { // handle cancel flow } is PaymentResult.Failed -> { // handle failures // (for example, the customer might need to choose a new payment // method) } } } } ``` > `confirm` が完了するまでには数秒かかる場合があります。この間、フォームが再送信されないように無効化し、待機中のインジケーター (スピナーなど) を表示します。エラーが発生した場合には顧客に表示して、フォームを再度有効化し、待機中のインジケーターを非表示にします。 成功した場合、Stripe から以下のいずれかのステータスで PaymentIntent オブジェクトが返されます。 | ステータス | 説明 | 次のステップ | | ----------------- | ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | `requires_action` | 銀行口座の確認を完了するには、追加のアクションが必要です。 | ステップ 5: [少額入金で銀行口座を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#android-verify-with-microdeposits) | | `processing` | 銀行口座が即座に確認されたか、確認が不要です。 | ステップ 6: [PaymentIntent の成功を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#android-confirm-paymentintent-succeeded) | Payment の確定に成功した後、同意書の確認メールと収集した銀行口座情報を顧客に送信する必要があります。Stripe はデフォルトでこれらの処理を行いますが、ご希望に応じて[カスタム通知の送信](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を選択することもできます。 ## 少額入金で銀行口座を確認する [クライアント側] すべての顧客が銀行口座を即時に確認できるわけではありません。このステップは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。 このような場合、Stripe は `descriptor_code` による少額入金を送金し、銀行口座の確認でさらに問題が発生した場合には、`amount` による少額入金に戻る場合があります。これらの入金が顧客のオンライン明細書に表示されるには 1 ~ 2 営業日かかります。 - **明細書表記コード**。Stripe は、SM で始まる一意の 6 桁の `descriptor_code` を使用し、0.01 USD の 1 件の少額入金を顧客の銀行口座に送金します。顧客は、この文字列を使用して銀行口座を確認します。 - **金額**。Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は、この入金額を使用して銀行口座を確認します。 前のステップで行った `confirmPayment` メソッドの呼び出しの結果として、`requires_action` 状態のPaymentIntentが返されます。この PaymentIntent には、確認を完了するための有益な情報を含む [next_action](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-verify_with_microdeposits) フィールドが含まれています。 [請求書メール](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-billing_details-email)を指定した場合、Stripe はこのメールで入金の到着予定日を顧客に通知します。このメールには、Stripe がオンラインで提供する確認ページへのリンクが含まれ、顧客はそのページで入金額を確認して銀行口座の確認を完了することができます。 > 確認の失敗は、明細書表記ベースの少額入金の場合は 10 回、金額ベースの少額入金の場合は 3 回までです。この上限を超えると、Stripe は銀行口座を確認できなくなります。また、少額入金の確認は 10 日経過するとタイムアウトになります。この期間内に少額入金を確認できなかった場合、PaymentIntent は新しい支払い方法の詳細を要求する状態に戻ります。少額入金とは何か、どのように使用されるのかを顧客に明確に伝えることで、確認に関する問題を回避できます。 ### オプション: カスタムのメール通知を送信する また、顧客に[カスタムのメール通知](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を送信することもできます。カスタムメールを設定した後は、顧客が確認メールに応答する方法を指定する必要があります。以下の方法のうち、いずれか _1 つ_を指定してください。 - Stripe 上のオンライン確認ページを使用します。これを行うには、[next_action](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-verify_with_microdeposits-hosted_verification_url) オブジェクトの `verify_with_microdeposits[hosted_verification_url]` URL を使用し、顧客に確認プロセスを完了するよう指示します。 - Stripe がオンラインで提供する確認ページを使用しない場合には、ご自身のアプリにフォームを作成します。顧客はこのフォームを使用して少額入金の金額を伝え、Android SDK を使用して銀行口座を確認します。 - 少なくとも `descriptor code` パラメーター (確認のための 6 桁の文字列) を処理するフォームを設定します。 - また Stripe では、`amounts` パラメーターも処理するようにフォームを設定することをお勧めします。これはこのパラメーターが、顧客が利用する一部の銀行で必要とされることがあるためです。 組み込みは、`descriptor_code` *「または」* `amounts` のみを渡します。組み込みでどちらが使用されるかを判断するには、`next_action` オブジェクトの `verify_with_microdeposits[microdeposit_type]` の値を確認します。 #### Kotlin ```kotlin // Use if you are using a descriptor code, do not use if you are using amounts fun verifyPaymentIntentWithMicrodeposits( clientSecret: String, descriptorCode: String, callback: ApiResultCallback ) // Use if you are using amounts, do not use if you are using descriptor code fun verifyPaymentIntentWithMicrodeposits( clientSecret: String, firstAmount: Int, secondAmount: Int, callback: ApiResultCallback ) ``` 銀行口座の確認が成功すると、Stripe は、`processing` の `status` の PaymentIntent オブジェクトを返します。 確認が失敗する理由はいくつかあります。失敗は、直接的なエラー応答として同期的に発生します。 ```json { "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_method_microdeposit_failed` | 少額入金に失敗しました。指定した銀行口座、金融機関、支店の番号を確認してください。 | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | | `payment_method_microdeposit_verification_amounts_mismatch` | 指定された金額が銀行口座に送金された金額と一致しません。確認試行の残り回数はあと {attempts_remaining} 回です。 | 変化なし | | `payment_method_microdeposit_verification_attempts_exceeded` | 許容された確認の試行回数を超えました。 | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | ## PaymentIntent の成功を確認する [サーバー側] ACH ダイレクトデビットは、[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法です。このため、顧客の口座から引き落としを開始してから、決済の成功または失敗の通知を受けるまでに最大で 4 営業日かかります。 PaymentIntent を作成すると、その初期ステータスは `processing` となります。決済が成功すると、PaymentIntent のステータスは `processing` から `succeeded` に更新されます。 [Webhook](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks) を使用して決済が成功したことを*確認* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)し、顧客に決済完了を通知することをお勧めします。[Stripe ダッシュボード](https://dashboard.stripe.com/events)でイベントを表示することもできます。 #### PaymentIntent のイベント PaymentIntent のステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | | `payment_intent.processing` | 顧客の支払いは、Stripe に正常に送信されました。 | 開始された決済の成功または失敗の結果を待ちます。 | | `payment_intent.succeeded` | 顧客の支払いが成功しました。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `payment_intent.payment_failed` | 顧客の支払いは拒否されました。これは、少額入金確認の失敗に適用されることもあります。 | 顧客にメールまたはプッシュ通知で連絡し、別の決済手段をリクエストします。少額入金の確認に失敗して Webhook が送信された場合、ユーザーは銀行口座情報の再入力を求められ、その後、新しい少額入金が口座に入金されます。 | #### Charge のイベント 追加の Charge Webhook を使用して、支払いのステータスを追跡することもできます。`charge.updated` Webhook を受け取ると、支払いをキャンセルできなくなります。 支払いのステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------ | -------------------------------------------------------------------------- | -------------------------------------------------------- | | `charge.pending` | 顧客の支払いは正常に作成されました。 | 開始された決済が処理されるまで待ちます。 | | `charge.updated` | 顧客の支払いは更新されました。このイベントは、新しい取引残高が作成されたか、支払いの説明またはメタデータが更新されたときに出される可能性があります。 | 開始された決済の成功または失敗の結果を待ちます。 | | `charge.succeeded` | 顧客の支払いが成功して、残高で売上を利用できます。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `charge.failed` | 顧客の支払いは失敗しました。 | 支払いの failure_code と failure_message を確認して、次のアクションを判断します。 | ## 組み込みをテストする [Financial Connections](https://docs.stripe.com/financial-connections/testing.md#web-how-to-use-test-accounts) を使用して即時確認を行うシナリオをテストする方法をご紹介します。 ### サンドボックスで取引メールを送信する 銀行口座の詳細を収集し、同意書を受け付けたら、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で同意書の確認メールと少額入金の確認メールを送信します。 ドメインが **{domain}** で、ユーザー名が **{username}** の場合、メール形式 **{username}+test\_email@{domain}** を使用してテスト取引メールを送信します。 たとえば、ドメインが **example.com** でユーザー名が **info** の場合、ACH Direct Debit 決済のテストには **info+test\_email@example.com** という形式を使用します。この形式により、メールが正しくルーティングされます。**+test\_email** サフィックスを含めない場合、メールは送信されません。 > テスト中にこれらのメールをトリガーする前に、Stripe [アカウントを設定](https://docs.stripe.com/get-started/account/set-up.md)する必要があります。 ### テスト用口座番号 Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。 | 口座番号 | トークン | 金融番号 | 動作 | | -------------- | -------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------- | | `000123456789` | `pm_usBankAccount_success` | `110000000` | 支払いは成功します。 | | `000111111113` | `pm_usBankAccount_accountClosed` | `110000000` | 口座が解約済みであるため、支払いは失敗します。 | | `000000004954` | `pm_usBankAccount_riskLevelHighest` | `110000000` | この支払いは、[不正利用のリスクが高い](https://docs.stripe.com/radar/risk-evaluation.md#high-risk)ため、Radar によってブロックされています。 | | `000111111116` | `pm_usBankAccount_noAccount` | `110000000` | 口座が見つからないため、支払いは失敗します。 | | `000222222227` | `pm_usBankAccount_insufficientFunds` | `110000000` | 残高不足のため、支払いは失敗します。 | | `000333333335` | `pm_usBankAccount_debitNotAuthorized` | `110000000` | 引き落としがオーソリされていないため、支払いは失敗します。 | | `000444444440` | `pm_usBankAccount_invalidCurrency` | `110000000` | 通貨が無効であるため、支払いは失敗します。 | | `000666666661` | `pm_usBankAccount_failMicrodeposits` | `110000000` | 支払いで少額入金の送金が失敗します。 | | `000555555559` | `pm_usBankAccount_dispute` | `110000000` | 支払いによって不審請求の申請が開始されています。 | | `000000000009` | `pm_usBankAccount_processing` | `110000000` | 支払いは無期限に処理中のままになります。 [PaymentIntent キャンセル](https://docs.stripe.com/api/payment_intents/cancel.md) をテストするのに役立ちます。 | | `000777777771` | `pm_usBankAccount_weeklyLimitExceeded` | `110000000` | 支払い額がアカウントの週次支払い額の上限を超えているため、支払いが失敗しました。 | | `000888888885` | | `110000000` | [トークン化されたアカウント番号](https://docs.stripe.com/financial-connections/tokenized-account-numbers.md)が無効化されると決済が失敗します。 | テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。 ### 少額入金の金額と明細書表記コードをテストする さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。 | 少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ | | ------------- | --------------- | ------------------------- | | `32` および `45` | SM11AA | アカウントの確認をシミュレーションします。 | | `10` および `11` | SM33CC | 許容された確認回数の超過をシミュレーションします。 | | `40` および `41` | SM44DD | 少額入金のタイムアウトをシミュレーションします。 | ### 売上処理の動作をテストする テスト取引は即座に売上として処理され、利用可能なテスト残高に追加されます。この動作は、利用可能な残高で取引が売上として処理されるまでに[数日](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#timing)かかることがある、本番環境とは異なります。 ## Optional: 即時の確認のみ [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、銀行口座の即時確認のみを要求するように設定することもできます。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` これにより、少額入金の確認を処理する必要はなくなりますが、即時確認に失敗した場合は、PaymentIntent のステータスは、顧客の銀行口座の即時確認に失敗したことを示す `requires_payment_method` となります。 ## Optional: 少額入金のみによる確認 [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、少額入金による確認のみを要求するように設定することもできます。 > カスタムの決済フォームを使用している場合、自社の UI を構築して銀行口座の詳細を収集する必要があります。Stripe の少額入金に関するメールを無効にしている場合は、少額入金のコードまたは金額を確認するために顧客用の自社の UI を構築する必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` 自社のフォームで顧客の銀行口座を収集し、その詳細を使用して [stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) を呼び出し、PaymentIntent を完了する必要があります。 ```javascript var form = document.getElementById('payment-form'); var accountholderName = document.getElementById('accountholder-name'); var email = document.getElementById('email'); var accountNumber = document.getElementById('account-number'); var routingNumber = document.getElementById('routing-number'); var accountHolderType= document.getElementById('account-holder-type'); var submitButton = document.getElementById('submit-button'); var clientSecret = submitButton.dataset.secret; form.addEventListener('submit', function(event) { event.preventDefault(); stripe.confirmUsBankAccountPayment(clientSecret, { payment_method: { billing_details: { name: accountholderName.value, email: email.value, }, us_bank_account: { account_number: accountNumber.value, routing_number: routingNumber.value, account_holder_type: accountHolderType.value, // 'individual' or 'company' }, }, }) .then(({paymentIntent, error}) => { if (error) { // Inform the customer that there was an error. console.log(error.message); } else { // Handle next step based on the intent's status. console.log("PaymentIntent ID: " + paymentIntent.id); console.log("PaymentIntent status: " + paymentIntent.status); } }); }); ``` ## Optional: 支払いの参照情報 支払い参照番号は銀行で生成され、これを使用して銀行口座の所有者は銀行で資金を確認できます。支払いが成功すると、ダッシュボードと [Charge オブジェクト](https://docs.stripe.com/api/charges/object.md)内に支払い参照番号が表示されます。 | 支払いの状態 | 支払いの参照値 | | ------ | ------------------------- | | 保留中 | 利用不可 | | 失敗 | 利用不可 | | 成功 | 利用可能 (091000015001234 など) | また、`charge.succeeded` Webhook を受け取ったら、`payment_method_details` の内容を確認して、[payment_reference](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-us_bank_account-payment_reference) を見つけます。 次のイベントの例は、成功した ACH 支払いと支払い参照番号を示しています。 #### charge-succeeded ```json { "id": "{{EVENT_ID}}", "object": "event", // omitted some fields in the example "type": "charge.succeeded", "data": { "object": { "id": "{{PAYMENT_ID}}", "object": "charge", //... "paid": true, "payment_intent": "{{PAYMENT_INTENT_ID}}", "payment_method": "{{PAYMENT_METHOD_ID}}", "payment_method_details": { "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK", "fingerprint": "Ih3foEnRvLXShyfB", "last4": "1000","payment_reference": "091000015001234", "routing_number": "110000000" } } // ... } } } ``` `destination_details` の内容を表示して、返金された ACH 支払いに関連付けられた [refund reference](https://docs.stripe.com/api/refunds/object.md#refund_object-destination_details-us_bank_transfer-reference) を見つけます。 次のイベントの例は、返金参照番号が指定された、成功した ACH 返金のレンダリングを示しています。 [返金](https://docs.stripe.com/refunds.md) の詳細をご覧ください。 #### charge-refund-updated ```json { "id": "{{EVENT_ID}}", "object": "event", "type": "charge.refund.updated", "data": { "object": { "id": "{{REFUND_ID}}", "object": "refund", //... "payment_intent": "{{PAYMENT_INTENT_ID}}", "destination_details": { "type": "us_bank_transfer", "us_bank_transfer": {"reference": "091000015001111", "reference_status": "available" } } // ... } } } ``` ## See also - [今後の支払いに備えて ACH Direct Debit のプレオーソリデビットの詳細を保存する](https://docs.stripe.com/payments/ach-direct-debit/set-up-payment.md) # React Native > This is a React Native for when payment-ui is mobile and platform is react-native. View the full page at https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment?payment-ui=mobile&platform=react-native. > #### Accounts v2 API を使用した顧客の表現 > > Accounts v2 API では、Connect ユーザーには一般提供され、その他の Stripe ユーザーには公開プレビューで提供されます。Accounts v2 プレビューの一部である場合は、コードで[プレビューバージョン](https://docs.stripe.com/api-v2-overview.md#sdk-and-api-versioning)を指定する必要があります。 > > Accounts v2 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. アプリでの ACH ダイレクトデビットによる決済の受け付けは、以下のように構成されます。 - 決済を追跡するためのオブジェクトを作成する - 支払い方法の詳細を収集する - 決済を処理するために Stripe に送信する - 顧客の銀行口座を確認する Stripe では、[Payment Intent (支払いインテント)](https://docs.stripe.com/payments/payment-intents.md) を使用して、支払いが完了するまでの状態のすべてを追跡および処理します。 > ACH ダイレクトデビットは[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法であるため、決済後すぐには売上が利用可能になりません。通常、決済金額がお客様のアカウントに入金されるまでに 4 営業日かかります。 ## Stripe を設定する [サーバ側] [クライアント側] ### サーバ側 この組み込みには、Stripe API と通信するエンドポイントがサーバ上に必要です。Stripe の公式ライブラリを使用して、サーバから Stripe API にアクセスします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ### クライアント側 [React Native SDK](https://github.com/stripe/stripe-react-native) はオープンソースであり、詳細なドキュメントが提供されています。内部では、[ネイティブの iOS](https://github.com/stripe/stripe-ios) および [Android](https://github.com/stripe/stripe-android) の SDK を使用します。Stripe の React Native SDK をインストールするには、プロジェクトのディレクトリーで (使用するパッケージマネージャーによって異なる) 次のいずれかのコマンドを実行します。 #### yarn ```bash yarn add @stripe/stripe-react-native ``` #### npm ```bash npm install @stripe/stripe-react-native ``` 次に、その他の必要な依存関係をインストールします。 - iOS の場合は、**ios** ディレクトリに移動して `pod install` を実行し、必要なネイティブ依存関係もインストールします。 - Android の場合は、依存関係をインストールする必要はありません。 > [公式の TypeScript ガイド](https://reactnative.dev/docs/typescript#adding-typescript-to-an-existing-project)に従って TypeScript のサポートを追加することをお勧めします。 ### Stripe の初期化 React Native アプリで Stripe を初期化するには、決済画面を `StripeProvider` コンポーネントでラップするか、`initStripe` 初期化メソッドを使用します。`publishableKey` の API [公開可能キー](https://docs.stripe.com/keys.md#obtain-api-keys)のみが必要です。次の例は、`StripeProvider` コンポーネントを使用して Stripe を初期化する方法を示しています。 ```jsx import { useState, useEffect } from 'react'; import { StripeProvider } from '@stripe/stripe-react-native'; function App() { const [publishableKey, setPublishableKey] = useState(''); const fetchPublishableKey = async () => { const key = await fetchKey(); // fetch key from your server here setPublishableKey(key); }; useEffect(() => { fetchPublishableKey(); }, []); return ( {/* Your app code here */} ); } ``` > テストおよび開発時には API の[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 Stripe では、顧客の銀行口座を即座に確認できます。口座に関する追加データを取得する場合は、[Stripe Financial Connections](https://docs.stripe.com/financial-connections.md) を使用して[データアクセスを登録](https://dashboard.stripe.com/financial-connections/application)します。 Stripe Financial Connections を使用すると、金融口座をビジネスに関連付けることで、顧客が財務データを安全に共有できます。Financial Connections を使用して、トークン化された口座番号と金融番号、残高データ、所有者の詳細、取引データなどの顧客に許可された財務データにアクセスします。 このデータにアクセスすることで、決済を開始する前に残高を確認するなどのアクションを実行し、残高不足による決済の失敗の可能性を減らすことができます。 Financial Connections を利用すると、ユーザーがより少ないステップで自身のアカウントをLinkに関連付け、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 プレビューへのアクセスをリクエストするには、 > > For most use cases, we recommend [modeling your customers as customer-configured Account objects](https://docs.stripe.com/accounts-v2/use-accounts-as-customers.md) instead of using [Customer](https://docs.stripe.com/api/customers.md) objects. #### Accounts v2 ユーザーがあなたのビジネスでアカウントを作成したときに、顧客が設定する [Account](https://docs.stripe.com/api/v2/core/accounts/object.md#v2_account_object-configuration-customer) オブジェクトを作成するか、このユーザーに関連付けられた既存の `Account` を取得します。`Account` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Account` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl -X POST https://api.stripe.com/v2/core/accounts \ -H "Authorization: Bearer <>" \ -H "Stripe-Version: 2026-04-22.preview" \ --json '{ "contact_email": "{{CUSTOMER_EMAIL}}" }' ``` #### Customers v1 ユーザーがあなたのビジネスでアカウントを作成したときに、*Customer* (Customer objects represent customers of your business. They let you reuse payment methods and give you the ability to track multiple payments)オブジェクトを作成するか、このユーザーに関連付けられた既存の `Customer` を取得します。`Customer` オブジェクトの ID を自社の顧客に関する内部表現に関連付けると、後で保存済みの決済手段の詳細を取得して利用できます。`Customer` にメールアドレスを含めると、Financial Connections の [return user optimization](https://docs.stripe.com/financial-connections/fundamentals.md#return-user-optimization) を有効にできます。 ```curl curl https://api.stripe.com/v1/customers \ -u "<>:" \ -d email={{CUSTOMER_EMAIL}} ``` ## PaymentIntent を作成する [サーバー側] [PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents.md) は、顧客から支払いを回収する意図を表すオブジェクトで、決済プロセスのライフサイクルの各段階を追跡します。 ### サーバー側 まず、サーバーで PaymentIntent を作成し、回収する金額と通貨 `usd` を指定します。Payment Intents API を使用した実装がすでにある場合は、PaymentIntent の[支払い方法タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)のリストに `us_bank_account` を追加します。Customer の [ID](https://docs.stripe.com/api/customers/object.md#customer_object-id) を指定します。 将来その支払い方法を再利用する場合には、値を `off_session` に設定して [setup_future_usage](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-setup_future_usage) パラメーターを指定します。 Financial Connections 手数料の詳細については、[料金体系の詳細](https://stripe.com/financial-connections#pricing)をご覧ください。 デフォルトでは、銀行口座の支払い情報の収集では、手動の口座番号入力と少額入金の確認のフォールバックオプションを使用し、[Financial Connections](https://docs.stripe.com/financial-connections.md) で顧客のアカウントを即時確認します。Financial Connections を設定し、ACH の実装を最適化するために追加の口座データにアクセスする方法については、[Financial Connections に関するドキュメント](https://docs.stripe.com/financial-connections/ach-direct-debit-payments.md)をご覧ください。たとえば、Financial Connections を使用して、ACH 決済の開始前にアカウントの残高を確認できます。 > 顧客がアカウントを認証した後で、追加データにアクセスを拡張するには、権限を拡張してアカウントを再度関連付ける必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" ``` ### クライアント側 PaymentIntent には *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これを React Native アプリで使用することで、PaymentIntent オブジェクト全体を渡すことなく安全に支払いプロセスを完了できます。アプリで、サーバーの PaymentIntent をリクエストし、その client secret を保存します。 ```javascript function PaymentScreen() { // ... const fetchIntentClientSecret = async () => { const response = await fetch(`${API_URL}/create-intent`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ // This is an example request body, the parameters you pass are up to you customer: '', product: '', }), }); const {clientSecret} = await response.json(); return clientSecret; }; return ...; } ``` ## 支払い方法の詳細を収集する [クライアント側] PaymentIntent オブジェクト全体をクライアントに送信する代わりに、前のステップからの *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) を使用します。これは、Stripe API リクエストを認証する API キーとは異なります。 client secret は支払いを確定できるため、慎重に取り扱う必要があります。記録したり、URL に埋め込んだり、当該の顧客以外に漏洩することがないようにしてください。 [collectBankAccountForPayment](https://docs.stripe.com/js/payment_intents/collect_bank_account_for_payment) を使用して銀行口座の詳細を収集し、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) を作成して PaymentIntent に関連付けます。ACH Direct Debit PaymentMethod を作成するには、`billingDetails` パラメーターに口座名義人を含める必要があります。 ```javascript import {collectBankAccountForPayment} from '@stripe/stripe-react-native'; export default function MyPaymentScreen() { const [name, setName] = useState(''); const handleCollectBankAccountPress = async () => { // Fetch the intent client secret from the backend. // See `fetchIntentClientSecret()`'s implementation above. const {clientSecret} = await fetchIntentClientSecret(); const {paymentIntent, error} = await collectBankAccountForPayment( clientSecret, { paymentMethodType: 'USBankAccount', paymentMethodData: { billingDetails: { name: "John Doe", }, }, }, ); if (error) { Alert.alert(`Error code: ${error.code}`, error.message); } else if (paymentIntent) { Alert.alert('Payment status:', paymentIntent.status); if (paymentIntent.status === PaymentIntents.Status.RequiresConfirmation) { // The next step is to call `confirmPayment` } else if ( paymentIntent.status === PaymentIntents.Status.RequiresAction ) { // The next step is to call `verifyMicrodepositsForPayment` } } }; return ( setName(value.nativeEvent.text)} /> ``` ```ruby get '/checkout' do @intent = # ... Fetch or create the PaymentIntent erb :checkout end ``` ## 支払い方法の詳細を収集する [クライアント側] 顧客が ACH Direct Debitでの支払いをクリックしたときに、Stripe.js を使用してその支払いを Stripe に送信することをお勧めします。[Stripe.js](https://docs.stripe.com/payments/elements.md) は、決済フローを構築するための Stripe の基本的な JavaScript ライブラリです。これにより、実装に関する複雑な処理が自動的に行われ、将来、他の決済手段にも対応できるように実装を簡単に拡張できます。 Stripe.js スクリプトを決済ページに含めるには、このスクリプトを HTML ファイルの `head` に追加します。 ```html Checkout ``` 決済ページで以下の JavaScript を使用して、Stripe.js のインスタンスを作成します。 ```javascript // 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('<>'); ``` PaymentIntent オブジェクト全体をクライアントに送信する代わりに、前のステップからの *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) を使用します。これは、Stripe API リクエストを認証する API キーとは異なります。 client secret は支払いを完了できるため、慎重に取り扱う必要があります。記録したり、URL に埋め込んだり、当該の顧客以外に漏洩することがないようにしてください。 [stripe.collectBankAccountForPayment](https://docs.stripe.com/js/payment_intents/collect_bank_account_for_payment) を使用して、[Financial Connections](https://docs.stripe.com/financial-connections.md) で銀行口座の詳細を収集し、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) を作成して PaymentIntent に関連付けます。ACH ダイレクトデビットの PaymentMethod を作成するには、`billing_details` パラメーターに口座名義人を含める必要があります。 ```javascript // 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 認証フロー](https://docs.stripe.com/financial-connections/fundamentals.md#authentication-flow)では、銀行口座の詳細の収集と確認を自動的に処理します。顧客が認証フローを完了すると、*PaymentMethod* (PaymentMethods represent your customer's payment instruments, used with the Payment Intents or Setup Intents APIs) が自動的に PaymentIntent に関連付けられ、[Financial Connections アカウント](https://docs.stripe.com/api/financial_connections/accounts.md)が作成されます。 > 手動入力と少額入金によって顧客が関連付けた銀行口座では、残高、所有権、取引などの追加の銀行口座データにアクセスできません。 すべてのデバイスで最適なユーザー体験を提供できるように、ビューポートの `meta` タグを使用して、ページのビューポートの `minimum-scale` を 1 に設定します。 ```html ``` ### モバイルアプリで OAuth リダイレクトを処理する WebView が埋め込まれたページに Stripe.js を含めるほか、アプリで、顧客を OAuth ログインのためにネイティブモバイルブラウザーにリダイレクトする必要がある場合があります。 > 2024 年 1 月 1 日より、WebView ベースのすべての実装で、安全な機関認証とアプリのリダイレクトに適切に対処することが求められるようになり、対処できない場合は Financial Connections の認証フローに影響が及びます。上記の iOS または Android の手順をご覧ください。 #### Android Android では、以前にマニフェストで設定した `return_url` の[インテントフィルター](https://developer.android.com/guide/components/intents-filters)を登録する必要があります。 [Android のリンクの処理](https://developer.android.com/training/app-links)の詳細をご覧ください。 ```xml ``` WebView で [WebViewClient](https://developer.android.com/reference/android/webkit/WebViewClient) を登録します。`shouldOverrideUrlLoading` を上書きして、OAuth ログインページをカスタムタブ/安全なブラウザーインスタンスで開くことができます。 ```kotlin val webViewClient = object : WebViewClient() { override fun shouldOverrideUrlLoading( view: WebView, webResourceRequest: WebResourceRequest ): Boolean { val url = webResourceRequest.url.toString() CustomTabsIntent.Builder().build().launchUrl(view.context, Uri.parse(url)) return true } } // ... // register the web view client on your WebView myWebView.webViewClient = webViewClient ``` #### iOS iOS で、WebView が OAuth ウィンドウを開こうとしたときに、アプリが対応できるようにする必要があります。このプロセスでは、銀行アプリ、または対応していない場合は安全なブラウザーインスタンスで、URL を開きます。 `WKWebView` は、新しいウィンドウを開くリクエストを受信すると、まず URL をユニバーサルリンクとして開こうとします。ユニバーサルリンクを使用すると、ユーザーのデバイスにインストールされているバンキングアプリが、関連付けられた URL を直接処理し、認証プロセスを効率化できます。この方法では、デバイス上の既存の信頼できるアプリを活用することで、ユーザーのセキュリティと利便性が向上します。 対応する銀行アプリがインストールされていないか、リンクが認識されないなどの理由で、URL をユニバーサルリンクとして開くことができない場合、アプリは `ASWebAuthenticationSession` の使用にフォールバックする必要があります。このセッションにより、機密情報を安全に取り扱うための、セキュアなアプリ内ブラウザーでの認証フローをスムーズに実行できるようになります。`ASWebAuthenticationSession` がネイティブブラウザーを模倣することにより、ユーザーはアプリを離れずに認証できます。 ```swift class ViewController: UIViewController { private var webAuthenticationSession: ASWebAuthenticationSession? override func viewDidLoad() { super.viewDidLoad() // Initialize and configure your WKWebView let webView = WKWebView(frame: .zero, configuration: WKWebViewConfiguration()) // Load your website URL webView.load(URLRequest(url: URL(string: "https://yourwebsite.com")!)) // Add the web view to the view view.addSubview(webView) // Important: Assign a `uiDelegate` to handle redirects webView.uiDelegate = self } } extension ViewController: WKUIDelegate { func webView( _ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures ) -> WKWebView? { // Check if the link is attempting to open in a new window. // This is typically the case for a banking partner's authentication flow. let isAttemptingToOpenLinkInNewWindow = navigationAction.targetFrame?.isMainFrame != true if isAttemptingToOpenLinkInNewWindow, let url = navigationAction.request.url { // Attempt to open the URL as a universal link. // Universal links allow apps on the device to handle specific URLs directly. UIApplication.shared.open( url, options: [.universalLinksOnly: true], completionHandler: { [weak self] success in guard let self else { return } if success { // App-to-app flow: // The URL was successfully opened in a banking application that supports universal links. print("Successfully opened the authentication URL in a bank app: \(url)") } else { // Fallback for when no compatible bank app is found: // Create an `ASWebAuthenticationSession` to handle the authentication in a secure in-app browser self.launchInSecureBrowser(url: url) } }) } return nil } private func launchInSecureBrowser(url: URL) { let redirectURL = URL(string: "https://yourwebsite.com")! let webAuthenticationSession = ASWebAuthenticationSession( url: url, callbackURLScheme: redirectURL.scheme, completionHandler: { redirectURL, error in if let error { if (error as NSError).domain == ASWebAuthenticationSessionErrorDomain, (error as NSError).code == ASWebAuthenticationSessionError.canceledLogin.rawValue { print("User manually closed the browser by pressing 'Cancel' at the top-left corner.") } else { print("Received an error from ASWebAuthenticationSession: \(error)") } } else { // IMPORTANT NOTE: // The browser will automatically close when // the `callbackURLScheme` is called. print("Received a redirect URL: \(redirectURL?.absoluteString ?? "null")") } } ) // Store the session reference to prevent premature deallocation self.webAuthenticationSession = webAuthenticationSession // Set the presentation context provider to handle the browser's UI presentation webAuthenticationSession.presentationContextProvider = self // Use an ephemeral session to enhance privacy // This also disables the initial Apple alert about signing in to another app webAuthenticationSession.prefersEphemeralWebBrowserSession = true // Initiate the authentication session webAuthenticationSession.start() } } ``` 顧客が金融機関にログインして、口座へのアクセスが認証されると、Stripe によって `return_url` にリダイレクトされてアプリに戻ります。アプリに戻った後、顧客は銀行口座情報の収集プロセスを再開して完了することができます。 ## 同意書承認を収集し、支払いを送信する [クライアント側] 支払いを開始する前に、顧客に同意書の規約を表示して、顧客から承認を得る必要があります。 Nacha の運営規則に準拠するため、決済を開始する前に、同意書の規約を表示して顧客から承認を得る必要があります。[同意書](https://docs.stripe.com/payments/ach-direct-debit.md#mandates)の詳細については、こちらの記事をご覧ください。 顧客が同意書の規約を承認する場合、PaymentIntent を確定する必要があります。顧客がフォームを送信したら、[stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) を使用して支払いを完了します。 ```javascript 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](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) の完了には数秒かかる場合があります。この間、フォームが再送信されないように無効化し、待機中のインジケーター (スピナーなど) を表示します。エラーが発生した場合は、それを顧客に表示し、フォームを再度有効化し、待機中のインジケーターを非表示にします。 成功した場合、Stripe から以下のいずれかのステータスで PaymentIntent オブジェクトが返されます。 | ステータス | 説明 | 次のステップ | | ----------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `requires_action` | 銀行口座の確認を完了するには、追加のアクションが必要です。 | ステップ 6: [少額入金で銀行口座を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#web-verify-with-microdeposits) | | `processing` | 銀行口座が即座に確認されたか、確認が必要ありません。 | ステップ 7: [PaymentIntent の成功を確認する](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#web-confirm-paymentintent-succeeded) | PaymentIntent の確定に成功した後、同意書の確認メールと収集した銀行口座情報を顧客に送信する必要があります。Stripe はデフォルトでこれらの処理を行いますが、ご希望に応じて[カスタム通知の送信](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を選択することもできます。 ## 少額入金で銀行口座を確認する [クライアント側] すべての顧客が銀行口座を即時に確認できるわけではありません。このステップは、顧客が前のステップで即時確認フローからオプトアウトした場合にのみ適用されます。 このような場合、Stripe は `descriptor_code` による少額入金を送金し、銀行口座の確認でさらに問題が発生した場合には、`amount` による少額入金に戻る場合があります。これらの入金が顧客のオンライン明細書に表示されるには 1 ~ 2 営業日かかります。 - **明細書表記コード**。SM で始まる一意の 6 桁の `descriptor_code` を指定して、0.01 USD の 1 件の少額入金を顧客の銀行口座に送金します。顧客は、この文字列を使用して、銀行口座を確認します。 - **金額**。Stripe は、`ACCTVERIFY` という明細書表記を使用し、一意でない 2 件の少額入金を顧客の銀行口座に送金します。顧客は、この入金額を使用して銀行口座を確認します。 前のステップの [stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) メソッドの呼び出しの結果として、`requires_action` 状態の PaymentIntent が返されます。この PaymentIntent には、確認を完了するための有益な情報を含む `next_action` フィールドが含まれています。 ```javascript next_action: { type: "verify_with_microdeposits", verify_with_microdeposits: { arrival_date: 1647586800, hosted_verification_url: "https://payments.stripe.com/…", microdeposit_type: "descriptor_code" } } ``` [請求書メール](https://docs.stripe.com/api/payment_methods/object.md#payment_method_object-billing_details-email)を指定した場合、Stripe はこのメールで入金の到着予定日を顧客に通知します。このメールには、Stripe がオンラインで提供する確認ページへのリンクが含まれ、顧客はそのページで入金額を確認して銀行口座の確認を完了することができます。 > 確認の失敗は、明細書表記ベースの少額入金の場合は 10 回、金額ベースの少額入金の場合は 3 回までです。この上限を超えると、Stripe は銀行口座を確認できなくなります。また、少額入金の確認は 10 日経過するとタイムアウトになります。この期間内に少額入金を確認できなかった場合、PaymentIntent は新しい支払い方法の詳細を要求する状態に戻ります。少額入金とは何か、どのように使用されるのかを顧客に明確に伝えることで、確認に関する問題を回避できます。 ### オプション: カスタムのメール通知を送信する 必要に応じて、顧客に[カスタムのメール通知](https://docs.stripe.com/payments/ach-direct-debit.md#mandate-and-microdeposit-emails)を送信することができます。カスタムメールを設定した後は、顧客が確認メールに応答する方法を指定する必要があります。以下の方法のうち、いずれか _1 つ_を指定してください。 - Stripe 上のオンライン確認ページを使用します。これを行うには、[next_action](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-verify_with_microdeposits-hosted_verification_url) オブジェクトの `verify_with_microdeposits[hosted_verification_url]` URL を使用し、顧客に確認プロセスを完了するよう指示します。 - Stripe がオンラインで提供する確認ページを使用しない場合、ご自身のサイトにフォームを作成します。顧客はこのフォームを使用して少額入金の金額を伝え、[Stripe.js](https://docs.stripe.com/js/payment_intents/verify_microdeposits_for_payment) を使用して、銀行口座を確認します。 - 確認のために、少なくとも 6 桁のストリングの `descriptor code` パラメーターを処理するフォームを設定します。 - また Stripe では、`amounts` パラメーターも処理するようにフォームを設定することをお勧めします。これはこのパラメーターが、顧客が利用する一部の銀行で必要とされることがあるためです。 組み込みは、`descriptor_code` 「または」 `amounts` でのみ渡されます。組み込みでどちらが使用されているかを判断するには、`next_action` オブジェクトの `verify_with_microdeposits[microdeposit_type]` の値を確認します。 ```javascript 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](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.processing) *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) イベントを送信します。 確認が失敗する原因はいくつか存在します。失敗は直接的なエラー応答で同期的に発生することも、[payment_intent.payment_failed](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.failed) Webhook イベントを通じて非同期で発生することもあります (以下の例を参照してください)。 #### 同期エラー ```json { "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" } } ``` #### Webhook イベント ```javascript { "object": { "id": "pi_1234", "object": "payment_intent", "customer": "cus_0246", ... "last_payment_error": { "code": "payment_method_microdeposit_verification_attempts_exceeded", "message": "You have exceeded the number of allowed verification attempts.", }, ... "status": "requires_payment_method" } } ``` | エラーコード | 同期または非同期 | メッセージ | ステータスの変化 | | ------------------------------------------------------------ | ----------------------------- | ------------------------------------------------------------------ | -------------------------------------------------------------------- | | `payment_method_microdeposit_failed` | 同期、または Webhook イベントを通じて非同期で発生 | 少額入金に失敗しました。指定した銀行口座、金融機関、支店の番号を確認してください | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | | `payment_method_microdeposit_verification_amounts_mismatch` | 同期 | 指定された金額が銀行口座に送金された金額と一致しません。確認試行の残り回数はあと {attempts_remaining} 回です。 | 変化なし | | `payment_method_microdeposit_verification_attempts_exceeded` | 同期、または Webhook イベントを通じて非同期で発生 | 許容された確認の試行回数を超えました | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | | `payment_method_microdeposit_verification_timeout` | Webhook イベントを通じて非同期で発生 | 少額入金がタイムアウトになりました。顧客は要求された 10 日の期間内に銀行口座を確認しませんでした。 | `status` は `requires_payment_method` で、`last_payment_error` が設定されます。 | ## PaymentIntent の成功を確認する [サーバー側] ACH ダイレクトデビットは、[通知遅延型](https://docs.stripe.com/payments/payment-methods.md#payment-notification)の支払い方法です。このため、顧客の口座から引き落としを開始してから、決済の成功または失敗の通知を受けるまでに最大で 4 営業日かかります。 PaymentIntent を作成すると、その初期ステータスは `processing` となります。決済が成功すると、PaymentIntent のステータスは `processing` から `succeeded` に更新されます。 [Webhook](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks) を使用して決済が成功したことを*確認* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)し、顧客に決済完了を通知することをお勧めします。[Stripe ダッシュボード](https://dashboard.stripe.com/events)でイベントを表示することもできます。 #### PaymentIntent のイベント PaymentIntent のステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------------------- | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------- | | `payment_intent.processing` | 顧客の支払いは、Stripe に正常に送信されました。 | 開始された決済の成功または失敗の結果を待ちます。 | | `payment_intent.succeeded` | 顧客の支払いが成功しました。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `payment_intent.payment_failed` | 顧客の支払いは拒否されました。これは、少額入金確認の失敗に適用されることもあります。 | 顧客にメールまたはプッシュ通知で連絡し、別の決済手段をリクエストします。少額入金の確認に失敗して Webhook が送信された場合、ユーザーは銀行口座情報の再入力を求められ、その後、新しい少額入金が口座に入金されます。 | #### Charge のイベント 追加の Charge Webhook を使用して、支払いのステータスを追跡することもできます。`charge.updated` Webhook を受け取ると、支払いをキャンセルできなくなります。 支払いのステータスが更新されると、以下のイベントが送信されます。 | イベント | 説明 | 次のステップ | | ------------------ | -------------------------------------------------------------------------- | -------------------------------------------------------- | | `charge.pending` | 顧客の支払いは正常に作成されました。 | 開始された決済が処理されるまで待ちます。 | | `charge.updated` | 顧客の支払いは更新されました。このイベントは、新しい取引残高が作成されたか、支払いの説明またはメタデータが更新されたときに出される可能性があります。 | 開始された決済の成功または失敗の結果を待ちます。 | | `charge.succeeded` | 顧客の支払いが成功して、残高で売上を利用できます。 | 購入された商品またはサービスのフルフィルメントを行います。 | | `charge.failed` | 顧客の支払いは失敗しました。 | 支払いの failure_code と failure_message を確認して、次のアクションを判断します。 | ## 組み込みをテストする [Financial Connections](https://docs.stripe.com/financial-connections/testing.md#web-how-to-use-test-accounts) を使用して即時確認を行うシナリオをテストする方法をご紹介します。 ### サンドボックスで取引メールを送信する 銀行口座の詳細を収集し、同意書を受け付けたら、*サンドボックス* (A sandbox is an isolated test environment that allows you to test Stripe functionality in your account without affecting your live integration. Use sandboxes to safely experiment with new features and changes)で同意書の確認メールと少額入金の確認メールを送信します。 ドメインが **{domain}** で、ユーザー名が **{username}** の場合、メール形式 **{username}+test\_email@{domain}** を使用してテスト取引メールを送信します。 たとえば、ドメインが **example.com** でユーザー名が **info** の場合、ACH Direct Debit 決済のテストには **info+test\_email@example.com** という形式を使用します。この形式により、メールが正しくルーティングされます。**+test\_email** サフィックスを含めない場合、メールは送信されません。 > テスト中にこれらのメールをトリガーする前に、Stripe [アカウントを設定](https://docs.stripe.com/get-started/account/set-up.md)する必要があります。 ### テスト用口座番号 Stripe では、手動入力の銀行口座の組み込みが本番環境に移行する準備が整ったかどうかを確認するため、テスト用の口座番号と対応するトークンをいくつか用意しています。 | 口座番号 | トークン | 金融番号 | 動作 | | -------------- | -------------------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------- | | `000123456789` | `pm_usBankAccount_success` | `110000000` | 支払いは成功します。 | | `000111111113` | `pm_usBankAccount_accountClosed` | `110000000` | 口座が解約済みであるため、支払いは失敗します。 | | `000000004954` | `pm_usBankAccount_riskLevelHighest` | `110000000` | この支払いは、[不正利用のリスクが高い](https://docs.stripe.com/radar/risk-evaluation.md#high-risk)ため、Radar によってブロックされています。 | | `000111111116` | `pm_usBankAccount_noAccount` | `110000000` | 口座が見つからないため、支払いは失敗します。 | | `000222222227` | `pm_usBankAccount_insufficientFunds` | `110000000` | 残高不足のため、支払いは失敗します。 | | `000333333335` | `pm_usBankAccount_debitNotAuthorized` | `110000000` | 引き落としがオーソリされていないため、支払いは失敗します。 | | `000444444440` | `pm_usBankAccount_invalidCurrency` | `110000000` | 通貨が無効であるため、支払いは失敗します。 | | `000666666661` | `pm_usBankAccount_failMicrodeposits` | `110000000` | 支払いで少額入金の送金が失敗します。 | | `000555555559` | `pm_usBankAccount_dispute` | `110000000` | 支払いによって不審請求の申請が開始されています。 | | `000000000009` | `pm_usBankAccount_processing` | `110000000` | 支払いは無期限に処理中のままになります。 [PaymentIntent キャンセル](https://docs.stripe.com/api/payment_intents/cancel.md) をテストするのに役立ちます。 | | `000777777771` | `pm_usBankAccount_weeklyLimitExceeded` | `110000000` | 支払い額がアカウントの週次支払い額の上限を超えているため、支払いが失敗しました。 | | `000888888885` | | `110000000` | [トークン化されたアカウント番号](https://docs.stripe.com/financial-connections/tokenized-account-numbers.md)が無効化されると決済が失敗します。 | テスト取引を完了する前に、自動的に支払いに成功または失敗するテスト用のすべての口座を確認する必要があります。確認するには、下記の少額入金のテスト用の金額または明細書表記コードを使用します。 ### 少額入金の金額と明細書表記コードをテストする さまざまなシナリオを再現するために、これらの少額入金の金額「または」明細書表記コードの値 0.01 を使用します。 | 少額入金の金額 | 明細書表記コードの値 0.01 | シナリオ | | ------------- | --------------- | ------------------------- | | `32` および `45` | SM11AA | アカウントの確認をシミュレーションします。 | | `10` および `11` | SM33CC | 許容された確認回数の超過をシミュレーションします。 | | `40` および `41` | SM44DD | 少額入金のタイムアウトをシミュレーションします。 | ### 売上処理の動作をテストする テスト取引は即座に売上として処理され、利用可能なテスト残高に追加されます。この動作は、利用可能な残高で取引が売上として処理されるまでに[数日](https://docs.stripe.com/payments/ach-direct-debit/accept-a-payment.md#timing)かかることがある、本番環境とは異なります。 ## Optional: 即時の確認のみ [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、銀行口座の即時確認のみを要求するように設定することもできます。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=instant" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=payment_method" \ -d "payment_method_options[us_bank_account][financial_connections][permissions][]=balances" ``` これにより、少額入金の確認を処理する必要はなくなりますが、即時確認に失敗した場合は、PaymentIntent のステータスは、顧客の銀行口座の即時確認に失敗したことを示す `requires_payment_method` となります。 ## Optional: 少額入金のみによる確認 [サーバー側] デフォルトでは、アメリカの銀行口座による支払いを使用すると、顧客は銀行口座の即時確認、または少額入金を使用できます。必要に応じて、PaymentIntent を作成するときに、[verification_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_options-us_bank_account-verification_method) パラメーターを使用して、少額入金による確認のみを要求するように設定することもできます。 > カスタムの決済フォームを使用している場合、自社の UI を構築して銀行口座の詳細を収集する必要があります。Stripe の少額入金に関するメールを無効にしている場合は、少額入金のコードまたは金額を確認するために顧客用の自社の UI を構築する必要があります。 #### Accounts v2 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer_account={{CUSTOMERACCOUNT_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` #### Customers v1 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d amount=1099 \ -d currency=usd \ -d setup_future_usage=off_session \ -d "customer={{CUSTOMER_ID}}" \ -d "payment_method_types[]=us_bank_account" \ -d "payment_method_options[us_bank_account][verification_method]=microdeposits" ``` 自社のフォームで顧客の銀行口座を収集し、その詳細を使用して [stripe.confirmUsBankAccountPayment](https://docs.stripe.com/js/payment_intents/confirm_us_bank_account_payment) を呼び出し、PaymentIntent を完了する必要があります。 ```javascript var form = document.getElementById('payment-form'); var accountholderName = document.getElementById('accountholder-name'); var email = document.getElementById('email'); var accountNumber = document.getElementById('account-number'); var routingNumber = document.getElementById('routing-number'); var accountHolderType= document.getElementById('account-holder-type'); var submitButton = document.getElementById('submit-button'); var clientSecret = submitButton.dataset.secret; form.addEventListener('submit', function(event) { event.preventDefault(); stripe.confirmUsBankAccountPayment(clientSecret, { payment_method: { billing_details: { name: accountholderName.value, email: email.value, }, us_bank_account: { account_number: accountNumber.value, routing_number: routingNumber.value, account_holder_type: accountHolderType.value, // 'individual' or 'company' }, }, }) .then(({paymentIntent, error}) => { if (error) { // Inform the customer that there was an error. console.log(error.message); } else { // Handle next step based on the intent's status. console.log("PaymentIntent ID: " + paymentIntent.id); console.log("PaymentIntent status: " + paymentIntent.status); } }); }); ``` ## Optional: Financial Connections 銀行口座の残高に関する情報を取得する 資金不足のために決済が失敗することがないように、決済を開始する前に顧客の残高を確認することをお勧めします。ユーザーの許可を得た上で、Financial Connections を使用して[口座残高にアクセス](https://docs.stripe.com/financial-connections/balances.md)できます。 ## Optional: 支払いの参照情報 支払い参照番号は銀行で生成され、これを使用して銀行口座の所有者は銀行で資金を確認できます。支払いが成功すると、ダッシュボードと [Charge オブジェクト](https://docs.stripe.com/api/charges/object.md)内に支払い参照番号が表示されます。 | 支払いの状態 | 支払いの参照値 | | ------ | ------------------------- | | 保留中 | 利用不可 | | 失敗 | 利用不可 | | 成功 | 利用可能 (091000015001234 など) | また、`charge.succeeded` Webhook を受け取ったら、`payment_method_details` の内容を確認して、[payment_reference](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-us_bank_account-payment_reference) を見つけます。 次のイベントの例は、成功した ACH 支払いと支払い参照番号を示しています。 #### charge-succeeded ```json { "id": "{{EVENT_ID}}", "object": "event", // omitted some fields in the example "type": "charge.succeeded", "data": { "object": { "id": "{{PAYMENT_ID}}", "object": "charge", //... "paid": true, "payment_intent": "{{PAYMENT_INTENT_ID}}", "payment_method": "{{PAYMENT_METHOD_ID}}", "payment_method_details": { "type": "us_bank_account", "us_bank_account": { "account_holder_type": "individual", "account_type": "checking", "bank_name": "TEST BANK", "fingerprint": "Ih3foEnRvLXShyfB", "last4": "1000","payment_reference": "091000015001234", "routing_number": "110000000" } } // ... } } } ``` `destination_details` の内容を表示して、返金された ACH 支払いに関連付けられた [refund reference](https://docs.stripe.com/api/refunds/object.md#refund_object-destination_details-us_bank_transfer-reference) を見つけます。 次のイベントの例は、返金参照番号が指定された、成功した ACH 返金のレンダリングを示しています。 [返金](https://docs.stripe.com/refunds.md) の詳細をご覧ください。 #### charge-refund-updated ```json { "id": "{{EVENT_ID}}", "object": "event", "type": "charge.refund.updated", "data": { "object": { "id": "{{REFUND_ID}}", "object": "refund", //... "payment_intent": "{{PAYMENT_INTENT_ID}}", "destination_details": { "type": "us_bank_transfer", "us_bank_transfer": {"reference": "091000015001111", "reference_status": "available" } } // ... } } } ``` ## See also - [今後の支払いに備えて ACH Direct Debit のプレオーソリデビットの詳細を保存する](https://docs.stripe.com/payments/ach-direct-debit/set-up-payment.md)