fix: the Mercado Pago script is tried twice, and a card form the customer left for PIX shows no error (DTF-WEB-1S)
All checks were successful
Build and deploy / Validate source (push) Successful in 12s
Build and deploy / Integration suite on a real stack (push) Successful in 8m14s
Build and deploy / Secret scan and release gate (push) Successful in 16s
Build and deploy / Publish images (push) Successful in 1m28s
All checks were successful
Build and deploy / Validate source (push) Successful in 12s
Build and deploy / Integration suite on a real stack (push) Successful in 8m14s
Build and deploy / Secret scan and release gate (push) Successful in 16s
Build and deploy / Publish images (push) Successful in 1m28s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -777,16 +777,23 @@
|
||||
// Card: Mercado Pago's own form (Card Payment Brick). The card is typed into
|
||||
// Mercado Pago's secure fields and becomes a one-time token; the number never
|
||||
// reaches this page's code or our server.
|
||||
// A script that failed (a phone's network blinking, Sentry DTF-WEB-1S) is
|
||||
// tried once more before the customer reads that it did not load.
|
||||
let sdkLoading=null;
|
||||
function loadMercadoPago() {
|
||||
if (window.MercadoPago) return Promise.resolve();
|
||||
sdkLoading = sdkLoading || new Promise((resolve,reject)=>{
|
||||
function sdkScript() {
|
||||
return new Promise((resolve,reject)=>{
|
||||
const script=document.createElement('script');
|
||||
script.src='https://sdk.mercadopago.com/js/v2';
|
||||
script.onload=resolve;
|
||||
script.onerror=()=>{sdkLoading=null;reject(new Error('Não foi possível carregar o formulário do Mercado Pago.'));};
|
||||
script.onerror=()=>{script.remove();reject(new Error('Não foi possível carregar o formulário do Mercado Pago.'));};
|
||||
document.head.append(script);
|
||||
});
|
||||
}
|
||||
function loadMercadoPago() {
|
||||
if (window.MercadoPago) return Promise.resolve();
|
||||
sdkLoading = sdkLoading || sdkScript()
|
||||
.catch(()=>new Promise(r=>setTimeout(r,2000)).then(sdkScript))
|
||||
.catch(error=>{sdkLoading=null;throw error;});
|
||||
return sdkLoading;
|
||||
}
|
||||
// The document in the card form, which opens with the order's; the server
|
||||
@@ -815,7 +822,8 @@
|
||||
const espera=node('div',null,'skel skelBloco');
|
||||
into.append(espera,holder);
|
||||
try { await loadMercadoPago(); }
|
||||
catch(error) { espera.remove(); message(error.message,'error'); return; }
|
||||
// The customer may be on PIX by now: a card form no one waits for says nothing.
|
||||
catch(error) { espera.remove(); if (live()) message(error.message,'error'); return; }
|
||||
const session=await ready;
|
||||
if (!live()) return;
|
||||
const mp=new window.MercadoPago(session.payment_public_key,{locale:'pt-BR'});
|
||||
|
||||
Reference in New Issue
Block a user