From fcdb88ae6c815409e50e30cb021c792c64478b14 Mon Sep 17 00:00:00 2001 From: Vitor Date: Tue, 16 Jun 2026 11:33:05 -0300 Subject: [PATCH] =?UTF-8?q?fix(mercadopago):=20Infere=20tipo=20do=20docume?= =?UTF-8?q?nto=20pelo=20n=C3=BAmero=20de=20d=C3=ADgitos,=20n=C3=A3o=20pelo?= =?UTF-8?q?=20cadastro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clientes PJ (registry_type 'j') podem pagar com cartão pessoal (CPF) e clientes PF podem usar cartão corporativo (CNPJ). O tipo enviado ao Mercado Pago agora é derivado da contagem de dígitos do documento (11 = CPF, 14 = CNPJ) em vez do registry_type do cadastro, tanto na tokenização client-side quanto na criação da transação server-side. --- packages/apps/mercadopago/assets/onload-expression.js | 9 +++++++-- packages/apps/mercadopago/src/mp-create-transaction.ts | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/apps/mercadopago/assets/onload-expression.js b/packages/apps/mercadopago/assets/onload-expression.js index 1a1ddda39..64b4fd175 100644 --- a/packages/apps/mercadopago/assets/onload-expression.js +++ b/packages/apps/mercadopago/assets/onload-expression.js @@ -4,6 +4,9 @@ window._mpHash = function (data) { return new Promise((resolve, reject) => { + if (data.doc) { + data = Object.assign({}, data, { doc: data.doc.replace(/\D/g, '') }); + } window ._mpBrand(data.number) .then(() => { @@ -122,8 +125,10 @@ const $typeDoc = document.createElement('select'); $typeDoc.setAttribute('data-checkout', 'docType'); const $typeDocOption = document.createElement('option'); - $typeDocOption.text = customer.registry_type === 'j' ? 'CNPJ' : 'CPF'; - $typeDocOption.value = customer.registry_type === 'j' ? 'CNPJ' : 'CPF'; + const _docNum = (mpParams.docNumber || '').replace(/\D/g, ''); + const _docType = _docNum.length === 14 ? 'CNPJ' : 'CPF'; + $typeDocOption.text = _docType; + $typeDocOption.value = _docType; $typeDocOption.setAttribute('selected', true); $typeDoc.add($typeDocOption); diff --git a/packages/apps/mercadopago/src/mp-create-transaction.ts b/packages/apps/mercadopago/src/mp-create-transaction.ts index 775bdf10e..92d4263e9 100644 --- a/packages/apps/mercadopago/src/mp-create-transaction.ts +++ b/packages/apps/mercadopago/src/mp-create-transaction.ts @@ -159,7 +159,7 @@ export default async (appData: AppModuleBody) => { first_name: payerOrBuyer.fullname.replace(/\s.*/, ''), last_name: payerOrBuyer.fullname.replace(/[^\s]+\s/, ''), identification: { - type: payerOrBuyer.registry_type === 'j' ? 'CNPJ' : 'CPF', + type: String(payerOrBuyer.doc_number).replace(/\D/g, '').length === 14 ? 'CNPJ' : 'CPF', number: String(payerOrBuyer.doc_number), }, },