๐Ÿ’ณ
๐Ÿ’ณ Money & Payments in Software ยท PAY-101 ยท Session 3 of 6

Prices, Discounts & Tax

A checkout total is a small pipeline that's easy to get subtly wrong: subtotal, then discount, then tax on the discounted amount, then shipping. Order and rounding both matter - do them deliberately.

โฑ 8 min read๐Ÿ“… Updated 2026-08-10๐Ÿ“Š Tables, charts & examples

Turning a cart into a total looks trivial and is quietly full of traps. Does '20% off' apply before or after the coupon? Is tax charged on the price before or after the discount? Is the price tax-inclusive (most of the world) or tax-exclusive (US sales tax added at the till)? Get the order or the rounding wrong and every order is off by a little. This session lays out the checkout pipeline and the rules that keep it correct.

๐Ÿ“Œ Worked example
Two coupons, one argument. A shopper has a 20%-off code and a $5-off code on a $100 order. Apply 20% then $5: $100 -> $80 -> $75. Apply $5 then 20%: $100 -> $95 -> $76. Same two coupons, a dollar apart - purely because of order. Neither is 'wrong' mathematically, but the business must pick a rule and apply it consistently, or customers comparing receipts will (rightly) cry foul. Then tax: at 8% on the discounted $75, that's $6, for $81 before shipping - not 8% of the original $100. Get the order or the base wrong and every discounted order is a little off. The lesson isn't a formula; it's that the pipeline - discount (in a defined order), then tax on what's actually owed, then shipping - has to be deliberate and consistent, because money that's 'a dollar off, sometimes' is a trust problem, not just a rounding one.

The checkout pipeline

A total is a sequence of steps, and the order is not arbitrary - it changes the answer.

subtotal   = sum(qty x unit_price)      # from the line items
discount   = apply discounts to the subtotal
base       = subtotal - discount
tax        = round(base x tax_rate)      # tax on the DISCOUNTED amount
total      = base + tax + shipping
๐ŸŽฏ
Discount first, then tax on the discounted amount, then shipping. Tax is almost always charged on what the customer actually pays after discounts, not the pre-discount price - charging tax on the full price when there's a discount overcharges the customer. Discounts that stack apply in order, each to the running total, so '20% off then $5 off' differs from '$5 off then 20% off' - be explicit about the order. And every step rounds to the cent, so the pieces must still add up: subtotal - discount + tax + shipping == total. The stack's larzcart runs exactly this pipeline, larzdiscount handles stacking/caps/tiers, and larztax does the tax math.

Inclusive vs exclusive tax

The single most common tax bug is confusing tax-inclusive and tax-exclusive prices.

StyleWho uses itThe price...You need to...
ExclusiveUS sales taxexcludes tax; tax is addedadd tax on top (add_on)
InclusiveVAT / GST (most countries)already includes taxextract tax out (extract)
Compounde.g. Quebec QST on GSTa tax stacked on a taxapply on the running total

With an exclusive price you <b>add</b> tax on top; with an inclusive price the tax is already baked in and you must <b>extract</b> it (net = gross / (1 + rate)) to know the tax portion. Compound taxes stack on the running total, not the bare price. Whichever way, the rounded lines must reconcile to the gross - <a href='/stack/larztax'>larztax</a> absorbs any rounding drift into the final line so <code>net + taxes == gross</code> exactly. And note: correct tax <i>math</i> is your job; the correct <i>rate</i> for a given sale is a legal question, not something a library can answer.

Getting the total right

  • Order matters: subtotal -> discount -> tax on the discounted amount -> shipping.
  • Stacked discounts apply in order, each to the running total.
  • Know inclusive vs exclusive tax - add on top, or extract out; they're different.
  • Everything reconciles to the cent - round each step deliberately.

๐Ÿงฉ Do it with LarzOS

Turn this lesson into action with the exact free tools and AI workflows for the job:

