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

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:
Cauê Faleiros
2026-11-23 11:46:28 -03:00
parent 65f8dd211e
commit 6e05dd93c2
4 changed files with 48 additions and 16 deletions

View File

@@ -166,9 +166,10 @@ class MercadoPagoTests(unittest.TestCase):
{'type': 'card', 'token': 'tok_def', 'payment_method_id': 'visa'})
self.assertNotEqual(self.requests[-1].headers['x-idempotency-key'], first_key)
self.assertTrue(first_key.startswith('dtf-quote-q-card-'))
# 3-D Secure is asked of debit only. The payer is the order's customer,
# never the card form's document (Marcus, 2026-11-18): finance
# reconciles by it and the invoice is issued to it.
# 3-D Secure is asked of debit only. The payer is a real document
# (Marcus, 2026-11-18): a placeholder from the card form (999...) gives
# way to the order's, with the order's name; the order's document is
# always kept in the metadata for finance.
self.assertNotIn('three_d_secure_mode', body)
self.mp.create('q', 1000, {'mail': 'a@example.test', 'cnpj': '11222333000181', 'name': 'Maria da Silva'},
{'type': 'card', 'token': 'tok_deb', 'payment_method_id': 'debmaster',
@@ -177,9 +178,18 @@ class MercadoPagoTests(unittest.TestCase):
self.assertEqual(debit['three_d_secure_mode'], 'optional')
self.assertEqual(debit['payer'], {'email': 'a@example.test', 'first_name': 'Maria', 'last_name': 'da Silva',
'identification': {'type': 'CNPJ', 'number': '11222333000181'}})
self.assertEqual(debit['metadata'], {'documento_pedido': '11222333000181'})
self.assertEqual(body['payer']['identification'], {'type': 'CNPJ', 'number': '11222333000181'})
# An order from before the Site asked the name sends none.
self.assertNotIn('first_name', body['payer'])
# A valid document typed in the card form (someone else's card) is the
# payer, as the card token says; the order's stays in the metadata.
self.mp.create('q', 1000, {'mail': 'a@example.test', 'cnpj': '11222333000181', 'name': 'Maria da Silva'},
{'type': 'card', 'token': 'tok_other', 'payment_method_id': 'visa',
'payer_document_type': 'CPF', 'payer_document': '52998224725'})
other = json.loads(self.requests[-1].content)
self.assertEqual(other['payer']['identification'], {'type': 'CPF', 'number': '52998224725'})
self.assertEqual(other['metadata'], {'documento_pedido': '11222333000181'})
self.mp.create('q', 1000, {'mail': 'a@example.test', 'cnpj': '11222333000181'},
{'type': 'card', 'token': 'tok_iss', 'payment_method_id': 'master', 'issuer_id': '24'})
self.assertNotIn('issuer_id', json.loads(self.requests[-1].content))