PAY-12Recommended
Freeze what the customer agreed to on the order
When 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.
How to do it
Prices, tax rates and coupons change. An order, its invoice and its refunds must show what the customer agreed to. Keep the price ID on the line for reports. Store the tax calculation ID from your tax service too. Refunds and credit notes work only from the stored lines.
Examples
SQL example
CREATE TABLE order_lines (
order_id text NOT NULL REFERENCES orders(id),
line_no int NOT NULL,
price_id text NOT NULL,
description text NOT NULL,
quantity int NOT NULL CHECK (quantity > 0),
unit_amount_minor bigint NOT NULL,
discount_minor bigint NOT NULL DEFAULT 0,
tax_rate_bp int NOT NULL,
tax_minor bigint NOT NULL,
currency char(3) NOT NULL,
PRIMARY KEY (order_id, line_no)
);
How to check
On staging, change a price and a tax rate, then open an older order and refund it. The order, the invoice and the refund all show the old amounts.
Sources
Related rules
- DAT-5 Keep one fact in one place in Data and databases
- AGT-80 Let agents buy through the same order flow as people in Agents as users
- ECM-13 Recheck prices and stock when the order is placed in E-commerce and fulfilment
- ECM-34 Refund exactly what each returned line cost in E-commerce and fulfilment
- PRC-5 Preview the amount before a plan change in Pricing, plans and entitlements
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/order-snapshot">Agent Wranglers payments and billing playbook</a>. In code you write, add a comment next to it with the same link.