Show prices in the shop currency (STRIPE_CURRENCY), not hard-coded EUR
formatPrice always formatted EUR, so the public shop, checkout, basket and order confirmation showed € even when Stripe charged another currency. It now takes a currency; both apps pass STRIPE_CURRENCY to the blocks as layout data `currency` (like `timezone`), so one setting drives what Stripe charges and every price shown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qq6FzyGitv5gDZEcCHDGoo
This commit is contained in:
parent
de8d29beb4
commit
e29eaaa8e8
9 changed files with 93 additions and 65 deletions
|
|
@ -5,7 +5,7 @@
|
|||
import { page } from '$app/state';
|
||||
import { DEFAULT_NOTES_HINT, DEFAULT_PRIVACY_NOTICE, type BasketLine, type CheckoutBlockData } from '$shared/types';
|
||||
import { getBasketContext } from '$shared/basket.svelte';
|
||||
import { DEFAULT_TIMEZONE, formatInstant, formatPrice } from '$shared/calendar';
|
||||
import { DEFAULT_CURRENCY, DEFAULT_TIMEZONE, formatInstant, formatPrice } from '$shared/calendar';
|
||||
import { loadStripe } from '$shared/stripe-client';
|
||||
import type { Stripe, StripeElements, StripePaymentElement } from '@stripe/stripe-js';
|
||||
|
||||
|
|
@ -43,12 +43,15 @@
|
|||
lastSig = sig;
|
||||
});
|
||||
|
||||
// Prices in the shop currency (STRIPE_CURRENCY, via layout data).
|
||||
const currency = $derived<string>(page.data.currency ?? DEFAULT_CURRENCY);
|
||||
|
||||
const payLabel = $derived(
|
||||
payState === 'confirming'
|
||||
? 'Confirming…'
|
||||
: payState === 'creating'
|
||||
? 'Preparing payment…'
|
||||
: `Pay ${formatPrice(basket.total)}`
|
||||
: `Pay ${formatPrice(basket.total, currency)}`
|
||||
);
|
||||
|
||||
const timezone = $derived<string>(page.data.timezone ?? DEFAULT_TIMEZONE);
|
||||
|
|
@ -345,7 +348,7 @@
|
|||
{#if line.lineType === 'slot' && line.slotStart}
|
||||
<p class="text-sm text-fg-body/70">{formatSlotTime(line.slotStart)}</p>
|
||||
{/if}
|
||||
<p class="text-sm text-fg-body/70">{formatPrice(line.itemPrice ?? 0)}</p>
|
||||
<p class="text-sm text-fg-body/70">{formatPrice(line.itemPrice ?? 0, currency)}</p>
|
||||
</div>
|
||||
|
||||
<!-- Products, and places in a group session (capacity > 1); the server checks what's left. -->
|
||||
|
|
@ -374,7 +377,7 @@
|
|||
{/if}
|
||||
|
||||
<p class="w-20 shrink-0 text-right font-medium">
|
||||
{formatPrice((line.itemPrice ?? 0) * line.quantity)}
|
||||
{formatPrice((line.itemPrice ?? 0) * line.quantity, currency)}
|
||||
</p>
|
||||
|
||||
<button
|
||||
|
|
@ -394,7 +397,7 @@
|
|||
<div class="mt-6 rounded-2xl border border-charcoal/10 bg-white p-5">
|
||||
<div class="flex items-center justify-between">
|
||||
<span class="text-fg-body/70">Subtotal</span>
|
||||
<span class="font-serif text-xl font-bold">{formatPrice(basket.total)}</span>
|
||||
<span class="font-serif text-xl font-bold">{formatPrice(basket.total, currency)}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
@ -505,7 +508,7 @@
|
|||
disabled={payState === 'confirming'}
|
||||
onclick={confirmPayment}
|
||||
>
|
||||
{payState === 'confirming' ? 'Confirming…' : `Confirm payment — ${formatPrice(basket.total)}`}
|
||||
{payState === 'confirming' ? 'Confirming…' : `Confirm payment — ${formatPrice(basket.total, currency)}`}
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
import { page } from '$app/state';
|
||||
import type { BasketLine, ShopBlockData, ItemRecord, SlotRecord } from '$shared/types';
|
||||
import { getBasketContext } from '$shared/basket.svelte';
|
||||
import { DEFAULT_TIMEZONE, addMonths, createCalendarMonth, formatInstant, formatPrice, startOfMonth, zonedDateKey } from '$shared/calendar';
|
||||
import { DEFAULT_CURRENCY, DEFAULT_TIMEZONE, addMonths, createCalendarMonth, formatInstant, formatPrice, startOfMonth, zonedDateKey } from '$shared/calendar';
|
||||
import { formatDateKey } from '$shared/slots';
|
||||
|
||||
let { data = {}, items = [], slots = [] } = $props<{
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
const MONTHS_SHOWN = 2;
|
||||
const weekdayLetters = ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
|
||||
const timezone = $derived<string>(page.data.timezone ?? DEFAULT_TIMEZONE);
|
||||
const currency = $derived<string>(page.data.currency ?? DEFAULT_CURRENCY);
|
||||
|
||||
let visibleItems: ItemRecord[] = $derived.by(() => {
|
||||
let result: ItemRecord[] = items;
|
||||
|
|
@ -234,7 +235,7 @@
|
|||
{/if}
|
||||
|
||||
<div class="mt-auto flex flex-wrap items-center gap-x-3 gap-y-1 pt-3">
|
||||
<span class="text-lg font-semibold text-sage-dark">{formatPrice(item.price)}</span>
|
||||
<span class="text-lg font-semibold text-sage-dark">{formatPrice(item.price, currency)}</span>
|
||||
{#if isService && item.duration != null}
|
||||
<span class="text-xs text-charcoal/60">{item.duration} min</span>
|
||||
{:else if !isService && item.stock != null && item.stock > 0 && item.stock <= 5}
|
||||
|
|
|
|||
|
|
@ -58,8 +58,25 @@ export const DISPLAY_LOCALE = 'en-GB';
|
|||
/** Fallback when no SITE_TIMEZONE reaches the page. */
|
||||
export const DEFAULT_TIMEZONE = 'Europe/Oslo';
|
||||
|
||||
export function formatPrice(amount: number) {
|
||||
return new Intl.NumberFormat(DISPLAY_LOCALE, { style: 'currency', currency: 'EUR' }).format(amount);
|
||||
/** Fallback when no shop currency reaches the page. */
|
||||
export const DEFAULT_CURRENCY = 'EUR';
|
||||
|
||||
/**
|
||||
* The shop currency as an ISO 4217 code, from STRIPE_CURRENCY ('nok' → 'NOK').
|
||||
* One setting for what Stripe charges and what every price shows.
|
||||
*/
|
||||
export function shopCurrency(value: string | undefined) {
|
||||
return (value || DEFAULT_CURRENCY).toUpperCase();
|
||||
}
|
||||
|
||||
/** A price in the shop currency (layout data `currency`). */
|
||||
export function formatPrice(amount: number, currency = DEFAULT_CURRENCY) {
|
||||
try {
|
||||
return new Intl.NumberFormat(DISPLAY_LOCALE, { style: 'currency', currency }).format(amount);
|
||||
} catch {
|
||||
// Not a currency code Intl knows (a typo in STRIPE_CURRENCY).
|
||||
return `${amount.toFixed(2)} ${currency}`;
|
||||
}
|
||||
}
|
||||
|
||||
/** Format an instant in `timeZone` with the display locale. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue