Accéder directement au contenu
Créez un compte
ou
connecter-vous
Logo de la documentation Stripe
/
Demander à l'assistant IA
Créez un compte
Connectez-vous
Démarrer
Paiements
Revenus
Plateformes et places de marché
Gestion de fonds
Ressources pour les développeurs
Aperçu
À propos des paiements Stripe
Mettre votre intégration à niveau
Analyses des paiements
Paiements en ligne
PrésentationTrouver votre cas d'usageUse Managed Payments
Utiliser Payment Links
Utiliser une page de paiement préconfigurée
Build a custom integration with Elements
    Présentation
    Compare Checkout Sessions and PaymentIntents
    Quickstart guides
    Concevoir une intégration avancée
    Personnaliser l'apparence
    Gérer les moyens de paiement
    Collecter des informations supplémentaires
    Créer une intégration pour les abonnements
    Dynamic updates
      Shipping options
      Postes de facture
      Trial durations
      Discounts
      Payment amounts
      Line item quantities
    Ajouter des réductions
    Percevoir les taxes sur vos paiements
    Offrir aux clients la possibilité de payer dans leur devise locale
    Enregistrer et récupérer les moyens de paiement des clients
    Envoyer des reçus ou factures après paiement
    Approuver manuellement les paiements sur votre serveur
    Autoriser et capturer un paiement séparément
    Liste des modifications de la version bêta d'Elements avec l'API Checkout Sessions
Développer une intégration dans l'application
Moyens de paiement
Ajouter des moyens de paiement
Gérer les moyens de paiement
Paiement accéléré avec Link
Interfaces de paiement
Payment Links
Checkout
Elements pour le web
Paiements dans l'application
Scénarios de paiement
Gérer plusieurs devises
Tunnels de paiement personnalisés
Acquisition flexible
Orchestration
Paiements par TPE
Terminal
Au-delà des paiements
Constituez votre entreprise
Cryptomonnaies
Financial Connections
Climate
Comprendre la fraude
Radar pour la protection contre la fraude
Gestion des litiges
Vérifier l'identité
AccueilPaiementsBuild a custom integration with ElementsDynamic updates

Remarque

Cette page n'est pas encore disponible dans cette langue. Nous faisons tout notre possible pour proposer notre documentation dans davantage de langues et nous vous fournirons la version traduite dès qu'elle sera disponible.

Make line item quantities adjustable

Learn how to allow your customers to adjust the quantity of items during checkout.

The line items for each Checkout Session keep track of what your customer is purchasing. You can configure the Checkout Session so customers can adjust line item quantities during checkout.

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.

Enable adjustable quantities
Server-side

Remarque

Other line item updates, such as adding new line items, aren’t supported for this integration.

Set adjustable_quantity on your line_items when creating a Checkout Session to allow your customers to update the quantity of an item during checkout.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
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}}

You can customize the default settings for the minimum and maximum quantities allowed by setting adjustable_quantity.minimum and adjustable_quantity.maximum. By default, an item’s minimum adjustable quantity is 0 and the maximum adjustable quantity is 99. You can specify a value of up to 999999 for adjustable_quantity.maximum.

Checkout prevents the customer from removing an item if it’s the only item remaining.

Update line item quantities
Client-side

Use updateLineItemQuantity to change a line item’s quantity in response to customer interaction, such as a button to increment the quantity. Pass the line item ID and the new quantity:

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, }) }) });

Handle completed transactions
Server-side

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.

Remarque

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
Python
PHP
Java
Node.js
Go
.NET
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"
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
Cette page vous a-t-elle été utile ?
OuiNon
  • Besoin d'aide ? Contactez le service Support.
  • Rejoignez notre programme d'accès anticipé.
  • Consultez notre log des modifications.
  • Des questions ? Contactez l'équipe commerciale.
  • LLM ? Lire llms.txt.
  • Propulsé par Markdoc