From 8b5aafa2994b9ae1c6c755f91ec17d809b26e79b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Tue, 29 Sep 2026 13:37:16 -0300 Subject: [PATCH] fix: let Mercado Pago take the card issuer from the card number 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 --- app/mercadopago.py | 5 +++-- tests/test_mercadopago.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/mercadopago.py b/app/mercadopago.py index 15b46a7..0bfb84a 100644 --- a/app/mercadopago.py +++ b/app/mercadopago.py @@ -85,8 +85,9 @@ class MercadoPagoPayment: body.update(token=method['token'], payment_method_id=method['payment_method_id'], installments=int(method.get('installments', 1)), three_d_secure_mode='optional') - if method.get('issuer_id'): - body['issuer_id'] = method['issuer_id'] + # No issuer_id: Mercado Pago takes the issuer from the card number. + # The form's suggestion was refused for its own test cards + # (10111, "the issuer does not have the BIN configured"). else: raise ValueError('Unsupported payment method') # A PIX retry must return the same code; a new one, after the last diff --git a/tests/test_mercadopago.py b/tests/test_mercadopago.py index 5f749f6..bb4854f 100644 --- a/tests/test_mercadopago.py +++ b/tests/test_mercadopago.py @@ -140,6 +140,9 @@ class MercadoPagoTests(unittest.TestCase): self.assertNotEqual(self.requests[-1].headers['x-idempotency-key'], first_key) self.assertTrue(first_key.startswith('dtf-quote-q-card-')) 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'}, {'type': 'card', 'token': 'tok_ghi', 'payment_method_id': 'visa'})['challenge'])