๐ŸŽฏ Key takeaways

  • A checkout total is a pipeline: subtotal -> discount -> tax on the discounted amount -> shipping.
  • Tax is charged on what the customer pays after discounts, not the pre-discount price.
  • Stacked discounts apply in order, each to the running total - the order changes the result.
  • Know inclusive (VAT, extract) vs exclusive (US, add on top) tax; both must reconcile to the cent.

Frequently asked

Should tax really be calculated on the price after the discount, not before?

In the large majority of real cases, yes - tax is calculated on the actual amount the customer pays after discounts are applied, because tax is generally owed on the real transaction price, and a discount reduces that price. If an item is $100 and the customer uses a $20 discount, they pay $80, and tax is typically owed on the $80 they actually paid, not the original $100 - charging tax on the full $100 would overcharge the customer for tax on money they never paid. This is the standard behaviour for most discounts (sales, coupons, promotional price reductions) in most jurisdictions, which is why the correct pipeline applies the discount first and then computes tax on the discounted amount. That said - and this is where it gets genuinely complicated - tax law is jurisdiction-specific and has exceptions, so the precise rule can vary by location and by the type of discount. Some specific situations are treated differently: for example, certain manufacturer coupons or rebates (where a third party reimburses the seller) may be taxed on the pre-discount price in some jurisdictions, because the seller effectively receives the full amount; and some regions have particular rules for specific discount types. So while 'tax on the discounted amount' is the correct and standard default that handles most cases, the authoritative answer for a specific business depends on its jurisdiction's tax rules and the nature of the discount, which is a legal/accounting question. The software principle is clear: your system should be able to apply discounts before tax (the common correct case) and compute tax on the resulting amount, and it should be flexible enough to handle the exceptions your jurisdiction requires. A tax library like larztax gets the math right for whatever base you give it; determining the correct taxable base (post-discount, or pre-discount for special cases) according to your local law is the business's responsibility, ideally with professional tax advice. So: default to tax-on-discounted-amount (correct for most cases), but know that tax law has jurisdiction-specific exceptions, and get proper advice for your situation. The key software point is to compute the pipeline correctly and flexibly; the key real-world point is that the correct taxable base is a legal question.

Why is confusing inclusive and exclusive tax such a common and serious bug?

It's common because the same price number means two completely different things depending on the convention, and if your code assumes the wrong one, it silently computes wrong totals that look plausible - so the bug hides until someone reconciles the numbers. Consider a price of 100 with a 20% tax. If that 100 is tax-exclusive (US-style), the customer pays 120 (100 + 20 tax) and the business keeps 100. If that same 100 is tax-inclusive (VAT-style, common in most of the world), the customer pays 100 total, of which about 16.67 is tax and 83.33 is the net price - the tax is already inside the 100. These are very different outcomes (the customer pays 120 vs 100; the business nets 100 vs 83.33; the tax is 20 vs 16.67), yet the input number '100' looks identical. If a developer writes code assuming exclusive tax but the prices are actually inclusive (or vice versa), every calculation is wrong - either overcharging customers, undercharging them, or misreporting the tax owed to authorities - and because the numbers still look like reasonable money amounts, nothing crashes or obviously breaks; the error only surfaces when totals don't reconcile, tax filings are off, or customers complain. It's especially dangerous for international systems, where different countries use different conventions, so the same codebase might need to handle both. The seriousness comes from the consequences: wrong tax handling can mean financial losses, unhappy customers, and compliance problems with tax authorities (which can carry penalties). The fix is to be explicit everywhere about which convention a price uses, and to use tax handling that supports both operations clearly - adding tax onto an exclusive price, and extracting tax out of an inclusive price - as distinct, named operations (as larztax does with add_on vs extract), so you never accidentally treat one as the other. Store or label whether prices are tax-inclusive or exclusive, handle the two cases deliberately, and test both. The bug is common because the ambiguity is invisible in the raw number and the wrong assumption fails silently; it's serious because money and legal compliance are at stake. Explicitness about the convention, and using the right operation for each, is the defence.

Session 3 of 6 complete

Next up: Keeping the Books: Double-Entry

Continue to Session 4 โ†’

Related lessons

More in this course

Course home → · Browse all courses →