From ca1ba677ce9cf9f5c145f56f29521e4194c6de31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Tue, 1 Dec 2026 09:40:03 -0300 Subject: [PATCH] fix: a Site payment lands in Tiny's MERCADO PAGO account, and card uses the forma de recebimento Marcus gave (2026-12-01) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pix and card paid on the Site carry meioPagamento 977344550 on their installment; an order the team registered as paid outside, the customer's credit and the boleto keep theirs. Cartão de crédito is 919478945 (the 977460722 read from a store order on 19/10 was not it). Co-Authored-By: Claude Opus 5.5 --- app/tiny.py | 13 ++++++++++++- tests/test_tiny.py | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/tiny.py b/app/tiny.py index 550f8b3..c6b9ea2 100644 --- a/app/tiny.py +++ b/app/tiny.py @@ -144,9 +144,16 @@ PICKUP_EXACT = 'retirar pessoalmente' # "CORREÇÃO DTF", used for it before, is for correction orders only. "Boleto" is # for a montador Venda order (front 7a.3); no id is known yet, and while # TINY_RECEIPT_BOLETO is empty the order goes without a forma de recebimento. +# Cartão de crédito is 919478945 (Marcus, 2026-12-01; 977460722, read from a +# store order on 2026-10-19, was not the forma he names). _BOLETO = os.environ.get('TINY_RECEIPT_BOLETO', '').strip() -RECEIPT_METHODS = {'pix': 919478952, 'card': 977460722, 'cash': 919478944, 'credit': 987762591, +RECEIPT_METHODS = {'pix': 919478952, 'card': 919478945, 'cash': 919478944, 'credit': 987762591, **({'faturado': int(_BOLETO)} if _BOLETO.isdigit() else {})} +# The account ("meio de pagamento") a Site payment lands in: MERCADO PAGO, the +# one the store's orders use (Marcus, 2026-12-01; not "MERCADO PAGO - NÃO +# USAR", 987326894). Only Pix and card paid on the Site, through Mercado Pago. +MERCADO_PAGO_ACCOUNT = 977344550 +SITE_PAID = ('pix', 'card') PICKUP_CARRIER = 761565838 # Dropstar's answers: the financial category "DTF SITE" (RECEITAS, id sent on # 2026-10-26; it goes in pagamento.categoria, and replaced the store's @@ -665,6 +672,10 @@ def order_payload(payload, contact_id, today=None, product_id=None, shipping=Non account = setting('TINY_BOLETO_ACCOUNT') if method == 'faturado' and account.isdigit(): parcela['meioPagamento'] = {'id': int(account)} + # Paid on the Site: the money is in the Mercado Pago account. An order + # the team registered as paid outside (D-35) names no account. + elif method in SITE_PAID and not (payload.get('payment') or {}).get('outside'): + parcela['meioPagamento'] = {'id': MERCADO_PAGO_ACCOUNT} pedido['pagamento'].update({'formaRecebimento': {'id': received}, 'parcelas': [parcela]}) destination = order.get('destination') if destination: diff --git a/tests/test_tiny.py b/tests/test_tiny.py index 8e1e896..30235eb 100644 --- a/tests/test_tiny.py +++ b/tests/test_tiny.py @@ -215,10 +215,11 @@ class TinyTests(FakeTinyCase): mock.patch.dict(tiny_module.RECEIPT_METHODS, {'faturado': 919478947}): pedido = order_payload({**PAID, 'payment': {'method': 'faturado'}}, 777, date(2026, 9, 24)) self.assertNotIn('meioPagamento', pedido['pagamento']['parcelas'][0]) - # A pix order never gets the boleto account. + # A pix order never gets the boleto account: paid on the Site, it is + # the MERCADO PAGO one (Marcus, 2026-12-01). with mock.patch.dict(os.environ, {'TINY_BOLETO_ACCOUNT': '977344551'}): pedido = order_payload({**PAID, 'payment': {'method': 'pix'}}, 777, date(2026, 9, 24)) - self.assertNotIn('meioPagamento', pedido['pagamento']['parcelas'][0]) + self.assertEqual(pedido['pagamento']['parcelas'][0]['meioPagamento'], {'id': 977344550}) def test_the_check_lists_ajuste_fino_by_its_sku(self): from app.tiny import check @@ -480,8 +481,13 @@ class TinyStatusTests(FakeTinyCase): self.assertEqual(pickup['transportador'], {'fretePorConta': 'R', 'id': PICKUP_CARRIER, 'formaEnvio': {'id': 77}, 'formaFrete': {'id': 771}}) self.assertEqual(pickup['dataPrevista'], '2026-09-25') + # Paid on the Site: the parcel lands in the MERCADO PAGO account (Marcus, 2026-12-01). self.assertEqual(pickup['pagamento'], {'categoria': {'id': CATEGORY}, 'formaRecebimento': {'id': RECEIPT_METHODS['pix']}, - 'parcelas': [{'dias': 0, 'data': '2026-09-24', 'valor': 84.72, 'formaRecebimento': {'id': RECEIPT_METHODS['pix']}}]}) + 'parcelas': [{'dias': 0, 'data': '2026-09-24', 'valor': 84.72, 'formaRecebimento': {'id': RECEIPT_METHODS['pix']}, + 'meioPagamento': {'id': 977344550}}]}) + # The forma de recebimento ids Marcus listed on 2026-12-01. + self.assertEqual((RECEIPT_METHODS['pix'], RECEIPT_METHODS['card'], RECEIPT_METHODS['credit']), + (919478952, 919478945, 987762591)) # Delivery: the Correios contract's PAC or SEDEX, or Jadlog; the date in working days. for service, method, frete in (('pac', 78, 781), ('sedex', 78, 782), ('jadlog', 80, 801)): order = {**PAID['order'], 'freight': {'service': service, 'total_cents': 1500, 'days': 6}} @@ -491,6 +497,7 @@ class TinyStatusTests(FakeTinyCase): 'formaFrete': {'id': frete}}, service) self.assertEqual(sent['dataPrevista'], '2026-10-02') self.assertEqual(sent['pagamento']['formaRecebimento'], {'id': RECEIPT_METHODS['card']}) + self.assertEqual(sent['pagamento']['parcelas'][0]['meioPagamento'], {'id': 977344550}) # Looked up once per service. self.assertEqual(self.calls.count(('GET', '/formas-envio/78')), 2) # A test order, or a carrier Tiny does not have: the order still goes, without them, @@ -511,6 +518,9 @@ class TinyStatusTests(FakeTinyCase): 1, thursday, shipping=self.tiny.shipping) self.assertEqual(pix['pagamento']['formaRecebimento'], {'id': RECEIPT_METHODS['pix']}) self.assertEqual(pix['pagamento']['categoria'], {'id': CATEGORY}) + # Paid outside the site: not through Mercado Pago, so no account. + self.assertNotIn('meioPagamento', pix['pagamento']['parcelas'][0]) + self.assertNotIn('meioPagamento', counter['pagamento']['parcelas'][0]) # Dinheiro (Marcus, 2026-10-27) and the customer's credit, CREDITO # PRE-PAGO (Marcus, 2026-11-18; no longer CORREÇÃO DTF). self.assertEqual((RECEIPT_METHODS['cash'], RECEIPT_METHODS['credit']), (919478944, 987762591))