1. Checkout
Documentation
  • Back to home
  • StripeKit
  • Installation
  • Getting Started
  • Choosing a Mode
  • Type Reference
  • Setup
    • Configuration
    • Timezones
    • Storage Adapter
    • Money and Currency
    • Error Handling
  • Stripe
    • Elements
  • Modules
    • Overview
    • Customers
      • Overview
      • List
      • Retrieve
      • Find or Create by Email
      • Create
      • Update
      • Sync
      • Delete
    • Payment Methods
      • Overview
      • Create Setup Intent
      • List
      • Attach
      • Detach
      • Set Default
      • Sync
    • Payments
      • Overview
      • Pay With Saved Method
      • Create
      • Retrieve
      • Confirm
      • Cancel
      • Sync
    • Checkout
      • Overview
      • Get
      • Create
      • Submit Fields
      • Apply Coupon
      • Mark Complete
    • Subscriptions
      • Overview
      • Create
      • Retrieve
      • Cancel
      • Resume
      • Toggle Collection Method
      • Update Fields
      • Apply Promotion Code
      • List By Customer
      • Find By Metadata
      • Sync
    • Invoices
      • Overview
      • Retrieve
      • List By Customer
      • List By Subscription
      • Pay With Saved Method
      • Void
      • Finalize
      • Sync
    • Coupons
      • Overview
      • Create
      • Validate
      • Apply To Subscription
      • List
      • Deactivate
    • Webhooks
      • Overview
      • Process
      • Events Reference
    • Sync
      • Overview
  1. Checkout

Apply Coupon

kit.checkout.applyCoupon()#

Applies (or removes) a coupon code on an existing checkout session in the elements flow, recalculating and updating the underlying PaymentIntent's amount.

Signature#

Parameters#

FieldTypeRequiredDescription
checkoutIdstringYesThe session to apply the coupon to.
couponCodestring|nullYesThe code to apply, or null to remove any currently applied coupon and reset to originalAmount.
originalAmountnumberYesThe pre-discount amount in minor currency units, used as the baseline for the discount calculation and as the fallback if couponCode is null.
paymentIntentIdstring|nullNoUnused directly; the session's own stored PaymentIntent ID is used instead.

Example request#

Example response#

If the discount brings the amount to exactly zero:

Errors#

ExceptionWhen
NotFoundErrorThe checkout session was not found.
ConfigurationErrorThe coupons module isn't attached, which should never happen in normal use.
ValidationErrorcouponCode is invalid or expired; or the session has no active PaymentIntent to discount (for example, an api flow session, or a subscription checkout with no elements-flow PaymentIntent).
StripeOperationErrorStripe rejects the amount update.

Notes#

This only works for sessions that have a PaymentIntent, meaning the elements flow. api-flow (hosted Checkout Session) discounts are applied at creation time via couponCode on create() instead, since Stripe Checkout Sessions can't have their line items changed after creation.
When the discount brings the total to 0, clientSecret is null and no PaymentIntent update is attempted, since a PaymentIntent cannot have an amount of 0. Your frontend should treat isFree: true as "nothing left to confirm, mark the order complete directly."
Discount math: percent coupons multiply originalAmount by (1 - discountValue / 100); amount coupons subtract discountValue (in major units) converted to minor units. Both are rounded and floored at 0.
Previous
Submit Fields
Next
Mark Complete
Built with