既存の顧客の支払い
顧客がオンセッションの間に既存の決済手段に請求する方法をご紹介します。
Checkout セッションでは、買い手が各自の支払いの詳細を入力できます。買い手が既存の顧客の場合、Checkout セッションを設定して、顧客の保存済みのカードのいずれかを使って詳細に事前入力可能です。
Checkout セッションを作成クライアント側サーバー側
サーバー側のエンドポイントを呼び出して Checkout セッションを作成する購入ボタンをウェブサイトに追加します。
<html> <head> <title>Checkout</title> </head> <body> <form action="/create-checkout-session" method="POST"> <button type="submit">Checkout</button> </form> </body> </html>
Checkout は、customer
パラメーターを指定した既存の Customer オブジェクトの再利用をサポートします。既存の顧客を再利用すると、Payment Intents や Subscriptions など、Checkout によって作成されたすべてのオブジェクトがその Customer オブジェクトに関連付けられます。
success_
に {CHECKOUT_
テンプレート変数を追加することで、顧客が Checkout セッションを正常に完了した後でセッション ID にアクセスできます。Checkout セッションを作成したら、レスポンスで返された URL に顧客をリダイレクトします。
支払いページのフィールドを事前入力
If all the following conditions are true, Checkout prefills the email, name, card, and billing address fields on the payment page using details from the customer’s saved card:
- Checkout is in
payment
orsubscription
mode;setup
mode doesn’t support prefilling fields. - The customer has a saved card. Checkout only supports prefilling card payment methods.
- The saved card has
allow_
set toredisplay always
or you adjusted the default display setting. - The payment method includes
billing_
required by itsdetails billing_
type:address_ collection auto
requires values foremail
,name
, andaddress[country]
. US, CA, and GB billing addresses also requireaddress[postal_
.code] required
requires values foremail
,name
, and alladdress
fields.
If your customer has multiple saved cards, Checkout prefills details from the card matching the following prioritization:
- In
payment
mode, Stripe prefills the fields using the customer’s the newest saved card. - In
subscription
mode, Stripe prefills the customer’s default payment method if it’s a card. Otherwise Stripe prefills the newest saved card.
Prefill timeout
The prefilled payment method displays for 30 minutes following Checkout Session creation. After it expires, loading the same Checkout Session doesn’t prefill the payment method anymore for security reasons.
支払い後のイベントを処理サーバー側
Stripe sends a checkout.session.completed event when a customer completes a Checkout Session payment. Use the Dashboard webhook tool or follow the webhook guide to receive and handle these events, which might trigger you to:
- Send an order confirmation email to your customer.
- Log the sale in a database.
- Start a shipping workflow.
Listen for these events rather than waiting for your customer to be redirected back to your website. Triggering fulfillment only from your Checkout landing page is unreliable. Setting up your integration to listen for asynchronous events allows you to accept different types of payment methods with a single integration.
Learn more in our fulfillment guide for Checkout.
Handle the following events when collecting payments with the Checkout:
Event | Description | Action |
---|---|---|
checkout.session.completed | Sent when a customer successfully completes a Checkout Session. | Send the customer an order confirmation and fulfill their order. |
checkout.session.async_payment_succeeded | Sent when a payment made with a delayed payment method, such as ACH direct debt, succeeds. | Send the customer an order confirmation and fulfill their order. |
checkout.session.async_payment_failed | Sent when a payment made with a delayed payment method, such as ACH direct debt, fails. | Notify the customer of the failure and bring them back on-session to attempt payment again. |