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) {