Stacked discount calculator
Final price after several percentage and fixed-amount discounts, applied in order like Stripe's stacked coupons, with an optional cap.
- Version 1
- Checked against 4 published values
- Free, no sign-up
Result: Stripe example: 20% off up to 50 on 400
| Total The price after all discounts (never below 0). |
350.00 exact |
|---|---|
| Total discount subtotal − total. |
50.00 exact |
Steps
| Step | Discount | Amount off | Price after |
|---|---|---|---|
| 1 | 20% | 50.00 | 350.00 |
Rounding: Half up, 2 decimal places. Calculator billing/discounts@1.
How it is calculated
for each discount in order: off = round(p% × price left) or min(amount, price left); price left −= off; the combined discount is at most max_total_discountApplies a list of discounts to a price, one after another. A percentage discount takes that percentage of the price left after the earlier discounts, so order matters: 20% then 5 off is not the same as 5 off then 20%. This is how Stripe applies several coupons to a subscription. With additive stacking, every percentage is taken from the original price instead, so 20% and 10% make 30% off. Each discount is rounded to the cent when it is applied, the price never goes below 0, and max_total_discount caps the combined discount.
- A percentage discount is rounded to the cent when it is applied, the way it appears as a discount line. A subtotal, fixed amount or cap with more decimals is rounded first, with an AMOUNTS_ROUNDED warning, so the steps, total and total_discount always add up to the subtotal.
- A discount larger than the price left takes it to 0 and the rest is not used, as with Stripe coupons (an amount_off of 200 on a 100 invoice gives 0, not a credit).
- Taxes are not included: Stripe applies discounts before tax, so compute tax on the total.
- Amounts are rounded to the cent (2 decimals) half up by default, the usual commercial rule and the one Stripe Tax uses. Set options.decimals for currencies with other minor units (0 for JPY, 3 for KWD) and options.rounding for another rule.
References
- Stripe: Stackable coupons and promotion codes (order of percent_off and amount_off matters)
- Stripe API: Create a coupon (amount_off larger than the subtotal gives 0)
- Stripe: Percent off up to maximum (20% off up to 50 USD)
Results follow each calculator's documented rules and the sources listed. They are not financial, tax or legal advice. Check that the rules fit your case before you rely on a result. See the terms.
Use it from your code
curl https://api.curatedapi.com/v1/calc/billing/discounts \
-H "Authorization: Bearer $CURATEDAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"subtotal": "400",
"discounts": ["20%"],
"max_total_discount": "50"
}'
The same call in Python
import os
import requests
payload = {
"subtotal": "400",
"discounts": ["20%"],
"max_total_discount": "50",
}
response = requests.post(
"https://api.curatedapi.com/v1/calc/billing/discounts",
headers={"Authorization": f"Bearer {os.environ['CURATEDAPI_KEY']}"},
json=payload,
timeout=10,
)
print(response.json()["result"])
The same call in JavaScript
const payload = {
"subtotal": "400",
"discounts": ["20%"],
"max_total_discount": "50",
};
const response = await fetch("https://api.curatedapi.com/v1/calc/billing/discounts", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.CURATEDAPI_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
});
console.log((await response.json()).result);
MCP tool calc_billing_discounts at https://mcp.curatedapi.com.
Inputs, outputs and errors in the API reference.
Put it on your website
<div data-curatedapi-widget="billing/discounts" data-key="capi_public_…"></div>
<script src="https://widgets.curatedapi.com/v1/widget.js" async></script>
Use a public key registered for your site. Calculations are billed like API calls. How widgets work.
Related calculators
Preview and check subscription charges
Show customers the exact charge before they change plan, or check an invoice before it goes out. Proration, tiers and stacked coupons follow the rules Stripe uses, to the cent.
Free for up to 1,000 charges priced a month. 50,000 charges priced a month cost $9.00 on the Starter plan.