Sign in
An image of the Stripe logo
Create account
Sign in
Home
Payments
Business operations
Financial services
Developer tools
Security
All products
Home
Payments
Business operations
Home
Payments
Business operations
Financial services
Developer tools
Support
Overview
Overview
How Checkout works
Quickstart
Fulfill your orders
Migrate payment methods to the Dashboard
Manage limited inventory
Migrate from legacy Checkout
Migrate Checkout to use Prices
Additional features
Add discounts
Add shipping
Make line item quantities adjustable
Let customers decide what to pay
Collect taxes
Collect tax IDs
Collect phone numbers
Customize your integration
Customize success page
Configure subscription upsells
Configure cross-sells
Recover abandoned carts
Collect consent for promotional emails
Analyze conversion funnel
Embed a pricing table (Beta)
Start a free trial without collecting payment details (Beta)
Testing
No-code options
checkout
·
HomePayments

Make line item quantities adjustable

Configure the Checkout Session so customers can adjust line item quantity during checkout.

Create a Checkout Session with adjustable_quantity enabled

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

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 999 for adjustable_quantity.maximum.

When using adjustable quantities with a line_items[].quantity value greater than 99 (the default adjustable maximum), set adjustable_quantity.maximum to be greater than or equal to that item’s quantity.

If you use adjustable quantities, change your configuration so that it uses adjustable_quantity.maximum when creating the Checkout Session to reserve inventory quantity instead of the line_items quantity.

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

# 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_4eC39HqLyjWDarjtT1zdp7dc"
require 'json' require 'sinatra' post '/create-checkout-session' do session = Stripe::Checkout::Session.create({ payment_method_types: ['card'], line_items: [{ price: '{{PRICE_ID}}', adjustable_quantity: { enabled: true, minimum: 1, maximum: 10, }, quantity: 1, }], mode: 'payment', success_url: 'https://example.com/success', cancel_url: 'https://example.com/cancel', }) { id: session.id }.to_json end

Handling completed transactions

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.

# 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_4eC39HqLyjWDarjtT1zdp7dc"
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/signatures 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
Was this page helpful?
Questions? Contact us.
View developer tutorials on YouTube.
Check out our product changelog.
Powered by Markdoc
You can unsubscribe at any time. Read our privacy policy.
On this page
Create a Checkout Session with enabled
Handling completed transactions
Stripe Shell
Test mode
▗▄ ▄▟█ █▀▀ ▗▟████▙▖ ██████ ███▗▟█ ███ ███▗▟██▙▖ ▗▟█████▙▖ ███▖ ▀▀ ███ ███▀▀▀ ███ ███▀ ███ ███ ███ ▝▜████▙▖ ███ ███ ███ ███ ███ █████████ ▄▄ ▝███ ███ ▄ ███ ███ ███▄ ███ ███ ▄▄ ▝▜████▛▘ ▝▜███▛ ███ ███ ███▝▜██▛▘ ▝▜█████▛▘ ███ ▀▘
Welcome to the Stripe Shell! Stripe Shell is a browser-based shell with the Stripe CLI pre-installed. Login to Stripe docs and press Control + Backtick on your keyboard to start managing your Stripe resources in test mode. - View supported commands: - Find webhook events: - Listen for webhook events: - Call Stripe APIs: stripe [api resource] [operation] (e.g. )
The Stripe Shell is best experienced on desktop.
$