curatedapi

Stacked discount calculator

Final price after several percentage and fixed-amount discounts, applied in order like Stripe's stacked coupons, with an optional cap.

The price before discounts.
The discounts in the order they apply: a percentage such as "20%" or an amount off such as "5" (in the subtotal's currency). 1 to 20 items. One per line, or separated by commas.
How percentage discounts combine. Options: sequential: each discount applies to the price left after the earlier ones (Stripe's stacked coupons); additive: each percentage is taken from the original subtotal
Optional cap on the combined discount, like Stripe's "percent off up to maximum" coupon.
More options: rounding and decimals
Precision and rounding
Rounding mode applied once to each result. Default half_up.
Round results to this many digits after the decimal point.

Examples

Result: 100 with 5 off, then 20% off

Total
The price after all discounts (never below 0).
76.00 exact
Total discount
subtotal − total.
24.00 exact

Steps

StepDiscountAmount offPrice after
155.0095.00
220%19.0076.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_discount

Applies 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

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

POST /v1/calc/billing/discountsVersion 1
curl https://api.curatedapi.com/v1/calc/billing/discounts \
  -H "Authorization: Bearer $CURATEDAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "subtotal": "100",
    "discounts": ["5", "20%"]
  }'
The same call in Python
import os

import requests

payload = {
    "subtotal": "100",
    "discounts": ["5", "20%"],
}
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": "100",
    "discounts": ["5", "20%"],
};
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.