コンテンツにスキップ
アカウントを作成
または
サインイン
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 line items

Learn how to modify pricing and the contents of a cart during checkout.

Private preview

Dynamic updates is in private preview. Request access to dynamic updates to checkout.

Checkout Session (セッション) に含まれる項目を動的に追加、削除、更新する方法をご紹介します。

ご利用事例

このガイドでは、項目を更新してサブスクリプションをアップセルする方法を示しますが、以下を行うこともできます。

  • 在庫の確認:在庫チェックを実行し、顧客がアイテムの数量を変更しようとしたときに保留します。
  • 新しい商品を追加する:注文合計額が一定の金額を超えている場合に、補完商品を追加します。
  • 配送料金を更新する:注文合計額が変更された場合は、このガイドの購入時に配送オプションをカスタマイズするで説明されている方法を組み合わせて、配送料金を更新します。
  • 税率を更新する:Stripe Tax を使用していない場合は、入力された配送先住所に基づいて項目の税率を動的に更新できます。

Payment Intents API

If you use the Payment Intents API, you must manually track line item updates and modify the payment amount, or by creating a new PaymentIntent with adjusted amounts.

Set up the SDK
Server-side

Stripe の公式ライブラリを使用して、アプリケーションから Stripe API にアクセスします。

Command Line
Ruby
Python
PHP
Node.js
.NET
Go
Java
No results
gem install stripe -v 15.1.0-beta.2

Update the server SDK
Server-side

To use this beta, first update your SDK to use the checkout_server_update_beta=v1 beta version header.

Ruby
Python
PHP
Node
.NET
Go
Java
No results
# Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key =
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
Stripe.api_version = '2025-03-31.basil; checkout_server_update_beta=v1;'

Configure update permissions for the Checkout Session
Server-side

When you create the Checkout Session, pass the permissions.update_line_items=server_only option to disable client-side updates and to enable updating line items, such as updateLineItemQuantity, from your server.

Command Line
cURL
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -H "Stripe-Version: 2025-03-31.basil; checkout_server_update_beta=v1;" \ -d ui_mode=custom \ -d "permissions[update_line_items]"=server_only \ -d "line_items[0][price]"=
{{PRICE_ID}}
\ -d "line_items[0][quantity]"=1 \ -d mode=subscription \ --data-urlencode return_url="https://example.com/return"

Dynamically update line items
Server-side

Create an endpoint on your server to update the line items on the Checkout Session. You’ll call this from the front end in a later step.

セキュリティのヒント

Client-side code runs in an environment that’s controlled by the user. A malicious user can bypass your client-side validation, intercept and modify requests, or create new requests to your server.

When creating an endpoint, we recommend the following:

  • Create endpoints for specific customer interactions instead of making them generic. For example, “add cross-sell items” instead of a general “update” action. Specific endpoints can help with writing and maintaining validation logic.
  • Don’t pass session data directly from the client to your endpoint. Malicious clients can modify request data, making it an unreliable source for determining the Checkout Session state. Instead, pass the session ID to your server and use it to securely retrieve the data from the Stripe API.
Ruby
Python
PHP
Node
.NET
Go
Java
No results
require 'sinatra' require 'json' require 'stripe' set :port, 4242 # Set your secret key. Remember to switch to your live secret key in production. # See your keys here: https://dashboard.stripe.com/apikeys Stripe.api_key =
'sk_test_BQokikJOvBiI2HlWgH4olfQ2'
Stripe.api_version = '2025-03-31.basil; checkout_server_update_beta=v1;' MONTHLY_PRICE_ID = '{{MONTHLY_PRICE}}' YEARLY_PRICE_ID = '{{YEARLY_PRICE}}' post '/change-subscription-interval' do content_type :json request.body.rewind request_data = JSON.parse(request.body.read) checkout_session_id = request_data['checkout_session_id'] interval = request_data['interval'] if checkout_session_id.nil? || !['yearly', 'monthly'].include?(interval) status 400 return { type: 'error', message: 'We couldn't process your request. Please try again later.' }.to_json end begin # 1. Create the new line items for the Checkout Session. new_price = interval == 'yearly' ? YEARLY_PRICE_ID : MONTHLY_PRICE_ID line_items = [{ price: new_price, quantity: 1, }] # 2. Update the Checkout Session with the new line items. Stripe::Checkout::Session.update(checkout_session_id, { line_items: line_items, }) # 3. Return a success response. { type: 'success' }.to_json rescue Stripe::StripeError # Handle Stripe errors with a generic error message status 400 { type: 'error', message: 'We couldn't process your request. Please try again later.' }.to_json rescue StandardError # Handle unexpected errors status 500 { type: 'error', message: 'Something went wrong on our end. Please try again later.' }.to_json end end

When updating line items, you must retransmit the entire array of line items.

  • To keep an existing line item, specify its id.
  • To update an existing line item, specify its id along with the new values of the fields to update.
  • To add a new line item, specify a price and quantity without an id.
  • To remove an existing line item, omit the line item’s ID from the retransmitted array.
  • To reorder a line item, specify its id at the desired position in the retransmitted array.

Update the client SDK
Client-side

Initialize Stripe.js with the custom_checkout_server_updates_1 beta header.

checkout.js
const stripe = Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
, { betas: ['custom_checkout_server_updates_1'], });

Request server updates
Client-side

From your front end, send an update request to your server and wrap it in runServerUpdate. A successful request updates the Session object with the new line items.

index.html
<button id="change-subscription-interval" role="switch" aria-checked="false"> Save with a yearly subscription </button>
checkout.js
document.getElementById('change-subscription-interval') .addEventListener("click", async (event) => { const button = event.target; const isCurrentSubscriptionMonthly = button.getAttribute("aria-checked") === "false"; const updateCheckout = () => { return fetch("/change-subscription-interval", { method: "POST", headers: { "Content-type": "application/json", }, body: JSON.stringify({ checkout_session_id: checkout.session().id, interval: isCurrentSubscriptionMonthly ? "yearly" : "monthly", }) }); }; const response = await checkout.runServerUpdate(updateCheckout); if (!response.ok) { // Handle error state return; } // Update toggle state on success const isNewSubscriptionMonthly = !isCurrentSubscriptionMonthly; button.setAttribute("aria-checked", !isNewSubscriptionMonthly); button.textContent = isNewSubscriptionMonthly ? "Save with a yearly subscription" : "Use monthly subscription"; });
このページはお役に立ちましたか。
はいいいえ
  • お困りのことがございましたら 、サポートにお問い合わせください。
  • 早期アクセスプログラムにご参加ください。
  • 変更ログをご覧ください。
  • ご不明な点がございましたら、お問い合わせください。
  • LLM ですか?llms.txt を読んでください。
  • Powered by Markdoc