From bc1fb604681d07938fc6c6ee7120ef77e6055501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Fri, 2 Oct 2026 17:02:35 -0300 Subject: [PATCH] fix: a new cart goes to payment instead of showing the last order already paid After a payment the browser kept the paid quote as its draft, so a cart identical to it (the same test repeated) opened the old "Pagamento confirmado" instead of a payment. The confirmation now forgets the draft, and a draft found already paid when the customer asks to pay starts a new order. Co-Authored-By: Claude Opus 5.5 --- web/checkout.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/web/checkout.js b/web/checkout.js index ba57974..293348f 100644 --- a/web/checkout.js +++ b/web/checkout.js @@ -23,12 +23,14 @@ files:(item.localFiles||[]).map(file=>({name:file.name,size:file.size,lastModified:file.lastModified})) }))}); } - function clearDraft() { + // The quote this browser is paying, forgotten. clearDraft also empties the + // payment area; forgetDraft leaves on screen what is there (a confirmation). + function forgetDraft() { draftId=null;quotedCart=null;requestKey=null;requestBody=null; for(const key of ['dtf-quote','dtf-quote-cart','dtf-request-key','dtf-request-body']) localStorage.removeItem(key); - actions.replaceChildren(); } + function clearDraft() { forgetDraft(); actions.replaceChildren(); } const api = async (path, body) => { const response = await fetch('/api'+path, { credentials: 'same-origin', headers: {'Content-Type':'application/json'}, @@ -324,6 +326,8 @@ await ready; const quote=await api('/quotes/'+shownId); if(version!==refreshVersion || draftId!==shownId) return; + // Asked to pay a cart identical to one already paid: that is a new order. + if (go && quote.status==='paid') { forgetDraft(); return window.dtfCheckout(); } if (!naPagina()) { message(''); vaiPara(PAGAMENTO); return; } shownCart=cartSnapshot(); clearInterval(pixClock); @@ -415,6 +419,9 @@ } function confirmado(quote) { clearInterval(waitTimer); + // Paid: the next cart is a new order, even one identical to this (the same + // test repeated), never this quote shown again as already paid. + forgetDraft(); const box=node('div',null,'confirmado'); const titulo=node('h4','Pagamento confirmado'); titulo.insertAdjacentHTML('afterbegin', icone('okCirculo'));