add receipt
This commit is contained in:
parent
598cb49b61
commit
dd087d8826
@ -69,13 +69,17 @@ app.post('/api/checkout', async (request, reply) => {
|
|||||||
|
|
||||||
// ── Vérification session ──────────────────────────────────────────────────────
|
// ── Vérification session ──────────────────────────────────────────────────────
|
||||||
app.get('/api/session/:id', async (request) => {
|
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 {
|
return {
|
||||||
status: session.payment_status,
|
status: session.payment_status,
|
||||||
amount: session.amount_total,
|
amount: session.amount_total,
|
||||||
currency: session.currency,
|
currency: session.currency,
|
||||||
customer_email: session.customer_details?.email ?? null,
|
customer_email: session.customer_details?.email ?? null,
|
||||||
product: session.metadata?.product ?? null,
|
product: session.metadata?.product ?? null,
|
||||||
|
receipt_url: charge?.receipt_url ?? null,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -125,7 +125,10 @@ import Base from '../layouts/Base.astro';
|
|||||||
Un email de confirmation vous sera envoyé.<br>
|
Un email de confirmation vous sera envoyé.<br>
|
||||||
Votre lampe est fabriquée à la main à Paris.
|
Votre lampe est fabriquée à la main à Paris.
|
||||||
</p>
|
</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>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
@ -152,7 +155,7 @@ import Base from '../layouts/Base.astro';
|
|||||||
if (sessionId) {
|
if (sessionId) {
|
||||||
fetch(`/api/session/${sessionId}`)
|
fetch(`/api/session/${sessionId}`)
|
||||||
.then(r => r.json())
|
.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 loading = document.getElementById('loading');
|
||||||
const orderDetails = document.getElementById('order-details');
|
const orderDetails = document.getElementById('order-details');
|
||||||
if (loading) loading.style.display = 'none';
|
if (loading) loading.style.display = 'none';
|
||||||
@ -168,6 +171,11 @@ import Base from '../layouts/Base.astro';
|
|||||||
const img = document.getElementById('product-img') as HTMLImageElement;
|
const img = document.getElementById('product-img') as HTMLImageElement;
|
||||||
if (img) img.src = PRODUCT_IMAGES[data.product]!;
|
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(() => {
|
.catch(() => {
|
||||||
const loading = document.getElementById('loading');
|
const loading = document.getElementById('loading');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user