diff --git a/apps/web/src/views/checkout.ejs b/apps/web/src/views/checkout.ejs index 39cf28b..6138e65 100644 --- a/apps/web/src/views/checkout.ejs +++ b/apps/web/src/views/checkout.ejs @@ -211,6 +211,8 @@ if (!res.ok) throw new Error(data.error || 'Checkout failed'); paymentId = data.id; + // Update URL so refreshing restores this invoice + history.replaceState(null, '', `/dashboard/checkout/${data.id}`); showPayment(data); } catch (err) { errEl.textContent = err.message; @@ -342,6 +344,27 @@ setTimeout(() => { btn.textContent = 'Copy'; btn.classList.remove('text-green-400'); }, 1500); } + // Auto-load existing invoice if arriving via /dashboard/checkout/:id + const PRELOAD_INVOICE_ID = <%~ JSON.stringify(it.invoiceId) %>; + if (PRELOAD_INVOICE_ID) { + (async () => { + try { + const res = await fetch(`${PAY_API}/checkout/${PRELOAD_INVOICE_ID}`, { credentials: 'include' }); + if (!res.ok) return; + const data = await res.json(); + if (data.status === 'paid') { + document.getElementById('step-select').classList.add('hidden'); + document.getElementById('step-pay').classList.remove('hidden'); + document.getElementById('pay-status-section').classList.add('hidden'); + document.getElementById('pay-success').classList.remove('hidden'); + } else if (data.status !== 'expired') { + paymentId = data.id; + showPayment(data); + } + } catch {} + })(); + } + function resetCheckout() { if (sseAbort) { sseAbort.abort(); sseAbort = null; } if (pollInterval) { clearInterval(pollInterval); pollInterval = null; }