コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
売上
プラットフォームおよびマーケットプレイス
資金管理
開発者向けのツール
概要
Stripe Payments について
構築済みのシステムをアップグレード
支払いの分析
オンライン決済
概要ユースケースを見つけるManaged Payments
Payment Links を使用する
決済ページを構築
高度なシステムを構築
アプリ内実装を構築
決済手段
決済手段を追加
決済手段を管理
Link による購入の迅速化
支払いインターフェイス
Payment Links
Checkout
Web Elements
    概要
    Payment Element
      Payment Element のベストプラクティス
      カード Element の比較
      Payment Intents を使用して Payment Element に移行
      Checkout セッションを使用して Payment Element に移行
      Confirmation Tokens に移行
    Express Checkout Element
    Address Element
    Currency Selector Element
    Link Authentication Element
    Payment Method Messaging Element
アプリ内 Elements
決済シナリオ
カスタムの決済フロー
柔軟なアクワイアリング
オーケストレーション
店頭支払い
端末
他の Stripe プロダクト
Financial Connections
仮想通貨
Climate
ホーム支払いWeb ElementsPayment Element

Confirmation Tokensに移行する

PaymentMethod の代わりに ConfirmationToken を使用して、サーバーで支払いを確定します。

ページをコピー

このガイドを使用して、PaymentMethod ではなく、ConfirmationToken を使用してサーバーで支払いを確定し、クライアントから収集したデータを自社のサーバーに送信する方法をご覧ください。

ConfirmationToken は、配送先情報など、PaymentMethod で見つかったデータのスーパーセットを保持し、Stripe が構築した新しい機能を有効化します。

確認トークンを作成する
クライアント側

stripe.createPaymentMethod を呼び出すのではなく、stripe.createConfirmationToken を呼び出して、ConfirmationToken オブジェクトを作成します。この ConfirmationToken をサーバーに渡して PaymentIntent を確定します。

stripe.createConfirmationToken メソッドは、(params.payment_method_data を介して) stripe.createPaymentMethod と同じパラメーターを受け付けます。このほか、shipping と return_url パラメーターも受け付けます。

前
後
checkout.js
// Create the PaymentMethod using the details collected by the Payment Element. const {error, paymentMethod} = await stripe.createPaymentMethod({ elements, params: { billing_details: { name: 'Jenny Rosen', } } }); if (error) { // This point is only reached if there's an immediate error when creating the PaymentMethod. // Show the error to your customer (for example, payment details incomplete) handleError(error); return; } // Create and confirm the PaymentIntent const res = await fetch("/create-confirm-intent", { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({ paymentMethodId: paymentMethod.id, }), });
checkout.js
// Create the ConfirmationToken using the details collected by the Payment Element and additional shipping information. Provide shipping and return_url if you don't want to provide it when confirming the intent on the server const {error, confirmationToken} = await stripe.createConfirmationToken({ elements, params: { payment_method_data: { billing_details: { name: 'Jenny Rosen', } }, // Remove shipping if you're collecting it using Address Element or don't require it shipping: { name: 'Jenny Rosen', address: { line1: '1234 Main Street', city: 'San Francisco', state: 'CA', country: 'US', postal_code: '94111', }, }, return_url: 'https://example.com/order/123/complete', } }); if (error) { // This point is only reached if there's an immediate error when creating the ConfirmationToken. // Show the error to your customer (for example, payment details incomplete) handleError(error); return; } // Create and confirm the PaymentIntent const res = await fetch("/create-confirm-intent", { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify({ confirmationTokenId: confirmationToken.id, }), });

決済を作成して Stripe に送信する
サーバー側

以前のように PaymentMethod ではなく、ConfirmationToken をサーバーに渡してPaymentIntent を確定します。ConfirmationToken に保存されたプロパティは、確定時に ID が confirmation_token パラメーターに指定されたときに、Intent に適用されます。

注

ConfirmationToken にすでに shipping と return_url を指定している場合、 PaymentIntent を確定する際に、これらのフィールドを再度指定する必要はありません。

前
後
server.js
app.post('/create-confirm-intent', async (req, res) => { try { const intent = await stripe.paymentIntents.create({ confirm: true, amount: 1099, currency: 'usd', // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default. automatic_payment_methods: {enabled: true}, use_stripe_sdk: true, // the PaymentMethod ID sent by your client payment_method: req.body.paymentMethodId, return_url: 'https://example.com/order/123/complete', mandate_data: { customer_acceptance: { type: "online", online: { ip_address: req.ip, user_agent: req.get("user-agent"), }, }, }, shipping: { name: 'Jenny Rosen', address: { line1: '1234 Main Street', city: 'San Francisco', state: 'CA', country: 'US', postal_code: '94111', }, } }); res.json({ client_secret: intent.client_secret, status: intent.status }); } catch (err) { res.json({ error: err }) } });
server.js
app.post('/create-confirm-intent', async (req, res) => { try { const intent = await stripe.paymentIntents.create({ confirm: true, amount: 1099, currency: 'usd', // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default. automatic_payment_methods: {enabled: true}, use_stripe_sdk: true, // the ConfirmationToken ID sent by your client that already has the shipping, mandate_data, and return_url data confirmation_token: req.body.confirmationTokenId, }); res.json({ client_secret: intent.client_secret, status: intent.status }); } catch (err) { res.json({ error: err }) } });

確定時に PaymentIntent または SetupIntent に直接指定されるパラメーター (shipping など) は、ConfirmationToken の対応するプロパティーを上書きします。

オプション支払い方法に基づいた条件パラメーター setup_future_usage または capture_method を設定する

参照情報

  • 導入方法の設計
このページはお役に立ちましたか。
はいいいえ
お困りのことがございましたら 、サポートにお問い合わせください。
早期アクセスプログラムにご参加ください。
変更ログをご覧ください。
ご不明な点がございましたら、お問い合わせください。
LLM ですか?llms.txt を読んでください。
Powered by Markdoc