This guide covers integrating Mercado Pago with CoCart Preview API. Requires CoCart v4.6+ and a configured Mercado Pago payment gateway.
Overview
Mercado Pago integration with CoCart uses Checkout Bricks for a modular, secure, and customizable payment solution. This provides PCI compliance while supporting 15+ payment methods popular in Latin America, including PIX (Brazil), cards, installments, and digital wallets. Mercado Pago is the leading payment platform in Latin America, operating in Argentina, Brazil, Chile, Colombia, Mexico, Peru, and Uruguay.Prerequisites
Before implementing Mercado Pago checkout, ensure you have:- Mercado Pago payment gateway configured in WooCommerce
- Mercado Pago Public Key and Access Token
- A valid cart with items added
- Customer billing address information
- Mercado Pago account (sandbox mode available)
Integration Flow
1
Load SDK
Initialize the Mercado Pago JavaScript SDK
2
Create Bricks Instance
Set up the Bricks Builder with your public key
3
Mount Card Payment Brick
Render the secure payment form
4
Collect Payment Data
Customer enters payment information in the Brick
5
Generate Payment Token
Submit Brick form to get payment token
6
Complete Checkout
Submit payment token to CoCart for processing
Step 1: Load Mercado Pago SDK
Include the SDK in your checkout page:The Mercado Pago SDK is always served over HTTPS and includes the latest security updates.
Step 2: HTML Structure
Create containers for the payment Brick and form:Step 3: Initialize Mercado Pago SDK
Set up the SDK with your public key:Step 4: Create Card Payment Brick
Mount the payment form:Step 5: Handle Brick Submission
Process the payment data when Brick form is submitted:Step 6: Show Status Brick
Display payment result to customer:Complete Integration Example
Here’s a complete working implementation:Styling
Add CSS to style your checkout:Testing
For development and testing with Mercado Pago:Test Mode
Use test credentials from your Mercado Pago dashboard:- Public Key: Starts with
TEST- - Access Token: Starts with
TEST-
Test Cards by Country
Brazil (BRL):- Approved:
5031 4332 1540 6351(Mastercard) - CVV:
123 - Expiry: Any future date
- Cardholder:
APRO
- Approved:
5031 7557 3453 0604(Mastercard) - CVV:
123 - Expiry: Any future date
- Cardholder:
APRO
- Approved:
5474 9254 3267 0366(Mastercard) - CVV:
123 - Expiry: Any future date
- Cardholder:
APRO
Test Scenarios
To test different responses, use these cardholder names:- APRO: Approved payment
- CONT: Pending payment
- OTHE: Rejected (other reason)
- CALL: Rejected (call to authorize)
- FUND: Rejected (insufficient funds)
- SECU: Rejected (security code)
- EXPI: Rejected (expiration date)
- FORM: Rejected (form error)
Test CPF/CNPJ (Brazil)
Use these test documents:- CPF:
12345678909 - CNPJ:
12345678000190
Supported Payment Methods
Mercado Pago supports various payment methods by country:Brazil
- Credit/Debit Cards (Visa, Mastercard, Amex, Elo, Hipercard)
- PIX (Instant payment)
- Boleto Bancário
- Mercado Pago Wallet
Argentina
- Credit/Debit Cards (Visa, Mastercard, Amex, Naranja, Cabal)
- Rapipago / Pago Fácil
- Mercado Pago Wallet
Mexico
- Credit/Debit Cards (Visa, Mastercard, Amex)
- OXXO
- SPEI
- Mercado Pago Wallet
Chile, Colombia, Peru, Uruguay
- Credit/Debit Cards
- Cash payments (varies by country)
- Mercado Pago Wallet
Troubleshooting
Common Issues
Mercado Pago SDK Not Loading
Mercado Pago SDK Not Loading
Problem: MercadoPago object is undefined.Solution:
- Check browser console for errors
- Verify correct SDK URL (v2)
- Ensure HTTPS is enabled
Bricks Not Rendering
Bricks Not Rendering
Problem: Card Payment Brick doesn’t appear.Solution:
Token Generation Fails
Token Generation Fails
Problem: Can’t get payment token from Brick.Solution:
- Ensure all required fields are filled
- Verify card number is valid
- Check expiration date is future
- Validate CVV is correct length
Payment Method Not Recognized
Payment Method Not Recognized
Problem: Backend doesn’t accept Mercado Pago.Solution:
- Verify Mercado Pago gateway enabled
- Check payment method ID matches WooCommerce
- Ensure public key is configured
Wrong Country or Currency
Wrong Country or Currency
Problem: Payment fails due to country mismatch.Solution:
- Use correct public key for country
- Match locale to customer’s country
- Verify currency is supported
Test Mode vs Production
Test Mode vs Production
Problem: Works in test but not production.Solution:Checklist:
- Switch to production public key
- Update credentials in WooCommerce
- Verify account is activated
- Test with real card (small amount)
PIX Payment Issues (Brazil)
PIX Payment Issues (Brazil)
Problem: PIX payments not working.Solution:
- Ensure PIX is enabled in Mercado Pago account
- Verify customer is in Brazil
- Check amount is within PIX limits
- Ensure QR code is displaying correctly
- Verify PIX key is configured in account
Debug Mode
Getting Help
- Mercado Pago Documentation: Checkout Bricks Guide
- Mercado Pago Support: Contact through dashboard
- WooCommerce Logs: Check WooCommerce → Status → Logs
Best Practices
Security
- Never expose Access Token on frontend
- Always verify payments on server
- Use HTTPS for all requests
- Implement webhook verification
- Handle payment IDP notifications
- Enable 3DS authentication
User Experience
- Pre-fill customer information
- Show installment options clearly
- Support local payment methods
- Provide clear error messages
- Display payment status
- Enable retry for failed payments
Compliance
- PCI DSS compliant via Bricks
- Follow local regulations
- Store customer data securely
- Implement proper refund flows
- Maintain transaction logs
- Respect data privacy laws
Performance
- Load SDK from official CDN
- Cache payment contexts
- Implement proper timeouts
- Handle network errors
- Monitor success rates
- Set up IPN webhooks
Advanced Features
PIX Payments (Brazil)
For instant PIX payments:Installments
Configure installment options:Wallet Integration
Enable Mercado Pago Wallet:Webhook Handling (IPN)
Mercado Pago sends notifications via IPN (Instant Payment Notification):Error Handling
Handle common Mercado Pago errors:Troubleshooting
Common issues and solutions: Brick not loading: Verify SDK is loaded and public key is correct. Payment rejected: Check test card details match the scenario. IPN not received: Configure webhook URL in Mercado Pago dashboard. Installments not showing: Verify payment method supports installments. Currency mismatch: Ensure amount matches account currency.Always test your Mercado Pago integration thoroughly using test mode before going live. Configure IPN/webhooks to handle asynchronous payment updates. Monitor your Mercado Pago dashboard for chargebacks and disputes. Implement proper error logging for debugging payment issues.