コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
AI に質問する
アカウントを作成
サインイン
始める
支払い
売上
プラットフォームおよびマーケットプレイス
資金管理
開発者向けリソース
概要
Stripe Payments について
構築済みのシステムをアップグレード
支払いの分析
オンライン決済
概要ユースケースを見つけるUse Managed Payments
Payment Links を使用する
構築済みの決済ページを使用する
Build a custom integration with Elements
    概要
    Compare Checkout Sessions and PaymentIntents
    Quickstart guides
    高度なシステムを設計
    デザインをカスタマイズする
    決済手段を管理
    追加情報を収集する
    サブスクリプションの実装
    Dynamic updates
      Shipping options
      項目
      Trial durations
      割引
      Payment amounts
      Line item quantities
    割引を追加する
    支払いで税金を徴収
    顧客が現地通貨で支払いできるようにする
    顧客の支払い方法を保存および取得する
    領収書と支払い済みの請求書を送信する
    サーバーで支払いを手動で承認する
    支払いのオーソリとキャプチャーを分離する
    Elements with Checkout Sessions API ベータ版の変更ログ
アプリ内実装を構築
決済手段
決済手段を追加
決済手段を管理
Link による購入の迅速化
支払いインターフェイス
Payment Links
Checkout
Web Elements
アプリ内決済
決済シナリオ
複数の通貨を扱う
カスタムの決済フロー
柔軟なアクワイアリング
オーケストレーション
店頭支払い
端末
決済にとどまらない機能
会社を設立する
仮想通貨
Financial Connections
Climate
不正利用について
Radar の不正防止
不審請求の申請の管理
本人確認
ホーム支払いBuild a custom integration with ElementsDynamic updates

注

このページはまだ日本語ではご利用いただけません。より多くの言語で文書が閲覧できるように現在取り組んでいます。準備が整い次第、翻訳版を提供いたしますので、もう少しお待ちください。

Dynamically update payment amounts

Learn how to modify total amounts when customers change their selections during checkout.

Update the amount of a Checkout Session or Payment Intent when customers change what they’re buying or how much they pay. Recalculate the totals on your server, and then update the amount of the PaymentIntent.

Common use cases

  • Add or remove add-ons (such as gift wrap or a warranty).
  • Select a different shipping method or delivery speed.
  • Add additional services or charges.
  • Apply or remove a discount code or store credit.

Security best practices

  • Recalculate amounts on your server. Don’t trust client-provided prices or totals.
  • Authorize the update based on your business rules (for example, enforce max quantities).
  • Only update Sessions that are active and not completed or expired.

Constraints and behavior

  • You can update the amount while the Payment Intent or Checkout Session is awaiting payment (for example, requires_payment_method or requires_confirmation).
  • After confirmation, you generally can’t increase the amount.

Update the client SDK
Client-side

When using Elements with the Checkout Sessions API, wrap client calls to your server in runServerUpdate so the checkout state and totals refresh.

checkout.js
import {loadStripe} from '@stripe/stripe-js'; // Optional: include beta flags if your integration requires them const stripe = await loadStripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
, { betas: ['custom_checkout_server_updates_1'], }); const checkout = await stripe.initCheckout({ elementsOptions: {/* ... */}, }); // Example: Add additional service using price_data document .getElementById('add-service') .addEventListener('click', async () => { const updateOnServer = () => fetch('/update-custom-amount', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ checkout_session_id: checkout.session().id, product_id: 'gift_wrap', // Server looks up actual price }), }); const response = await checkout.runServerUpdate(updateOnServer); if (!response.ok) { // show error state } });

Create server endpoints
Server-side

Calculate amounts and validate inputs on your server. Then, you can update line_items with price_data to add ad-hoc charges.

注

Updating the line_items or price_data recalculates the Session total and taxes.

Node
Python
No results
import express from 'express'; import Stripe from 'stripe'; const app = express(); app.use(express.json()); const stripe = new Stripe(
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
); // Product catalog with prices - store this securely server-side const PRODUCTS = { gift_wrap: { name: 'Gift Wrap', price: 500 }, // $5.00 express_shipping: { name: 'Express Shipping', price: 1500 }, // $15.00 warranty: { name: 'Extended Warranty', price: 2000 }, // $20.00 }; app.post('/update-custom-amount', async (req, res) => { try { const {checkout_session_id, product_id} = req.body; const session = await stripe.checkout.sessions.retrieve(checkout_session_id); if (session.status === 'complete' || session.expires_at * 1000 < Date.now()) { return res.status(400).json({error: 'Session is no longer updatable.'}); } // Look up product price server-side const product = PRODUCTS[product_id]; if (!product) { return res.status(400).json({error: 'Invalid product ID'}); } // Add the additional product via price_data const updated = await stripe.checkout.sessions.update(checkout_session_id, { line_items: [ { price_data: { currency: 'usd', product_data: {name: product.name}, unit_amount: product.price, }, quantity: 1, }, ], }); return res.json({id: updated.id, amount_total: updated.amount_total}); } catch (err) { return res.status(400).json({error: err.message}); } }); app.listen(4242, () => console.log('Server running on port 4242'));
このページはお役に立ちましたか。
はいいいえ
  • お困りのことがございましたら 、サポートにお問い合わせください。
  • 早期アクセスプログラムにご参加ください。
  • 変更ログをご覧ください。
  • ご不明な点がございましたら、お問い合わせください。
  • LLM ですか?llms.txt を読んでください。
  • Powered by Markdoc