diff --git a/modules/rcart/mod.ts b/modules/rcart/mod.ts index 08bc880..6467fa5 100644 --- a/modules/rcart/mod.ts +++ b/modules/rcart/mod.ts @@ -2535,6 +2535,49 @@ routes.get("/request", (c) => { routes.get("/pay/:id", (c) => { const space = c.req.param("space") || "demo"; const paymentId = c.req.param("id"); + + // Check payment status server-side for graceful terminal-state messages + const docId = paymentRequestDocId(space, paymentId); + const doc = _syncServer?.getDoc(docId); + if (doc) { + const p = doc.payment; + const terminalStates: Record = { + paid: { title: 'Payment Complete', msg: 'This payment request has already been paid.', icon: '✓' }, + confirmed: { title: 'Payment Confirmed', msg: 'This payment has been confirmed on-chain.', icon: '✓' }, + expired: { title: 'Payment Expired', msg: 'This payment request has expired and is no longer accepting payments.', icon: '⏲' }, + cancelled: { title: 'Payment Cancelled', msg: 'This payment request has been cancelled by the creator.', icon: '✗' }, + filled: { title: 'Payment Limit Reached', msg: 'This payment request has reached its maximum number of payments.', icon: '✓' }, + }; + const info = terminalStates[p.status]; + if (info) { + const chainNames: Record = { 8453: 'Base', 84532: 'Base Sepolia', 1: 'Ethereum' }; + const explorerBase: Record = { 8453: 'https://basescan.org/tx/', 84532: 'https://sepolia.basescan.org/tx/', 1: 'https://etherscan.io/tx/' }; + const txLink = p.txHash && explorerBase[p.chainId] + ? `${p.txHash.slice(0, 10)}...${p.txHash.slice(-8)}` + : ''; + return c.html(renderShell({ + title: `${info.title} | rCart`, + moduleId: "rcart", + spaceSlug: space, + spaceVisibility: "public", + modules: getModuleInfoList(), + theme: "dark", + body: ` +
+
${info.icon}
+

${info.title}

+

${info.msg}

+ ${p.amount && p.amount !== '0' ? `
${p.amount} ${p.token}
` : ''} + ${p.fiatAmount ? `
≈ $${p.fiatAmount} ${p.fiatCurrency || 'USD'}
` : ''} + ${chainNames[p.chainId] ? `
Network: ${chainNames[p.chainId]}
` : ''} + ${txLink ? `
Tx: ${txLink}
` : ''} + ${p.paidAt ? `
Paid: ${new Date(p.paidAt).toLocaleString()}
` : ''} +
`, + styles: ``, + })); + } + } + return c.html(renderShell({ title: `Payment | rCart`, moduleId: "rcart",