Glossary

Stripe Custom Coupon

A Stripe custom coupon is a coupon with type set to custom, whose discount is worked out by a discount calculation script instead of a fixed percent_off or amount_off, so it can cap a percentage, give free units, or discount only prices you tag with metadata.

Also called: custom coupon, type=custom coupon, discount calculation script, extension-backed coupon, Stripe discount calculation extension

14-day free trial · card required · cancel anytime

Definition

A standard Stripe coupon takes either a percentage or a fixed amount off. Stripe describes the custom type as “A coupon type that uses an extension to calculate the discount.” The extension is a script at the discount calculation extension point, commerce.discount_calculation. Stripe sends it the invoice’s gross amount, its line items with their prices, products and metadata, the billing reason and the customer, and the script returns one number: the amount to subtract.

You can pick one of four Stripe-authored scripts when you create the coupon, with no code, or write your own in TypeScript and upload it as a Stripe App. Either way, the script is chosen and configured on the coupon itself, not on the Billing customizations page that the other billing scripts use. In the API, that means type=custom, the extension’s ID (it starts with extnpro_) in custom.extension.id, and its settings in custom.configuration.

Unlike the other billing scripts, discount calculation also supports classic billing mode, so a custom coupon isn’t limited to subscriptions in flexible billing mode.

Key points

  • +Created in the Dashboard by choosing Custom as the coupon type, or in the API with type=custom and an extension ID in custom.extension.id.
  • +Stripe-authored scripts: Percent off up to maximum, BOGO and quantity promos, Price-targeted amount off, and Price-targeted percent off.
  • +The script returns one non-negative discount amount, in the same currency as the gross amount and no larger than it.
  • +Calculated discounts are spread evenly across the invoice’s items, not attached to the lines that earned them.
  • +Only one custom coupon per subscription, and a custom coupon can’t be applied to a customer directly.
  • +If a user-authored script fails, Stripe falls back to a zero discount and doesn’t retry.
  • +Works in classic and flexible billing mode, unlike the other billing scripts.

The four Stripe-authored discount scripts

Stripe’s discount calculation page lists four scripts you can select when you create a custom coupon, each with Stripe’s own example.

Percent off up to maximum takes a percentage of the invoice total and caps it at an amount. Set to 20% up to 50 USD, a 200 USD invoice gets 40 USD off and a 400 USD invoice gets 50 USD off, not 80 USD. The maximum must be in the invoice currency. If the currencies don’t match, “Stripe applies no discount.”

BOGO and quantity promos gives free units after a purchase quantity, for products tagged with an exact, case-sensitive metadata key and value. Stripe combines quantities of the same product across invoice lines and discounts the cheapest eligible units first. With a buy quantity of 3, a free quantity of 2 and a 20 USD unit price, 3 units get nothing off, 4 units get 20 USD off, and 5 or more get 40 USD off. A purchase quantity of 0 makes it a plain targeted unit discount.

Price-targeted amount off takes a fixed amount off each line whose price carries the metadata. Each line’s discount is capped at its subtotal, and the total at the invoice total. Set to 10 USD, matching lines of 50 USD and 8 USD get 10 USD and 8 USD off, and a nonmatching 30 USD line gets nothing, for 18 USD in all.

Price-targeted percent off takes a percentage off each matching line and adds them up. At 25%, matching lines of 80 USD and 20 USD give 20 USD and 5 USD, for 25 USD, and a nonmatching 40 USD line gets nothing.

Limits Stripe puts on custom coupons

Stripe lists these limits for discount calculation scripts, on top of the general limits for scripts you write yourself. The script can’t change which items are on the invoice or the prices behind them. Multiple custom coupons can’t be applied to the same subscription, and a custom coupon can’t be applied to a customer directly. It can’t give an item-level discount either: “Calculated discounts are distributed evenly across all invoice items on the invoice.” The returned amount must be non-negative and in the same currency as the gross amount.

Custom coupons work on quotes through the quote’s discounts parameter. Stripe runs the script to price the quote, then “recalculates the discount for the resulting invoice or subscription” when the quote is accepted, so a script should return the same amount for the same inputs. They can also be retention offers in the customer portal’s cancellation flow, where the customer sees the coupon’s name and duration but not a predicted price. They can’t be used in portal subscription-update confirmations, or as retention offers on subscriptions with active prebilling.

