fix: let Mercado Pago take the card issuer from the card number
All checks were successful
Build and deploy / Validate source (push) Successful in 4s
Build and deploy / Integration suite on a real stack (push) Successful in 2m9s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 50s

Paying with Mercado Pago's own test card failed with 10111 ("the issuer
does not have the BIN configured"): the issuer_id suggested by the card
form did not match the card. issuer_id is optional, and without it Mercado
Pago resolves the issuer from the BIN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-09-29 13:37:16 -03:00
parent e47f88a6d6
commit 8b5aafa299
2 changed files with 6 additions and 2 deletions

View File

@@ -85,8 +85,9 @@ class MercadoPagoPayment:
body.update(token=method['token'], payment_method_id=method['payment_method_id'], body.update(token=method['token'], payment_method_id=method['payment_method_id'],
installments=int(method.get('installments', 1)), installments=int(method.get('installments', 1)),
three_d_secure_mode='optional') three_d_secure_mode='optional')
if method.get('issuer_id'): # No issuer_id: Mercado Pago takes the issuer from the card number.
body['issuer_id'] = method['issuer_id'] # The form's suggestion was refused for its own test cards
# (10111, "the issuer does not have the BIN configured").
else: else:
raise ValueError('Unsupported payment method') raise ValueError('Unsupported payment method')
# A PIX retry must return the same code; a new one, after the last # A PIX retry must return the same code; a new one, after the last

View File

@@ -140,6 +140,9 @@ class MercadoPagoTests(unittest.TestCase):
self.assertNotEqual(self.requests[-1].headers['x-idempotency-key'], first_key) self.assertNotEqual(self.requests[-1].headers['x-idempotency-key'], first_key)
self.assertTrue(first_key.startswith('dtf-quote-q-card-')) self.assertTrue(first_key.startswith('dtf-quote-q-card-'))
self.assertEqual(body['three_d_secure_mode'], 'optional') self.assertEqual(body['three_d_secure_mode'], 'optional')
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))
self.assertIsNone(self.mp.create('q', 1000, {'mail': 'a@example.test', 'cnpj': '11222333000181'}, self.assertIsNone(self.mp.create('q', 1000, {'mail': 'a@example.test', 'cnpj': '11222333000181'},
{'type': 'card', 'token': 'tok_ghi', 'payment_method_id': 'visa'})['challenge']) {'type': 'card', 'token': 'tok_ghi', 'payment_method_id': 'visa'})['challenge'])