Initial commit: Craft2Prints with Stages 1-3
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export type CurrencyCode = 'GBP' | 'USD' | 'EUR';
|
||||
|
||||
// Prices are stored as an integer in GBP pence — that's the canonical/base currency
|
||||
// for this site. These rates are fixed approximations for customer-facing display
|
||||
// only; they are NOT live exchange rates and are NOT used for actual payment
|
||||
// amounts (checkout charges in GBP regardless of what's displayed here). Update
|
||||
// them periodically if you want display prices to stay roughly current.
|
||||
export const CURRENCIES: { code: CurrencyCode; symbol: string; rate: number; label: string }[] = [
|
||||
{ code: 'GBP', symbol: '£', rate: 1, label: 'GBP — British Pound' },
|
||||
{ code: 'USD', symbol: '$', rate: 1.27, label: 'USD — US Dollar' },
|
||||
{ code: 'EUR', symbol: '€', rate: 1.17, label: 'EUR — Euro' },
|
||||
];
|
||||
|
||||
export function formatPrice(basePenceGBP: number, currency: CurrencyCode): string {
|
||||
const info = CURRENCIES.find((c) => c.code === currency) ?? CURRENCIES[0];
|
||||
const converted = (basePenceGBP / 100) * info.rate;
|
||||
return `${info.symbol}${converted.toFixed(2)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user