コンテンツにスキップ
アカウントを作成
または
サインイン
Stripe ドキュメントのロゴ
/
Ask AI
アカウントを作成
サインイン
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
開発者向けのツール
始める
支払い
財務の自動化
始める
支払い
財務の自動化
プラットフォームおよびマーケットプレイス
資金管理
概要
Stripe Payments について
構築済みのシステムをアップグレード
支払いの分析
オンライン決済
概要ユースケースを見つけるManaged Payments
Payment Links を使用する
決済ページを構築
    概要
    クイックスタート
    デザインをカスタマイズする
    追加情報を収集する
    税金を徴収する
    決済フローを動的に更新
    商品カタログを管理する
      限られた在庫を管理
      ラインアイテムの数量を調整可能にする
      顧客が支払い金額を決定できるようにする
    サブスクリプション
    決済手段を管理
    顧客が現地通貨で支払いできるようにする
    割引、アップセル、オプション品目を追加する
    将来の支払いを設定する
    支払い中に支払い詳細を保存する
    Manually approve payments on your server
    支払い後
    Elements with Checkout Sessions API ベータ版の変更ログ
    従来の Checkout からの移行
    Checkout を移行して Prices を使用
高度なシステムを構築
アプリ内実装を構築
支払い方法
決済手段を追加
決済手段を管理
Link による購入の迅速化
支払いインターフェイス
Payment Links
Checkout
Web Elements
アプリ内 Elements
決済シナリオ
カスタムの決済フロー
柔軟なアクワイアリング
オーケストレーション
店頭支払い
端末
他の Stripe プロダクト
Financial Connections
仮想通貨
Climate
ホーム支払いBuild a checkout pageManage your product catalog

注

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

ラインアイテムの数量を調整可能にする

顧客が決済時にラインアイテムの数量を調整できるようにします。

ページをコピー

各 Checkout セッションのラインアイテムは、顧客が購入しようとしているものを追跡します。顧客が決済時にラインアイテムの数量を調整できるように、Checkout セッションを設定できます。

数量の調整を有効にする
サーバー側

注

新しいラインアイテムの追加など、その他のラインアイテムの更新には、この実装は対応していません。

Checkout セッションを作成する際、line_items に adjustable_quantity を設定して、顧客が決済時にアイテムの数量を更新できるようにします。

Command Line
cURL
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d "line_items[0][price_data][currency]"=usd \ -d "line_items[0][price_data][product_data][name]"=T-shirt \ -d "line_items[0][price_data][unit_amount]"=2000 \ -d "line_items[0][quantity]"=1 \ -d "line_items[0][adjustable_quantity][enabled]"=true \ -d "line_items[0][adjustable_quantity][maximum]"=100 \ -d "line_items[0][adjustable_quantity][minimum]"=0 \ -d mode=payment \ -d ui_mode=custom \ -d return_url={{RETURN_URL}}

adjustable_quantity.minimum と adjustable_quantity.maximum を設定することにより、指定できる最小 / 最大数量のデフォルト設定をカスタマイズできます。デフォルトでは、アイテムの調整可能な最小数量は 0、調整可能な最大数量は 99 です。adjustable_quantity.maximum には最大 999999 の値を指定できます。

Checkout では、アイテムが残り 1 つの場合、顧客はそれを削除できません。

ラインアイテムの数量を更新する
クライアント側

updateLineItemQuantity を使用して、数量を増やすボタンなど、顧客の操作に応じてラインアイテムの数量を変更します。ラインアイテム ID と新しい数量を渡します。

index.html
<button class="increment-quantity-button" data-line-item="{{line item ID}}">+</button>
checkout.js
stripe.initCheckout({fetchClientSecret}).then((checkout) => { const button = document.querySelector('.increment-quantity-button'); const lineItem = button.getAttribute("data-line-item"); const quantity = checkout.session().lineItems.find((li) => li.id === lineItem).quantity; button.addEventListener('click', () => { checkout.updateLineItemQuantity({ lineItem, quantity: quantity + 1, }) }) });

完了した取引を処理する
サーバー側

After the payment completes, you can make a request for the finalized line items and their quantities. If your customer removes a line item, it is also removed from the line items response. See the Fulfillment guide to learn how to create an event handler to handle completed Checkout Sessions.

注

To test your event handler, install the Stripe CLI and use stripe listen --forward-to localhost:4242/webhook to forward events to your local server.

Ruby
# 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"
require 'sinatra' # You can find your endpoint's secret in your webhook settings endpoint_secret = 'whsec_...' post '/webhook' do event = nil # Verify webhook signature and extract the event # See https://stripe.com/docs/webhooks#verify-events for more information. begin sig_header = request.env['HTTP_STRIPE_SIGNATURE'] payload = request.body.read event = Stripe::Webhook.construct_event(payload, sig_header, endpoint_secret) rescue JSON::ParserError => e # Invalid payload return status 400 rescue Stripe::SignatureVerificationError => e # Invalid signature return status 400 end if event['type'] == 'checkout.session.completed' checkout_session = event['data']['object'] line_items = Stripe::Checkout::Session.list_line_items(checkout_session['id'], {limit: 100}) # Fulfill the purchase... begin fulfill_order(checkout_session, line_items) rescue NotImplementedError => e return status 400 end end status 200 end def fulfill_order(checkout_session, line_items) # TODO: Remove error and implement... raise NotImplementedError.new(<<~MSG) Given the Checkout Session "#{checkout_session.id}" load your internal order from the database here. Then you can reconcile your order's quantities with the final line item quantity purchased. You can use `checkout_session.metadata` and `price.metadata` to store and later reference your internal order and item ids. MSG end
このページはお役に立ちましたか。
はいいいえ
お困りのことがございましたら 、サポートにお問い合わせください。
早期アクセスプログラムにご参加ください。
変更ログをご覧ください。
ご不明な点がございましたら、お問い合わせください。
LLM ですか?llms.txt を読んでください。
Powered by Markdoc