When the script fails

The fallback for a discount script is different from the other billing scripts. A run fails on an invalid result, an exception or a timeout, and Stripe says it “doesn’t retry failed discount-calculation requests.” Then “If the script fails, Stripe falls back to a zero discount amount.” The invoice is billed at full price.

The Stripe-authored scripts are still in preview, and Stripe’s wording for them is broader: if customization fails or causes harm, Stripe “reserves the right to default to standard functionality and/or pause subscription processing.” Either way, Stripe emails the account when a billing script fails, and every run is listed in Workbench with its inputs and outputs. Stripe’s advice is to apply a new coupon to a subscription in a sandbox and check the resulting invoice before using it in live mode.

What a custom coupon means for QuickBooks

A custom coupon doesn’t add a new kind of entry to your books. It produces a discount on a Stripe invoice like any other coupon, and the invoice still has a gross amount, a discount and a net amount. How that discount lands in QuickBooks depends on whether you record sales at gross with a discount line, usually against a contra-revenue account, or at net.

The even spread is the part to plan for. Because Stripe distributes the calculated discount across all items on the invoice, a BOGO or price-targeted coupon that was earned by one product can show discount amounts on the other lines too. If you report sales by product in QuickBooks at net, the products that didn’t qualify will look discounted. Recording the discount as its own line at the invoice level keeps product revenue clean and puts the promotion’s cost in one place.

Watch the failure case at close. A failed run bills the customer in full, so the invoice in QuickBooks will show full revenue and full receivable. If you honor the promised discount afterwards with a credit note or a refund, that becomes its own transaction, not a correction to the original invoice.

Two older rules still apply. Proration lines are marked discountable=false, so a coupon never discounts a proration directly, though Stripe calculates the proration from the discounted price. And a percent off up to maximum coupon behaves like a percentage on small invoices and a fixed amount on large ones, so the discount rate in QuickBooks will vary from invoice to invoice.

Frequently asked questions

What is a custom coupon in Stripe?

It is a coupon with type set to custom, whose discount is calculated by a script at the discount calculation extension point instead of a fixed percentage or amount. Stripe offers four prebuilt scripts (percent off up to a maximum, BOGO and quantity promos, and price-targeted amount or percent off), and you can write your own.

Can a Stripe coupon take a percentage off with a maximum discount?

Yes, with a custom coupon using the Percent off up to maximum script. Stripe’s example is 20% off up to 50 USD: a 200 USD invoice gets 40 USD off and a 400 USD invoice gets 50 USD off. The maximum has to be in the invoice’s currency, or Stripe applies no discount.

Can I apply a Stripe custom coupon to a customer?

No. Stripe says custom coupons can’t be applied to a customer directly. Apply them to a subscription, where only one custom coupon is allowed, or use them on quotes and as retention offers in the customer portal’s cancellation flow.

What happens if a Stripe custom coupon script fails?

For a script you wrote, Stripe doesn’t retry the calculation and falls back to a zero discount, so the invoice is billed at full price. For the Stripe-authored scripts, which are in preview, Stripe reserves the right to use its standard behavior or pause subscription processing. Failures are emailed to the account and listed in Workbench.

Do custom coupons need flexible billing mode?

No. Discount calculation is the one billing script extension point that also supports classic billing mode. The other billing scripts, such as proration and customer balance scripts, run only on subscriptions in flexible billing mode.

What customers say about running Stripe through Acodei

Stripe Verified Partner BadgeIntuit QuickBooks
★★★★★
“If you're testing out all the different Stripe/QuickBooks integration apps right now, let me save you some time. This one is the best one by far.”
RyanOwner at Indie Music Academy
★★★★★
“Works well and is really helpful for massive transactions. The support is really fast and helpful. 100% recommended.”
AndresCo-founder and CEO at Kanguro Collections and Reinsurance

Related reading

More glossary terms

See the full glossary

Ready to try Acodei?

Connect Stripe to QuickBooks Online in minutes and let the fees, refunds, and payouts land where your accountant expects them.

14-day free trial · card required · cancel anytime