fix: the Mercado Pago payer is the order's customer, with document and name, for PIX and card (checkout item 2)
All checks were successful
Build and deploy / Validate source (push) Successful in 1m42s
Build and deploy / Integration suite on a real stack (push) Successful in 8m39s
Build and deploy / Secret scan and release gate (push) Successful in 12s
Build and deploy / Publish images (push) Successful in 2m12s

Marcus, 2026-11-18: finance reconciles the payment by the customer and
the invoice is issued to them; half the payments showed 999.999.999-99
and no name. The payer now always carries the order's CPF or CNPJ, the
first and last name from the order and the e-mail. The card form's
document is no longer sent by the Site nor used (the cardholder's data
travel in the card token); the field stays accepted for pages loaded
before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-23 10:33:29 -03:00
parent 177694edd3
commit 65f8dd211e
4 changed files with 35 additions and 21 deletions

View File

@@ -137,6 +137,11 @@ class MercadoPagoTests(unittest.TestCase):
self.mp.create('22222222-2222-3333-4444-555555555555', 1000, {'mail': 'a@example.test', 'cnpj': '52998224725'})
person = json.loads(self.requests[-1].content)
self.assertEqual(person['payer']['identification'], {'type': 'CPF', 'number': '52998224725'})
# A one-word name is both first and last name.
self.mp.create('33333333-2222-3333-4444-555555555555', 1000,
{'mail': 'a@example.test', 'cnpj': '52998224725', 'name': 'Kenia'})
self.assertEqual({k: v for k, v in json.loads(self.requests[-1].content)['payer'].items() if 'name' in k},
{'first_name': 'Kenia', 'last_name': 'Kenia'})
self.assertEqual((created['pix_qr_code'], created['status']), ('000201PIX', 'pending'))
# The code expires in 30 minutes, in the format Mercado Pago documents.
expires = datetime.fromisoformat(body['date_of_expiration'])
@@ -161,15 +166,20 @@ 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 cardholder is the payer.
# 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.
self.assertNotIn('three_d_secure_mode', body)
self.mp.create('q', 1000, {'mail': 'a@example.test', 'cnpj': '11222333000181'},
self.mp.create('q', 1000, {'mail': 'a@example.test', 'cnpj': '11222333000181', 'name': 'Maria da Silva'},
{'type': 'card', 'token': 'tok_deb', 'payment_method_id': 'debmaster',
'payer_document_type': 'CPF', 'payer_document': '12345678909'})
'payer_document_type': 'CPF', 'payer_document': '99999999999'})
debit = json.loads(self.requests[-1].content)
self.assertEqual(debit['three_d_secure_mode'], 'optional')
self.assertEqual(debit['payer']['identification'], {'type': 'CPF', 'number': '12345678909'})
self.assertEqual(debit['payer'], {'email': 'a@example.test', 'first_name': 'Maria', 'last_name': 'da Silva',
'identification': {'type': 'CNPJ', 'number': '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'])
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))