fix: the card form opens with the order's document, so the card token and the Mercado Pago payer agree
Some checks failed
Build and deploy / Validate source (push) Successful in 15s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Some checks failed
Build and deploy / Validate source (push) Successful in 15s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
65f8dd2 made the order's document the payer of every card payment, which
could differ from the document inside the card token and raise refusals.
The card form now opens with the order's CPF or CNPJ (Card Payment Brick
initialization.payer.identification), so both carry it. A valid document
the customer types there instead (someone else's card) is the payer, as
the token says; a placeholder such as 999.999.999-99, or none, gives way
to the order's. The order's document always rides in the payment's
metadata for finance, and the order's name goes as first and last name.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -784,6 +784,14 @@
|
||||
});
|
||||
return sdkLoading;
|
||||
}
|
||||
// The document in the card form, which opens with the order's; the server
|
||||
// keeps the order's when this one is not a valid CPF or CNPJ.
|
||||
function cardholder(id) {
|
||||
const number=String(id?.number||'').replace(/\D/g,'');
|
||||
const type=String(id?.type||'').toUpperCase();
|
||||
return ['CPF','CNPJ'].includes(type) && /^[0-9]{11,14}$/.test(number)
|
||||
? {payer_document_type:type, payer_document:number} : {};
|
||||
}
|
||||
// Each mount of the card form has its own number and its own holder. One
|
||||
// still mounting when the customer switched to PIX, or the page re-rendered,
|
||||
// is stale: Mercado Pago no longer finds its fields, so its callbacks are
|
||||
@@ -809,7 +817,10 @@
|
||||
let brick;
|
||||
try {
|
||||
brick=await mp.bricks().create('cardPayment',holder.id,{
|
||||
initialization:{amount:approved.total_cents/100, payer:{email:approved.customer.mail}},
|
||||
// The order's document already in the card form (Marcus, 2026-11-18):
|
||||
// the card token and the payer agree, and finance reconciles by it.
|
||||
initialization:{amount:approved.total_cents/100, payer:{email:approved.customer.mail,
|
||||
identification:{type:approved.customer.cnpj.length===11?'CPF':'CNPJ', number:approved.customer.cnpj}}},
|
||||
// Credit cards only, in up to 3 installments, as Dropstar decided.
|
||||
customization:{paymentMethods:{maxInstallments:3,types:{excluded:['debit_card']}},
|
||||
// The option above already names the card; the form's own title
|
||||
@@ -827,7 +838,8 @@
|
||||
result=await api('/payments/intent',{quote_id:draftId,method:{
|
||||
type:'card', token:data.token, payment_method_id:data.payment_method_id,
|
||||
installments:Number(data.installments)||1,
|
||||
issuer_id:data.issuer_id==null?null:String(data.issuer_id)}});
|
||||
issuer_id:data.issuer_id==null?null:String(data.issuer_id),
|
||||
...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.','error');
|
||||
|
||||
Reference in New Issue
Block a user