feat: a refused payment says what happened and what to do, in plain Portuguese
All checks were successful
Build and deploy / Validate source (push) Successful in 1m22s
Build and deploy / Integration suite on a real stack (push) Successful in 4m10s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 1m11s

A refused card showed Mercado Pago's code ("Pagamento recusado pelo Mercado
Pago (cc_rejected_insufficient_amount)"), a request it refused showed its
cause list, and some errors were in English ("Quote is already paid",
"Payment provider unavailable; try again"). Each now becomes one sentence:
"O cartão não tem limite suficiente para este valor. Use outro cartão ou
pague com PIX." The codes still go to the log and, on the Kanban's "Cartão
recusado" badge, beside the same sentence. A form check the customer cannot
read is replaced by a general one, and every error a customer or operator
can meet in the quote, upload, account and artwork routes is in Portuguese.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-06 15:54:14 -03:00
parent 172544b173
commit 959ed37b15
12 changed files with 190 additions and 47 deletions

View File

@@ -40,9 +40,18 @@
let data;
try { data = text ? JSON.parse(text) : {}; }
catch (_) { throw new Error(response.ok ? 'Resposta inválida do serviço.' : 'O serviço está indisponível. Tente novamente em instantes.'); }
if (!response.ok) { const error=new Error(typeof data.detail === 'string' ? data.detail : 'Confira os dados do pedido ('+response.status+').');error.status=response.status;throw error; }
if (!response.ok) { const error=new Error(problem(data.detail));error.status=response.status;throw error; }
return data;
};
// A refusal as one sentence: the server's own, or the first field a form
// check named, never a status code.
function problem(detail){
if (typeof detail === 'string') return detail;
// Only the checks written for customers speak Portuguese ("Value error, …").
const ours=Array.isArray(detail)&&detail.find(d=>typeof d?.msg==='string'&&d.msg.startsWith('Value error, '));
if (ours) return ours.msg.slice('Value error, '.length);
return 'Não foi possível concluir. Confira os dados e tente de novo.';
}
const ready = api('/session');
ready.then(session=>{
window.dtfUploadMaxBytes=session.max_upload_bytes;
@@ -400,7 +409,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.','error');
message(quote.payment.message||'O pagamento foi recusado. Tente de novo ou escolha outra forma de pagamento.','error');
}
} catch(_) {}
},3000);
@@ -598,8 +607,7 @@
: 'Pagamento em análise pelo Mercado Pago. Esta página atualiza assim que ele for confirmado.','pagNota'));
waitForOrder();
} else {
message('Pagamento recusado pelo Mercado Pago ('+(result.status_detail||result.status)+'). '+
'Confira os dados ou use outro cartão.','error');
message(result.message||'O pagamento foi recusado. Confira os dados ou use outro cartão ou pague com PIX.','error');
throw new Error('rejected');
}
}

View File

@@ -150,7 +150,7 @@ function paymentBadge(p){
:badge('! PIX expirou sem pagamento','warn','O código venceu e o cliente ainda pode gerar outro'+tried);
}
if(p.status==='approved')return badge('✓ Cartão aprovado','ok');
if(p.status==='rejected')return badge('! Cartão recusado','bad',(p.status_detail?'Motivo: '+p.status_detail:'Recusado')+tried);
if(p.status==='rejected')return badge('! Cartão recusado','bad',(p.message||'Recusado')+(p.status_detail?' ('+p.status_detail+')':'')+tried);
if(p.status==='pending')return badge(p.status_detail==='pending_challenge'?'Cartão aguardando o banco':'Cartão em análise','info',tried.slice(3));
return badge('Pagamento '+p.status,'',tried.slice(3));
}