Bancontact での支払いの受け付けは、支払いを追跡するための PaymentIntent (支払いインテント) オブジェクトの作成、支払い方法に関する情報と同意書承認の収集、および支払いを処理するための Stripe への送信で構成されます。Stripe は、PaymentIntent を使用して、支払いが完了するまでの支払いの状態のすべてを追跡して処理します。以降の支払いの作成には、最初の Bancontact PaymentIntent から収集された SEPA ダイレクトデビット PaymentMethod の ID が使用されます。
まず、Stripe アカウントが必要です。今すぐご登録ください。
アプリケーションから Stripe API にアクセスするには、Stripe の公式ライブラリを使用します。
お客様のビジネスで顧客がアカウントを作成する際に、Customer を作成し、それを、そのアカウントを表す独自の内部表記と関連付けます。このようにすると、保存されている支払い方法の詳細を後で取得して使用することができます。
curl -X POST https://api.stripe.com/v1/customers \
-u "sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
サーバーで PaymentIntent
を作成し、回収する amount
、eur
通貨、顧客 ID を指定し、Setup future usage (今後の使用の設定) の引数として off_session を指定します。既存の Payment Intents のシステムがある場合は、bancontact
を決済手段タイプ のリストに追加します。
curl https://api.stripe.com/v1/payment_intents \
-u "sk_test_BQokikJOvBiI2HlWgH4olfQ2
:" \
-d amount=1099 \
-d currency=eur \
-d "payment_method_types[]"=bancontact \
-d customer={{CUSTOMER_ID}} \
-d setup_future_usage=off_session
client secret を取得する
PaymentIntent には、client secret が含まれています。これは、支払いプロセスを安全に完了するためにクライアント側で使用されます。client secret をクライアント側に渡す際は、いくつかの方法を使用できます。
ブラウザーの fetch
関数を使用して、サーバーのエンドポイントから client secret を取得します。この方法は、クライアント側が 1 ページのアプリケーションで、特に React などの最新のフロントエンドフレームワークで構築されている場合に最適です。client secret を処理するサーバーのエンドポイントを作成します。
get '/secret' do
intent =
{client_secret: intent.client_secret}.to_json
end
その後、クライアント側で JavaScript を使用して client secret を取得します。
(async () => {
const response = await fetch('/secret');
const {client_secret: clientSecret} = await response.json();
})();
クライアントで支払いフォームを作成し、必要な請求先情報を顧客から収集します。
SEPA ダイレクトデビットの支払いを処理するには、顧客から同意書を収集する必要があります。以下に示す定型の承認用文書を表示し、顧客が黙示的にこの同意書に署名するようにしてください。
「Rocket Rides」はお客様の社名に置き換えます。
Authorization text template
支払い方法を設定するか、PaymentIntent を確定すると、承認済みの同意書が作成されます。顧客は黙示的に同意書に署名したため、フォームまたはメールを通じて、顧客にこれらの規約を伝える必要があります。
フィールド | 値 |
---|
name | 顧客の氏名。 |
email | 顧客のメール。 |
<form id="payment-form">
<div class="form-row">
<label for="name">
Name
</label>
<input id="name" name="name" required>
</div>
<div class="form-row">
<label for="email">
Email
</label>
<input id="email" name="email" required>
</div>
<button id="submit-button">Pay with Bancontact</button>
<div id="mandate-acceptance">
By providing your payment information and confirming this payment, you
authorise (A) Rocket Rides and Stripe, our payment service provider, to
send instructions to your bank to debit your account and (B) your bank to
debit your account in accordance with those instructions. As part of your
rights, you are entitled to a refund from your bank under the terms and
conditions of your agreement with your bank. A refund must be claimed
within 8 weeks starting from the date on which your account was debited.
Your rights are explained in a statement that you can obtain from your
bank. You agree to receive notifications for future debits up to 2 days
before they occur.
</div>
<div id="error-message" role="alert"></div>
</form>
PaymentIntent の client secret を使用し、クライアント側で支払いを作成します。client secret は、 Stripe API リクエストを認証する API キーとは異なります。client secret は支払いを完了できるため、慎重に取り扱う必要があります。ログに記録したり、URL に埋め込んだり、当該の顧客以外に公開したりしないでください。
stripe.confirmBancontactPayment を呼び出し、顧客を Bancontact のウェブサイトまたはアプリにリダイレクトして支払いを完了します。支払い完了後に顧客をリダイレクトする return_url を含めてください。また、顧客の氏名とメールアドレスを billing_details
で指定する必要もあります。
var stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx'
);
var accountholderName = document.getElementById('name');
var accountholderEmail = document.getElementById('email');
const {error} = await stripe.confirmBancontactPayment(
'{{PAYMENT_INTENT_CLIENT_SECRET}}',
{
payment_method: {
billing_details: {
name: accountholderName.value,
email: accountholderEmail.value,
},
},
return_url: 'https://example.com/checkout/complete',
}
);
if (error) {
}
顧客が支払いを送信すると、Stripe は顧客を return_url
にリダイレクトし、以下の URL クエリーパラメーターを含めます。返品ページでは、これらを使用して PaymentIntent のステータスを取得し、顧客に支払いステータスを表示できます。
return_url
を指定する際に、返品ページで使用する独自のクエリパラメーターを追加することもできます。
パラメーター | 説明 |
---|
payment_intent | PaymentIntent の一意の識別子。 |
payment_intent_client_secret | PaymentIntent オブジェクトの client secret。 |
顧客が自社のサイトにリダイレクトされたら、payment_intent_client_secret
を使用して PaymentIntent をクエリし、顧客に取引ステータスを表示できます。
顧客に再び請求する必要が生じたときは、新しい PaymentIntent を作成します。以前の PaymentIntent を 取得し、latest_charge
フィールドを展開して payment_method_details
内の generated_sepa_debit
ID を探すことで、SEPA ダイレクトデビットの支払い方法の ID を見つけます。
curl -G https://api.stripe.com/v1/payment_intents/{{PAYMENT_INTENT_ID}} \
-u "sk_test_BQokikJOvBiI2HlWgH4olfQ2
:" \
-d "expand[]"=latest_charge
SEPA ダイレクトデビットの決済手段 ID は、レスポンス内の payment_method_details にある generated_sepa_debit
ID になります。
SEPA ダイレクトデビットと顧客 ID を使用して PaymentIntent を作成します。
curl https://api.stripe.com/v1/payment_intents \
-u "sk_test_BQokikJOvBiI2HlWgH4olfQ2
:" \
-d "payment_method_types[]"=sepa_debit \
-d amount=1099 \
-d currency=eur \
-d customer= \
-d payment_method={{SEPA_DEBIT_PAYMENT_METHOD_ID}} \
-d confirm=true
payment_method.billing_details.email
を以下の値のいずれかに設定して PaymentMethod のステータスの移行をテストします。メールアドレスの先頭に独自のカスタムのテキストを含め、その後ろにアンダースコアを付けることができます。 たとえば、test_1_generatedSepaDebitIntentsFail@example.com
は、PaymentIntent とともに使用された場合に常に失敗する、SEPA ダイレクトデビットの PaymentMethod です。
メールアドレス | 説明 |
---|
generatedSepaDebitIntentsSucceed@example.com | PaymentIntent のステータスは、processing から succeeded に移行します。 |
generatedSepaDebitIntentsSucceedDelayed@example.com | The PaymentIntent status transitions from processing to succeeded after at least three minutes. |
generatedSepaDebitIntentsFail@example.com | PaymentIntent のステータスは、processing から requires_payment_method に移行します。 |
generatedSepaDebitIntentsFailDelayed@example.com | The PaymentIntent status transitions from processing to requires_payment_method after at least three minutes. |
generatedSepaDebitIntentsSucceedDisputed@example.com | PaymentIntent のステータスは、processing から succeeded に移行しますが、すぐに不審請求の申請が作成されます。 |