From b50318ce3d9a59300192242c6b862fd9f3c73d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Tue, 1 Dec 2026 14:24:12 -0300 Subject: [PATCH] fix: the Site stops waiting for a payment's order once the page lets the quote go (DTF-WEB-29) waitForOrder polled /quotes/ every 3 s after a PIX or a card challenge; "Voltar ao carrinho" (an expired PIX) cleared draftId and the poll went on asking /quotes/null, which reached Sentry as a 422. The wait now keeps the quote it started for and stops when the page's quote changes or is gone, and each wait clears only its own timer. Co-Authored-By: Claude Opus 5.5 --- web/checkout.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/web/checkout.js b/web/checkout.js index c11cff8..dad5182 100644 --- a/web/checkout.js +++ b/web/checkout.js @@ -679,21 +679,31 @@ let waitTimer=null; function waitForOrder() { clearInterval(waitTimer); - waitTimer=setInterval(async()=>{ + // The quote it waits for. When the page lets it go ("Voltar ao carrinho" + // after an expired PIX, another cart), the wait stops: it asked for + // /quotes/null every 3 s (Sentry DTF-WEB-29). + const waited=draftId; + if (!waited) return; + // Each wait stops only its own timer: an answer still on its way when a + // new wait starts must not stop the new one. + const timer=setInterval(async()=>{ + if (draftId!==waited) { clearInterval(timer); return; } try { - const quote=await api('/quotes/'+draftId); + const quote=await api('/quotes/'+waited); + if (draftId!==waited) { clearInterval(timer); return; } if (quote.status==='paid') { - clearInterval(waitTimer); + clearInterval(timer); await pagos(); await refresh(); } else if (quote.payment?.status==='rejected') { // Refused after the bank's confirmation or the provider's review. - clearInterval(waitTimer); + clearInterval(timer); await refresh(); message(quote.payment.message||'O pagamento foi recusado. Tente de novo ou escolha outra forma de pagamento.','error'); } } catch(_) {} },3000); + waitTimer=timer; } // 3-D Secure: the bank's own page, opened by posting its request in a frame. function showChallenge(challenge, into) {