MercadoPago
Complete guide to integrate online payments with MercadoPago in Sarah
Last updated: 2025-01-26
Sarah integrates with MercadoPago to process online payments in your store. This integration allows your customers to pay with credit card, debit card, bank transfer, and other payment methods available in MercadoPago.
Initial Configuration
1. Create Application in MercadoPago
- Log in to your MercadoPago Developers account
- Go to Your integrations > Create new application
- Complete your application data
- Copy your Access Token (public and private according to environment)
2. Configure in Sarah
- Log in to Sarah
- Go to Settings > Integrations > MercadoPago
- Enter your MercadoPago Access Token
- Select environment (Test or Production)
- Save configuration
3. Configure Webhook
To receive payment notifications, configure webhook in MercadoPago:
- In MercadoPago panel, go to Webhooks
- Add URL:
https://sarah.ar/api/mp/webhook - Select events to receive:
paymentorder(if using QR)
Payment Flow
1. Create Payment Preference
When a customer starts checkout, Sarah creates a payment preference in MercadoPago:
javascript// Example of created preference
{
"items": [
{
"title": "Product 1",
"quantity": 2,
"unit_price": 1500.00
}
],
"back_urls": {
"success": "https://your-store.com/checkout/success",
"failure": "https://your-store.com/checkout/failure",
"pending": "https://your-store.com/checkout/pending"
},
"external_reference": "sale_123",
"metadata": {
"sales_id": 123,
"box_id": 5
}
}
2. Redirect to Checkout
Customer is redirected to MercadoPago to complete payment.
3. Webhook Notification
MercadoPago sends a notification to Sarah when payment changes status:
Webhook URL:
POST /api/mp/webhook
Webhook structure:
json{
"type": "payment",
"data": {
"id": "1234567890"
}
}
4. Payment Processing
Sarah processes the webhook and updates sale status:
- Approved: Sale is marked as
paid - Rejected: Sale remains as
pendingor is canceled - Pending: Sale remains as
pending(e.g., cash payments)
Payment States
| MercadoPago State | State in Sarah | Description |
|---|---|---|
approved | paid | Payment approved and credited |
rejected | pending or cancelled | Payment rejected |
pending | pending | Pending payment (e.g., cash) |
in_process | pending | Payment under review |
cancelled | cancelled | Payment canceled |
Webhooks
Event: payment
Triggered when a payment changes status.
Structure:
json{
"type": "payment",
"data": {
"id": "1234567890"
}
}
Processing:
- Sarah gets payment details from MercadoPago API
- Verifies
external_reference(sale ID) - Updates sale status according to payment status
- If approved, marks sale as
paid
Event: order
Triggered when a QR or Point order changes status.
Structure:
json{
"type": "order",
"action": "order.processed",
"data": {
"id": "ORD01KBGJBJR73YSRQEHJWMQJKF7R"
}
}
Processing:
- Sarah gets order details
- Verifies
external_reference(sale ID) - If order is
processed, marks sale aspaid
Supported Payment Methods
MercadoPago supports multiple payment methods:
- 💳 Credit/debit card
- 🏦 Bank transfer
- 💵 Cash (Rapipago, Pago Fácil)
- 📱 MercadoPago account money
- 🔄 Interest-free installments (if enabled)
Security
Webhook Validation
Sarah validates MercadoPago webhooks:
- Origin verification: Webhooks must come from MercadoPago servers
- Data validation: Verifies payment exists and belongs to company
- Idempotency: Avoids processing same webhook multiple times
Access Token
- Never share your Access Token publicly
- Rotate token periodically if you suspect compromise
- Use different tokens for test and production
Use Cases
1. Online Sale with Checkout Pro
- Customer adds products to cart
- Starts checkout
- Sarah creates payment preference
- Customer is redirected to MercadoPago
- Customer completes payment
- MercadoPago sends webhook
- Sarah updates sale to
paid
2. Payment with QR
- QR code is generated in POS
- Customer scans with MercadoPago
- Customer confirms payment
- MercadoPago sends order webhook
- Sarah updates sale to
paid
3. Rejected Payment
- Customer attempts payment
- Payment is rejected (insufficient funds, etc.)
- MercadoPago sends webhook with
rejectedstatus - Sarah keeps sale as
pending - Customer can retry payment
Troubleshooting
Webhook doesn't arrive
- Verify URL: Ensure
https://sarah.ar/api/mp/webhookis accessible - Review logs: Check in MercadoPago if there are errors sending
- Test manually: Use MercadoPago webhook testing tool
Payment approved but sale doesn't update
- Verify external_reference: Must match sale ID
- Review logs: Look for errors in webhook processing
- Verify Access Token: Must have permissions to query payments
Duplicate payment
- Idempotency: Sarah avoids processing same webhook multiple times
- Verify in MercadoPago: Check if there are really two payments or it's the same
Error: "Invalid payment"
- Verify payment ID: Must exist in MercadoPago
- Verify Access Token: Must have access to payment
- Verify environment: Token must correspond to correct environment
Best Practices
- Configure webhooks in production: Essential to receive notifications
- Handle all states: Not only
approved, alsopendingandrejected - Implement retries: If webhook fails, MercadoPago will retry
- Log events: Save logs of all received webhooks
- Validate amounts: Verify payment amount matches sale
- Use external_reference: Always include sale ID to correlate
Additional Resources
- Official MercadoPago Documentation
- Payments API
- MercadoPago Webhooks
- MercadoPago POS - Integration with physical terminals
Support
If you need help:
- Review webhook logs in MercadoPago
- Verify configuration in Sarah
- Contact Sarah support with error details