Mercado Pago auto-pay
Built: 2026-11-03. Written for operators in Mexico (and other Mercado Pago countries) and for whoever maintains the code.
Many riders without a credit card hold a Mercado Pago account. Uber in Mexico lets them link it once and be charged automatically. RideKit does the same through Mercado Pago Wallet Connect.
What the rider does
Wallet → Mercado Pago auto-pay → Link. Mercado Pago's page opens, the rider approves, and Mercado Pago sends them back to a short page saying "Mercado Pago linked". It reads in Spanish, Portuguese or English, from the browser's language. Back in the app, the card says when it was linked.
From then on, nothing to do:
- Booking a wallet ride the balance doesn't cover. The missing amount is charged to Mercado Pago and the ride books. The charge is rounded up to a whole peso, and is at least MXN 10. If Mercado Pago declines, the booking is refused as for any short wallet.
- A wallet ride that ended above what the wallet held. The difference is charged after the trip. If that charge fails, it stays a pending balance, as with any other.
The card shows a warning when the last automatic charge was declined. Unlink forgets the account at once.
Every charge lands in the wallet as a normal top-up first. The ledger and receipts look exactly like any other top-up, and the same idempotency key keeps a retry from charging twice.
Turning it on
- Admin → Providers → Mercado Pago: the access token (the same one Checkout Pro uses).
- Ask Mercado Pago to enable Wallet Connect on the seller account.
- The backend must have a public address:
PUBLIC_BASE_URL, e.g.https://api.example.com/api. Mercado Pago sends the rider back toPUBLIC_BASE_URL/payments/mercadopago/linked. Without it, the card stays hidden. - The market must take Mercado Pago (Admin → Markets → Payments).
Privacy and security
- The payer token is stored encrypted (AES-256-GCM, the same key as provider secrets). Unlinking deletes it.
- The return page only completes a link that this backend started. A replayed or forged return does nothing.
Code
backend/src/payments/mercadopago-link.service.ts: link, complete, unlink, and charge-then-top-up;mercadopago-link.controller.ts:GET/POST/DELETE /payments/rider/mercadopago/link;- the public
/payments/mercadopago/linkedpage;
rides/rides.service.ts: the short-wallet booking;rides/dispatch.service.ts:settleOverrunFromLinkSafe;- migration
1700000155000-RiderPaymentLinks; - rider app:
src/components/MercadoPagoLink.tsx;app/(app)/wallet.tsx.
For development, MERCADOPAGO_API_BASE=http://localhost:12112 points every
Mercado Pago call at a local mock. No test reaches the real API.
Check locally
This follows Mercado Pago's published Wallet Connect contract. No real account has been linked through it yet. Link a test account on a Mexican test seller before launch, and confirm the auto-charge terms with your counsel and with Mercado Pago (cobro automático needs the rider's clear consent, which the approval page gives).