iLeben integrates with Mercado Pago using the officialDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/scooller/Leben-site/llms.txt
Use this file to discover all available pages before exploring further.
mercadopago/dx-php v3.x SDK, covering the full range of LATAM payment methods including credit cards, debit cards, and local wallet options. The flow is preference-based: the SDK creates a payment preference and returns an init_point URL that redirects the buyer to Mercado Pago’s hosted page. Payment confirmation arrives asynchronously via a signed webhook, separate from the user’s browser return.
Configuration
Obtain credentials from the Mercado Pago Developer Panel under your application’s Credentials tab. Use Test credentials in non-production environments and Production credentials in live deployments.Test and production tokens are distinct and not interchangeable. Using a test
ACCESS_TOKEN against the production API (or vice versa) will result in an Invalid access token error.Payment Flow
Initiate checkout
The frontend calls
POST /api/v1/checkout with gateway: "mercadopago" in the body. The API creates a Payment record with status pending and calls MercadoPagoService::createTransaction().Receive preference data
The API responds with a
redirect_url (the init_point) and a preference_id. Store both on the client for tracking.Redirect the user
The frontend redirects the user to the
init_point URL. Mercado Pago presents its hosted payment page with all locally available payment methods.Webhook received
After the user completes or abandons the payment, Mercado Pago sends an HTTP POST to
/payments/mercadopago/webhook. This is asynchronous and arrives independently of the browser redirect.Signature verification
PaymentWebhookController@mercadopagoWebhook verifies the request signature using MERCADOPAGO_WEBHOOK_SECRET before processing the payload. Requests that fail signature verification are rejected with a 401.Query payment status
The controller calls
getTransactionStatus($payment_id) to retrieve the authoritative status from the Mercado Pago API.Idempotent status update
The
Payment record is updated only if the incoming status represents a valid state transition. Duplicate webhook deliveries for the same event are safely ignored.PHP Example
The following snippet shows how to create a Mercado Pago preference using thePaymentGateway facade:
SDK Methods
| Method | Signature | Description |
|---|---|---|
createTransaction | createTransaction(array $data): array | Creates a payment preference; returns init_point and preference_id |
confirmTransaction | confirmTransaction(string $paymentId): array | Retrieves a specific MP payment object by ID |
getTransactionStatus | getTransactionStatus(string $paymentId): array | Queries the current status of a payment from the MP API |
refundTransaction | refundTransaction(string $paymentId, ?float $amount = null): array | Issues a full or partial refund for a completed payment |
Status Mapping
Mercado Pago statuses are mapped to iLeben’sPaymentStatus enum as follows:
| Mercado Pago Status | iLeben PaymentStatus |
|---|---|
approved | COMPLETED |
pending | PENDING |
in_process | PROCESSING |
rejected | FAILED |
cancelled | CANCELLED |
refunded | REFUNDED |
Webhook Setup
Register your webhook URL in the Mercado Pago Developer Panel.| Setting | Value |
|---|---|
| URL | https://your-domain.com/payments/mercadopago/webhook |
| Events | payment |
Web Routes
| Method | Route | Handler | Description |
|---|---|---|---|
POST | /payments/mercadopago/webhook | PaymentWebhookController@mercadopagoWebhook | Receives async payment notifications from MP |
GET | /payments/mercadopago/return | PaymentWebhookController@mercadopagoReturn | Receives the buyer redirect after payment |
Error Reference
| Error Message | Cause | Resolution |
|---|---|---|
Invalid access token | A test-mode token is being used against the production API, or a production token against the sandbox | Verify that MERCADOPAGO_ACCESS_TOKEN in .env matches the intended environment (Test vs. Production) in the MP Developer Panel. |
| Webhook not received | The webhook URL is not publicly accessible (common in local development) | Use ngrok or a similar tunneling tool to expose POST /payments/mercadopago/webhook publicly, then update the URL in the MP Developer Panel. |
Log Sanitization
Mercado Pago service calls are logged tostorage/logs/laravel.log. The mercadopago_payment metadata stored in the database contains only the minimum necessary fields — sensitive payment details and full API payloads are stripped before persistence.