This guide shows you how to accept payments using Mercado Pago, Latin America’s most popular digital wallet. Mercado Pago offers instant payment processing and is especially popular among younger demographics and frequent online shoppers.
Mercado Pago payments use a redirect flow where customers authenticate on Mercado Pago’s platform. Send your payment request to the Process Transaction endpoint:
The API response will include payment instructions and redirect information. Mercado Pago payments require a redirect flow where customers authenticate on Mercado Pago’s platform:
The response contains key fields you need to handle the payment flow:
Field
Description
id
Unique transaction identifier - store this for status checking
status
Current payment status - will be pending initially
next_action.redirect_to_url.url
URL where you should redirect the customer
next_action.redirect_to_url.return_url
URL where customer returns after payment
id and status fields validationCheck that you received a valid id and status before proceeding. If either is missing or invalid, do not redirect the customer and handle the error appropriately.
Use the URL from next_action.redirect_to_url.url to redirect your customer.
2
Customer authenticates
Customer logs into their Mercado Pago account and confirms payment details.
3
Customer completes payment
Customer selects their preferred funding source and confirms the payment.
4
Customer returns to your site
After payment, customer is redirected back to your return_url.
Here’s an example of how to redirect the customer to Mercado Pago. This code validates the response, extracts the redirect URL, and handles the customer redirect:
Copy
Ask AI
// Redirect customer to Mercado Pagofunction redirectToMercadoPago(response) { if (response.next_action && response.next_action.redirect_to_url) { const redirectUrl = response.next_action.redirect_to_url.url; // Option 1: Redirect in same window window.location.href = redirectUrl; // Option 2: Open in popup (better UX) const popup = window.open( redirectUrl, 'mercadopago_checkout', 'width=800,height=600,scrollbars=yes,resizable=yes' ); // Monitor popup for completion const checkClosed = setInterval(() => { if (popup.closed) { clearInterval(checkClosed); checkPaymentStatus(response.id); } }, 1000); }}