Overview
The Preferences API allows you to create payment preferences that define the items, amounts, and configuration for a Mercado Pago checkout experience. Preferences are used to initialize the Mercado Pago checkout flow.
This endpoint is only available in local and testing environments when MERCADOPAGO_ENABLE_DEMO_ROUTES=true. It is automatically disabled in production.
Create Preference
Creates a new payment preference with items and configuration.
Endpoint
POST /api/mercadopago/preferences
Request Parameters
Array of items to be purchased. Must contain at least one item. Item title or description
Quantity of items. Minimum value: 1
Price per unit. Minimum value: 0
URLs to redirect after payment completion URL for successful payment
URL for webhook notifications. Must be a valid URL.
Your internal reference ID for this preference
Custom metadata object for additional information
Whether the preference has an expiration date
Start date for preference validity
End date for preference validity
Request Example
{
"items" : [
{
"title" : "Producto demo" ,
"quantity" : 1 ,
"unit_price" : 100.5
}
],
"payer" : {
"email" : "[email protected] "
},
"back_urls" : {
"success" : "https://tu-app.test/pagos/exito" ,
"pending" : "https://tu-app.test/pagos/pendiente" ,
"failure" : "https://tu-app.test/pagos/error"
},
"notification_url" : "https://tu-app.test/api/mercadopago/webhooks" ,
"external_reference" : "pedido-1001"
}
Response
Returns the created preference object from Mercado Pago.
Indicates if the request was successful
The preference object returned by Mercado Pago Show Preference properties
Unique preference identifier
URL to initialize the checkout in production
URL to initialize the checkout in sandbox/testing
Array of items included in the preference
Your internal reference ID
Additional metadata (typically empty)
Response Example
{
"ok" : true ,
"data" : {
"id" : "123456789-abc123-def456-ghi789" ,
"init_point" : "https://www.mercadopago.com.ar/checkout/v1/redirect?pref_id=123456789-abc123" ,
"sandbox_init_point" : "https://sandbox.mercadopago.com.ar/checkout/v1/redirect?pref_id=123456789-abc123" ,
"items" : [
{
"id" : "item-001" ,
"title" : "Producto demo" ,
"quantity" : 1 ,
"unit_price" : 100.5
}
],
"payer" : {
"email" : "[email protected] "
},
"back_urls" : {
"success" : "https://tu-app.test/pagos/exito" ,
"pending" : "https://tu-app.test/pagos/pendiente" ,
"failure" : "https://tu-app.test/pagos/error"
},
"notification_url" : "https://tu-app.test/api/mercadopago/webhooks" ,
"external_reference" : "pedido-1001"
},
"meta" : []
}
cURL Example
curl --request POST \
--url http://localhost:8000/api/mercadopago/preferences \
--header 'Content-Type: application/json' \
--data '{
"items": [
{
"title": "Producto demo",
"quantity": 1,
"unit_price": 100.5
}
]
}'
Error Response
{
"ok" : false ,
"message" : "Error message describing what went wrong"
}
Implementation Notes
Availability
This endpoint is protected by the mercadopago.demo middleware and only responds when:
MERCADOPAGO_ENABLE_DEMO_ROUTES=true in configuration
Application environment is local or testing
In production or when demo routes are disabled, this endpoint returns 404.
Controller Reference
Implemented in: src/Http/Controllers/Api/PreferenceController.php:14
Request validation: src/Http/Requests/CreatePreferenceRequest.php:16
Best Practices
Production Usage : For production environments, create your own controllers that inject the PreferenceService and implement your application’s authentication, authorization, and business logic.
Security : Demo routes are for development and testing only. Never expose them in production environments.
Example Production Controller
use Fitodac\LaravelMercadoPago\Services\ PreferenceService ;
final class CheckoutPreferenceController
{
public function store ( Request $request , PreferenceService $preferenceService ) : JsonResponse
{
$payload = $request -> validate ([
'items' => [ 'required' , 'array' , 'min:1' ],
'items.*.title' => [ 'required' , 'string' ],
'items.*.quantity' => [ 'required' , 'integer' , 'min:1' ],
'items.*.unit_price' => [ 'required' , 'numeric' , 'min:0' ],
'external_reference' => [ 'sometimes' , 'string' ],
]);
$preference = $preferenceService -> create ( $payload );
return response () -> json ([
'id' => data_get ( $preference , 'id' ),
'init_point' => data_get ( $preference , 'init_point' ),
], 201 );
}
}