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
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:
@@ -413,9 +413,8 @@ class PaymentMethod(StrictModel):
|
||||
# Up to 3, as Dropstar sells; the card form offers no more.
|
||||
installments: int = Field(default=1, ge=1, le=3, strict=True)
|
||||
issuer_id: str | None = Field(default=None, max_length=40)
|
||||
# The card form's document. No longer sent nor used: the payer is the
|
||||
# order's customer (app/mercadopago.py payer, Marcus 2026-11-18); kept so a
|
||||
# page loaded before the change still pays.
|
||||
# The document in the card form, which opens with the order's: the payer
|
||||
# when it is a valid CPF or CNPJ (app/mercadopago.py payer).
|
||||
payer_document_type: Literal['CPF', 'CNPJ'] | None = None
|
||||
payer_document: str | None = Field(default=None, pattern=r'^[0-9]{11,14}$')
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ from typing import Mapping
|
||||
import httpx
|
||||
|
||||
from .adapters import PaymentEvent
|
||||
from .core.models import cnpj_ok, cpf_ok
|
||||
|
||||
API = 'https://api.mercadopago.com'
|
||||
# How old a signed timestamp may be. Mercado Pago retries a failed delivery
|
||||
@@ -41,15 +42,22 @@ PIX_MINUTES = 30
|
||||
BRASILIA = timezone(timedelta(hours=-3))
|
||||
|
||||
|
||||
def payer(customer):
|
||||
def payer(customer, method=None):
|
||||
"""Who pays, as Dropstar's finance reconciles it and the invoice is issued
|
||||
(Marcus, 2026-11-18): the customer's own CPF or CNPJ from the order, with
|
||||
their name and e-mail, for PIX and card alike, never a placeholder such
|
||||
as 999.999.999-99. The card form's document is not the payer: the
|
||||
cardholder's data travel inside the card token."""
|
||||
(Marcus, 2026-11-18): a real CPF or CNPJ, never a placeholder such as
|
||||
999.999.999-99, with the order's name and e-mail.
|
||||
|
||||
The card form opens with the order's document already in it (web/
|
||||
checkout.js), so the card token and the payer agree. A valid document
|
||||
the customer typed there instead (someone else's card) is the payer, as
|
||||
the token says; anything else, and PIX, is the order's own."""
|
||||
document = customer['cnpj']
|
||||
who = {'email': customer['mail'],
|
||||
'identification': {'type': 'CPF' if len(document) == 11 else 'CNPJ', 'number': document}}
|
||||
identification = {'type': 'CPF' if len(document) == 11 else 'CNPJ', 'number': document}
|
||||
typed = ''.join(ch for ch in str((method or {}).get('payer_document') or '') if ch.isdigit())
|
||||
kind = (method or {}).get('payer_document_type')
|
||||
if (kind == 'CPF' and cpf_ok(typed)) or (kind == 'CNPJ' and cnpj_ok(typed)):
|
||||
identification = {'type': kind, 'number': typed}
|
||||
who = {'email': customer['mail'], 'identification': identification}
|
||||
names = (customer.get('name') or '').split()
|
||||
if names:
|
||||
who['first_name'] = names[0]
|
||||
@@ -92,7 +100,10 @@ class MercadoPagoPayment:
|
||||
body = {'transaction_amount': float(Decimal(total_cents) / 100),
|
||||
'description': f'DTF - cotação {quote_id[:8]}',
|
||||
'external_reference': quote_id,
|
||||
'payer': payer(customer)}
|
||||
'payer': payer(customer, method if method['type'] == 'card' else None),
|
||||
# The order's own document, kept on the payment for finance
|
||||
# even when the card's holder is someone else.
|
||||
'metadata': {'documento_pedido': customer['cnpj']}}
|
||||
if self.notification_url:
|
||||
body['notification_url'] = self.notification_url
|
||||
expires_at = None
|
||||
|
||||
Reference in New Issue
Block a user