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 1
- Recommended 5
Required
Create each charge with an idempotency key
PAY-14Send an idempotency key, built from your own stable IDs, on every provider request that creates a payment, a refund or a payout.
Recommended
Hold money as integer minor units everywhere
PAY-10Hold 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.
Split amounts without losing a cent
PAY-11When 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.
Freeze what the customer agreed to on the order
PAY-12When 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
PAY-13Give orders a fixed list of states and allowed transitions in one place, and refuse any other change with a conditional database update.
Keep one open payment per order
PAY-15Allow at most one open payment attempt per order, and reuse it when the customer comes back to checkout.
Read this with
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/payments/amounts-and-orders">Agent Wranglers payments and billing playbook</a>. In code you write, add a comment next to it with the same link.