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), }, },