feat: update URL to /checkout/:id after creation, auto-load existing invoice on load
This commit is contained in:
parent
63c7d7c1d7
commit
b46c3c618e
|
|
@ -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; }
|
||||
|
|
|
|||
Loading…
Reference in New Issue