Amounts and orders
Hold money as integers with a currency, freeze what the customer agreed to, move orders through fixed states and never charge the same order twice.
- Required 5
- Recommended 1
Required
Hold money as integer minor units everywhere
RequiredHold every amount as an integer count of the currency's minor unit, with its ISO 4217 code, in code, database, provider calls and stored events.
Freeze what the customer agreed to on the order
RequiredWhen the order is created, copy the unit price, quantity, discount, tax rate, tax amount and currency onto each line. Never recompute them from the catalogue.
Move orders through a fixed set of states
RequiredGive orders a fixed list of states and allowed transitions in one place, and refuse any other change with a conditional database update.
Create each charge with an idempotency key
RequiredSend an idempotency key, built from your own stable IDs, on every provider request that creates a payment, a refund or a payout.
Keep one open payment per order
RequiredAllow at most one open payment attempt per order, and reuse it when the customer comes back to checkout.
Recommended
Split amounts without losing a cent
RecommendedWhen you split an amount, such as instalments or a discount across lines, hand out the leftover minor units in a fixed order. The parts must sum exactly to the total.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers payments playbook: https://agentwranglers.se/playbook/payments/amounts-and-orders.