add receipt

This commit is contained in:
ordinarthur 2026-02-27 18:37:58 +01:00
parent 598cb49b61
commit dd087d8826
2 changed files with 15 additions and 3 deletions

View File

@ -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,
}
})

View File

@ -125,7 +125,10 @@ import Base from '../layouts/Base.astro';
Un email de confirmation vous sera envoyé.<br>
Votre lampe est fabriquée à la main à Paris.
</p>
<a href="/" class="back">← RETOUR À LA COLLECTION</a>
<div style="display:flex; gap:0.8rem; flex-wrap:wrap;">
<a href="/" class="back">← RETOUR</a>
<a id="receipt-btn" href="#" target="_blank" rel="noopener" class="back" style="display:none; background:var(--clr-black); color:#e8a800; border-color:var(--clr-black);">↓ FACTURE PDF</a>
</div>
</div>
</main>
@ -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');