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_
orpayment_ method requires_
).confirmation - After confirmation, you generally can’t increase the amount.
Update the client SDKClient-side
When using Elements with the Checkout Sessions API, wrap client calls to your server in runServerUpdate
so the checkout state and totals refresh.
Create server endpointsServer-side
Calculate amounts and validate inputs on your server. Then, you can update line_
with price_data to add ad-hoc charges.
Remarque
Updating the line_
or price_
recalculates the Session total and taxes.