Our pricing page shows three currencies, and the only place a price is written down is one table. Here is how that holds together.
You can see it live: pounds, euros and dollars are the same page with a different query string.
One table, nothing else holds a price
CogniPrep Assess sells yearly plans by candidate allowance. The pricing page, the allowance screens, the emails and the plan change in Settings all read from a single price book in lib/pricing.ts. Amounts are stored in minor units (pence, cents), with a digit separator before the last two digits so a person can read them:
{ key: 'starter', allowance: 250, yearlyFee: { GBP: 1_900_00, EUR: 2_300_00, USD: 2_600_00 }, extraCandidate: { GBP: 10_00, EUR: 12_00, USD: 13_50 }, } 1_900_00 is 1,900.00. Everything else is derived: the difference between tiers, "from" prices, and what an upgrade costs part way through a year.
Fixed price lists, not live conversion
The three currencies are separate price lists. I converted the pound figures once and rounded up to a tidy number, so the euro and dollar prices do not wobble with an exchange rate. The catch is that changing a pound figure moves nothing else, so you have to change all three. That is exactly the sort of thing that goes wrong quietly, which is why the file is full of tests.
Tests that state the pricing logic
The suite does not just check that numbers equal numbers. It checks relationships, in every currency:
- each tier is bigger and dearer than the last, and its extra-candidate price is lower;
- an extra candidate always costs more than an included one;
- the one-off pack is never cheaper per candidate than an extra on the smallest plan;
- on the middle plan, moving up is cheaper than buying extras up to the safety ceiling.
If I fix a price in pounds and forget the dollar one, a test fails rather than a customer noticing.
Choosing the currency
Two inputs, one rule: the address wins.
export function pricingCurrency({ query, country }) { const asked = (Array.isArray(query) ? query[0] : query)?.trim().toUpperCase(); return isCurrency(asked) ? asked : currencyForCountry(country); } With no ?currency=, the page uses the visitor's country from the x-vercel-ip-country header: pounds for the UK and the Crown Dependencies, euros for the euro area and the places that use the euro anyway, dollars for everywhere else. With no country at all, as on a local machine, it is pounds.
Letting the address win is the useful part. A visitor can switch currency, and a link can be shared already in euros. It also means the page is rendered per request, because it reads headers. That was a deliberate trade against a static page.
Unknown currencies are written out
formatMoney renders £6, €7.50, $1,650 and drops decimals on whole amounts. A currency code the price book does not know is written as a code and an amount, so it is never mistaken for one we publish.
What I would do differently
I would generate the euro and dollar columns from one source and a rounding rule, then freeze the output. Today the conversion lives in a comment, and a comment is a weak place to keep a decision. The tests catch ordering mistakes, not a figure that is simply stale.
If you want to see where the table ends up, the pricing page is the real thing, and how it works shows the product the prices are for.