From dd087d8826668fd70784f91f029d6f1d97087953 Mon Sep 17 00:00:00 2001 From: ordinarthur Date: Fri, 27 Feb 2026 18:37:58 +0100 Subject: [PATCH] add receipt --- server.mjs | 6 +++++- src/pages/success.astro | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server.mjs b/server.mjs index 94a2720..d53e6cf 100644 --- a/server.mjs +++ b/server.mjs @@ -69,13 +69,17 @@ app.post('/api/checkout', async (request, reply) => { // ── Vérification session ────────────────────────────────────────────────────── app.get('/api/session/:id', async (request) => { - const session = await stripe.checkout.sessions.retrieve(request.params.id) + const session = await stripe.checkout.sessions.retrieve(request.params.id, { + expand: ['payment_intent.latest_charge'], + }) + const charge = session.payment_intent?.latest_charge return { status: session.payment_status, amount: session.amount_total, currency: session.currency, customer_email: session.customer_details?.email ?? null, product: session.metadata?.product ?? null, + receipt_url: charge?.receipt_url ?? null, } }) diff --git a/src/pages/success.astro b/src/pages/success.astro index e4775b6..7a5846d 100644 --- a/src/pages/success.astro +++ b/src/pages/success.astro @@ -125,7 +125,10 @@ import Base from '../layouts/Base.astro'; Un email de confirmation vous sera envoyé.
Votre lampe est fabriquée à la main à Paris.

- ← RETOUR À LA COLLECTION +
+ ← RETOUR + +
@@ -152,7 +155,7 @@ import Base from '../layouts/Base.astro'; if (sessionId) { fetch(`/api/session/${sessionId}`) .then(r => r.json()) - .then((data: { amount?: number; customer_email?: string; product?: string }) => { + .then((data: { amount?: number; customer_email?: string; product?: string; receipt_url?: string }) => { const loading = document.getElementById('loading'); const orderDetails = document.getElementById('order-details'); if (loading) loading.style.display = 'none'; @@ -168,6 +171,11 @@ import Base from '../layouts/Base.astro'; const img = document.getElementById('product-img') as HTMLImageElement; if (img) img.src = PRODUCT_IMAGES[data.product]!; } + + if (data.receipt_url) { + const btn = document.getElementById('receipt-btn') as HTMLAnchorElement; + if (btn) { btn.href = data.receipt_url; btn.style.display = 'inline-block'; } + } }) .catch(() => { const loading = document.getElementById('loading');