fix: payment errors show in red, not in the green of a success
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 2m38s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 54s
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 2m38s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 54s
The payment page's one message line was always green, so "O Mercado Pago recusou o pagamento" looked like good news. Each message now has a tone: an error (a refusal, a form error, a missing field) in red, a changed cart or an expired quote in amber, a created order in green, the rest neutral. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,7 +50,10 @@
|
||||
window.dtfSessionReady=ready;
|
||||
window.dtfApi=api;
|
||||
ready.catch(error => { status.textContent = error.message; });
|
||||
function message(text) { status.textContent = text; }
|
||||
// One message line under the steps. Its tone says what it is: a refusal or
|
||||
// a missing field is an error (red), a cart that changed a warning, a
|
||||
// created order a confirmation, the rest information.
|
||||
function message(text, tone='info') { status.textContent = text; status.dataset.tone = text ? tone : ''; }
|
||||
function button(label, handler, into = actions, className = 'pagBtn') {
|
||||
const el = document.createElement('button');
|
||||
el.type = 'button';
|
||||
@@ -266,10 +269,10 @@
|
||||
if (draftId && quotedCart === cartSnapshot()) { await refresh(true); return; }
|
||||
if (draftId) clearDraft();
|
||||
if (!clienteOk() || !entrega.cotado) return;
|
||||
if (!enderecoOk()) return message('Preencha o endereço de entrega.');
|
||||
if (!cartPodeEnviar()) return message('Revise a qualidade e confirme a ressalva de cada item antes de enviar o pedido.');
|
||||
if (!enderecoOk()) return message('Preencha o endereço de entrega.','error');
|
||||
if (!cartPodeEnviar()) return message('Revise a qualidade e confirme a ressalva de cada item antes de enviar o pedido.','error');
|
||||
const cart = itensAPagar();
|
||||
if (!cart.length) return message('Adicione um item ao pedido.');
|
||||
if (!cart.length) return message('Adicione um item ao pedido.','error');
|
||||
const initialCart=cartSnapshot();
|
||||
busy = true;
|
||||
$('bPagar').disabled = true;
|
||||
@@ -308,7 +311,7 @@
|
||||
quotedCart=initialCart;localStorage.setItem('dtf-quote-cart',quotedCart);
|
||||
draftId=quote.id; localStorage.setItem('dtf-quote',draftId);
|
||||
await refresh(true);
|
||||
} catch(error) { message(error.message); }
|
||||
} catch(error) { message(error.message,'error'); }
|
||||
finally { busy=false; pintaEntrega(); }
|
||||
};
|
||||
// `go`: the customer asked to pay, so the cart page moves to the payment page.
|
||||
@@ -332,7 +335,7 @@
|
||||
if (quote.status==='paid') { confirmado(quote); return; }
|
||||
if (naPix() && quote.status!=='approved') { vaiPara(PAGAMENTO); return; }
|
||||
if (!quotedCart || quotedCart!==cartSnapshot()) {
|
||||
message('O carrinho mudou ou não está disponível neste navegador. A cotação anterior continua separada; envie o carrinho atual para uma nova revisão.');
|
||||
message('O carrinho mudou ou não está disponível neste navegador. A cotação anterior continua separada; envie o carrinho atual para uma nova revisão.','warn');
|
||||
button('Enviar carrinho atual',()=>{clearDraft();window.dtfCheckout();});
|
||||
return;
|
||||
}
|
||||
@@ -358,17 +361,17 @@
|
||||
try {
|
||||
const order=await api('/orders/dev-paid',{quote_id:draftId});
|
||||
await pagos();
|
||||
message('Pedido #'+order.number+' criado e disponível no Kanban.');
|
||||
message('Pedido #'+order.number+' criado e disponível no Kanban.','ok');
|
||||
await refresh();
|
||||
} catch(error) { message(error.message); event.target.disabled=false; }
|
||||
} catch(error) { message(error.message,'error'); event.target.disabled=false; }
|
||||
});
|
||||
} else {
|
||||
message('Cotação expirada. Envie o carrinho de novo para pagar.');
|
||||
message('Cotação expirada. Envie o carrinho de novo para pagar.','warn');
|
||||
button('Voltar ao carrinho',()=>{clearDraft();vaiPara(CARRINHO);});
|
||||
}
|
||||
} catch(error) {
|
||||
if(version!==refreshVersion || draftId!==shownId) return;
|
||||
message(error.message);
|
||||
message(error.message,'error');
|
||||
actions.replaceChildren();
|
||||
button('Limpar referência e tentar de novo',clearDraft);
|
||||
}
|
||||
@@ -389,7 +392,7 @@
|
||||
// Refused after the bank's confirmation or the provider's review.
|
||||
clearInterval(waitTimer);
|
||||
await refresh();
|
||||
message('Pagamento recusado. Tente de novo ou escolha outra forma de pagamento.');
|
||||
message('Pagamento recusado. Tente de novo ou escolha outra forma de pagamento.','error');
|
||||
}
|
||||
} catch(_) {}
|
||||
},3000);
|
||||
@@ -451,7 +454,7 @@
|
||||
try {
|
||||
await api('/payments/intent',{quote_id:draftId,method:{type:'pix'}});
|
||||
vaiPara(PAGAMENTO_PIX);
|
||||
} catch(error) { message(error.message); event.target.disabled=false; }
|
||||
} catch(error) { message(error.message,'error'); event.target.disabled=false; }
|
||||
},area);
|
||||
}
|
||||
await pinta();
|
||||
@@ -464,12 +467,12 @@
|
||||
try { intent=await api('/payments/intent',{quote_id:draftId,method:{type:'pix'}}); }
|
||||
catch(error) {
|
||||
if (version!==refreshVersion) return;
|
||||
message(error.message);
|
||||
message(error.message,'error');
|
||||
button('Escolher outra forma de pagamento',()=>vaiPara(PAGAMENTO),actions,'pagBtn sec');
|
||||
return;
|
||||
}
|
||||
if (version!==refreshVersion) return;
|
||||
if (!intent.pix_qr_code) { message('Não foi possível gerar o PIX. Tente de novo em instantes.'); return; }
|
||||
if (!intent.pix_qr_code) { message('Não foi possível gerar o PIX. Tente de novo em instantes.','error'); return; }
|
||||
const box=node('div',null,'pixBox');
|
||||
box.append(node('h4','Pague com PIX'),
|
||||
node('p','Abra o app do seu banco, escolha pagar com PIX e leia o QR code ou cole o código abaixo.','pagNota'));
|
||||
@@ -545,7 +548,7 @@
|
||||
const espera=node('div',null,'skel skelBloco');
|
||||
into.append(espera,holder);
|
||||
try { await loadMercadoPago(); }
|
||||
catch(error) { espera.remove(); message(error.message); return; }
|
||||
catch(error) { espera.remove(); message(error.message,'error'); return; }
|
||||
const session=await ready;
|
||||
// The customer may have switched to PIX, or the page re-rendered, meanwhile.
|
||||
if (!holder.isConnected || version!==refreshVersion) return;
|
||||
@@ -563,7 +566,7 @@
|
||||
style:{customVariables:{baseColor:'#FFA81A',buttonTextColor:'#03060B'}}}},
|
||||
callbacks:{
|
||||
onReady:()=>{ espera.remove(); },
|
||||
onError:error=>{ console.error(error); message('Erro no formulário do cartão. Confira os dados e tente de novo.'); },
|
||||
onError:error=>{ console.error(error); message('Erro no formulário do cartão. Confira os dados e tente de novo.','error'); },
|
||||
onSubmit:async data=>{
|
||||
if (!cartOk()) { await refresh(); throw new Error('cart changed'); }
|
||||
message('');
|
||||
@@ -576,7 +579,7 @@
|
||||
...cardholder(data.payer?.identification)}});
|
||||
} catch(error) {
|
||||
// Rejecting stops the form's spinner; the reason is shown above it.
|
||||
message(error.message || 'Não foi possível concluir o pagamento. Tente de novo.');
|
||||
message(error.message || 'Não foi possível concluir o pagamento. Tente de novo.','error');
|
||||
status.scrollIntoView({behavior:'smooth',block:'center'});
|
||||
throw error;
|
||||
}
|
||||
@@ -589,7 +592,7 @@
|
||||
waitForOrder();
|
||||
} else {
|
||||
message('Pagamento recusado pelo Mercado Pago ('+(result.status_detail||result.status)+'). '+
|
||||
'Confira os dados ou use outro cartão.');
|
||||
'Confira os dados ou use outro cartão.','error');
|
||||
throw new Error('rejected');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +332,11 @@ section+section{border-top:0}
|
||||
#bPagar:disabled{background:#EDEDED;color:#8A8D92}
|
||||
#bMais{height:46px;border-radius:var(--raio2);font-family:"Inter",sans-serif;font-weight:600}
|
||||
.checkout{max-width:760px;margin:20px auto 0}
|
||||
.checkout #checkoutStatus:not(:empty){padding:16px 18px;border-radius:var(--raio);background:var(--verde-fundo);border:1px solid #BFE6CE;color:#14532D;font-size:16.5px}
|
||||
.checkout #checkoutStatus:not(:empty){padding:16px 18px;border-radius:var(--raio);background:#F6F7F8;border:1px solid var(--linha);color:var(--texto2);font-size:16.5px}
|
||||
/* The message's tone (checkout.js): green only for what went right. */
|
||||
.checkout #checkoutStatus[data-tone=ok]{background:var(--verde-fundo);border-color:#BFE6CE;color:#14532D}
|
||||
.checkout #checkoutStatus[data-tone=warn]{background:var(--aviso-fundo);border-color:var(--aviso-linha);color:#5A3A00}
|
||||
.checkout #checkoutStatus[data-tone=error]{background:#FDECEA;border-color:#F3C2BC;color:#8C2416}
|
||||
#checkoutActions{margin-top:12px}
|
||||
/* Only our own fields: Mercado Pago's card form (its instalment radios) keeps its own styles. */
|
||||
#checkoutActions .pixBox input{height:44px;border-radius:var(--raio2);border:1px solid #D6D6D6;padding:0 12px}
|
||||
|
||||
Reference in New Issue
Block a user