03 — Engine
What actually exists
Everything on this page is computed at render time by packages/core — the same pure modules checkout will use. 71 unit tests cover them. The storefront you just browsed is mock fixtures; this is the real build so far.
01 · A live quote
Order of operations is fixed: line = unit × qty → subtotal → discount (allocated across lines) → shipping → tax → total.
| Line | Qty | Unit | Subtotal | Discount | Taxable |
|---|---|---|---|---|---|
| li_tee | 2 | $65.00 | $130.00 | −$26.00 | $104.00 |
| li_hood | 1 | $140.00 | $140.00 | −$28.00 | $112.00 |
| Totals | $270.00 | −$54.00 | $216.00 | ||
Applied: BRUISED20 (value)
pricingHash 14adea7767d34dbdf50f722afbad942d…
02 · Clothing tax thresholds
New York exempts clothing under $110 per item; Massachusetts $175. Stripe recovers the per-unit price by dividing amount ÷ quantity, so both must travel together and both must be post-discount.
| Cart line | Qty | Amount sent | Per unit | NY treatment |
|---|---|---|---|---|
| Rot Tee ×2 | 2 | $130.00 | $65.00 | Exempt |
| Hood 01 ×1 | 1 | $140.00 | $140.00 | Taxable |
| Coach Jacket ×1 | 1 | $200.00 | $200.00 | Taxable |
| Tee ×2 after 20% off | 2 | $104.00 | $52.00 | Exempt |
amount 13000, quantity 1 makes Stripe see a $130 garment and charge NY sales tax on clothing that is individually exempt. And note row 4: a $100 item discounted to $80 crosses below the threshold, so sending gross amounts would tax something exempt at the price actually paid.Tax lines as sent to Stripe:
[
{
"reference": "li_tee",
"amount": 10400,
"quantity": 2,
"taxCode": "txcd_30011000"
},
{
"reference": "li_hood",
"amount": 11200,
"quantity": 1,
"taxCode": "txcd_30011000"
}
]03 · Allocation
Largest-remainder, so the parts always sum to the whole. Naive rounding splits 100¢ three ways as 33/33/33 = 99¢ — and a missing cent fails the database CHECK subtotal − discount + shipping + tax = total, so the order cannot be saved at all.
| Split | Parts | Sum |
|---|---|---|
| 100¢ ÷ 3 equal | 34 · 33 · 33 | 100¢ ✓ |
| $10 by 65/35 weight | 650 · 350 | 1000¢ ✓ |
04 · Order state machine
21 legal transitions. This table generates the Postgres trigger, so the app guard and the database backstop cannot drift — a test regenerates and diffs it. A refund never changes the lifecycle: a delivered, fully refunded order is still delivered.
| From | Event | To |
|---|---|---|
| pending | CHECKOUT_STARTED | awaiting_payment |
| pending | RESERVATION_EXPIRED | expired |
| pending | CANCELLED | cancelled |
| awaiting_payment | PAYMENT_PROCESSING | processing |
| awaiting_payment | PAYMENT_SUCCEEDED | paid |
| awaiting_payment | PAYMENT_FAILED | payment_failed |
| awaiting_payment | RESERVATION_EXPIRED | expired |
| awaiting_payment | CANCELLED | cancelled |
| processing | PAYMENT_SUCCEEDED | paid |
| processing | PAYMENT_FAILED | payment_failed |
| processing | AMOUNT_MISMATCH | under_review |
| processing | RESERVATION_EXPIRED | expired |
| payment_failed | PAYMENT_RETRIED | awaiting_payment |
| payment_failed | RESERVATION_EXPIRED | expired |
| payment_failed | CANCELLED | cancelled |
| under_review | REVIEW_APPROVED | paid |
| under_review | REVIEW_REJECTED | cancelled |
| paid | FULFILLED | fulfilled |
| paid | CANCELLED | cancelled |
| fulfilled | DELIVERED | delivered |
| fulfilled | RETURN_RECEIVED | fulfilled |