Preference configurations
You can adapt the Payment Brick integration to your business model by setting preference attributes.
If you offer high-value purchases, for example, you can exclude undesired payment methods for your operation.
Example of complete preference
json
{
"items": [
{
"id": "item-ID-1234",
"title": "My product",
"currency_id": "BRL",
"picture_url": "https://www.mercadopago.com/org-img/MP3/home/logomp3.gif",
"description": "Item description",
"category_id": "art",
"quantity": 1,
"unit_price": 75.76
}
],
"payer": {
"name": "<PAYER_NAME_HERE>",
"surname": "<PAYER_SURNAME_HERE>",
"email": "<PAYER_EMAIL_HERE>",
"phone": {
"area_code": "<PAYER_AREA_CODE_HERE>",
"number": "<PAYER_PHONE_NUMBER_HERE>"
},
"identification": {
"type": "<PAYER_DOC_TYPE_HERE>",
"number": "<PAYER_DOC_NUMBER_HERE>"
},
"address": {
"street_name": "Street",
"street_number": 123,
"zip_code": "<PAYER_ZIP_CODE_HERE>"
}
},
"back_urls": {
"success": "https://www.success.com",
"failure": "http://www.failure.com",
"pending": "http://www.pending.com"
},
"auto_return": "approved",
"payment_methods": {
"excluded_payment_methods": [
{
"id": "master"
}
],
"excluded_payment_types": [
{
"id": "ticket"
}
],
"installments": 12
},
"notification_url": "https://www.your-site.com/ipn",
"statement_descriptor": "MYBUSINESS",
"external_reference": "Reference_1234",
"expires": true,
"expiration_date_from": "2016-02-01T12:00:00.000-04:00",
"expiration_date_to": "2016-02-28T12:00:00.000-04:00"
}
Define the desired payment methods
Through payment preference, you can configure a default payment method to be rendered, delete unwanted ones, or choose a maximum number of installments to be offered.
Preference attribute | Description |
payment_methods | Class describing Payment Brick's payment methods and attributes. |
excluded_payment_types | Method that excludes undesired payment methods for your operation, such as credit card, ticket, etc. |
excluded_payment_methods | Method that excludes specific credit and debit card brands, such as Visa, Mastercard, American Express, etc. |
installments | Method that defines the maximum number of installments to be offered. |
purpose | By indicating the value wallet_purchase in this method, Payment Brick will only accept payments from registered users in Mercado Pago, with card and account balance. |
For example:
<?php
$preference = new MercadoPago\Preference();
// ...
$preference->payment_methods = array(
"excluded_payment_methods" => array(
array("id" => "master")
),
"excluded_payment_types" => array(
array("id" => "ticket")
),
"installments" => 12
);
// ...
?>
var preference = {}
preference = {
//...
"payment_methods": {
"excluded_payment_methods": [
{
"id": "master"
}
],
"excluded_payment_types": [
{
"id": "ticket"
}
],
"installments": 12
}
//...
}
PreferenceClient client = new PreferenceClient();
//...
List<PreferencePaymentMethodRequest> excludedPaymentMethods = new ArrayList<>();
excludedPaymentMethods.add(PreferencePaymentMethodRequest.builder().id("master").build());
excludedPaymentMethods.add(PreferencePaymentMethodRequest.builder().id("amex").build());
List<PreferencePaymentTypeRequest> excludedPaymentTypes = new ArrayList<>();
excludedPaymentTypes.add(PreferencePaymentTypeRequest.builder().id("ticket").build());
PreferencePaymentMethodsRequest paymentMethods =
PreferencePaymentMethodsRequest.builder()
.excludedPaymentMethods(excludedPaymentMethods)
.excludedPaymentTypes(excludedPaymentTypes)
.installments(12)
.build();
PreferenceRequest request = PreferenceRequest.builder().paymentMethods(paymentMethods).build();
client.create(request);
//...
#...
preference_data = {
# ...
payment_methods: {
excluded_payment_methods: [
{ id: 'master' }
],
excluded_payment_types: [
{ id: 'ticket' }
],
installments: 12
}
# ...
}
#...
var paymentMethods = new PreferencePaymentMethodsRequest
{
ExcludedPaymentMethods = new List<PreferencePaymentMethodRequest>
{
new PreferencePaymentMethodRequest
{
Id = "master",
},
},
ExcludedPaymentTypes = new List<PreferencePaymentTypeRequest>
{
new PreferencePaymentTypeRequest
{
Id = "ticket",
},
},
Installments = 12,
};
var request = new PreferenceRequest
{
// ...
PaymentMethods = paymentMethods,
};
#...
preference_data = {
"excluded_payment_methods": [
{ "id": "master" }
],
"excluded_payment_types": [
{ "id": "ticket" }
],
"installments": 12
}
#...
Accept payments from registered users only
You can accept payments with the Mercado Pago wallet only from registered users, with a credit card or money in account.
This allows your customers to have their account information available instantly at the time of payment, such as their pre saved cards and addresses.
To accept payments only from registered users, add the following attribute to your preferences:
json
"purpose": "wallet_purchase"
Once you complete the action, your preference should have a structure similar to the example below:
json
{
"purpose": "wallet_purchase",
"items": [
{
"title": "My product",
"quantity": 1,
"unit_price": 75.76
}
],
}
Enable binary mode
You can enable the binary mode if the business model requires payment approval to be instantaneous. This way, the payment can only be approved or declined. The payment may be pending (if any action is required by the buyer) or processing (if a manual review is required) when the binary mode is disabled.
To enable it, just set the payment preference's binary_mode
attribute to true
:
json
"binary_mode": true
Set an expiration date for your preferences
Set an expiration period for your payment preferences in the expires
, expiration_date_from
, and expiration_date_to
attributes:
json
"expires": true,
"expiration_date_from": "2017-02-01T12:00:00.000-04:00",
"expiration_date_to": "2017-02-28T12:00:00.000-04:00"
Note that the date must follow the format ISO 8601: yyyy-MM-dd'T'HH:mm:ssz
.
Send description on buyer card invoice
You can add a description for your business via the statement_descriptor
attribute of the payment preferences, as shown in the example below:
json
"statement_descriptor": "MYBUSINESS"
Depending on the card brand, the description (attribute value) will appear on the buyer's card invoice.
Set a preference for multiple items
If you need to create a preference for more than one item, you must add them as a list, as shown in the example below:
<?php
# Create a preference object
$preference = new MercadoPago\Preference();
# Create items in the preference
$item1 = new MercadoPago\Item
$item1->title = "Item de Prueba 1";
$item1->quantity = 2;
$item1->unit_price = 11.96;
$item2= new MercadoPago\Item
$item2->title = "Item de Prueba 2";
$item2->quantity = 1;
$item2->unit_price = 11.96;
$preference->items = array($item1,$item2);
# Save and post the preference
$preference->save();
?>
// Set your preference
var preference = {
items: [
{ title: 'Mi producto',
quantity: 1,
currency_id: 'MXN',
unit_price: 75.56 },
{ title: 'Mi producto 2’,
quantity: 2,
currency_id: 'MXN',
unit_price: 96.56 }
]
};
// Create the preference
mercadopago.preferences.create(preference)
.then(function(preference){
// This value replaces "$init_point$" string in your HTML
global.init_point = preference.body.init_point;
}).catch(function(error){
console.log(error);
});
// Create a preference object
PreferenceClient client = new PreferenceClient();
// Create items in the preference
List<PreferenceItemRequest> items = new ArrayList<>();
PreferenceItemRequest item1 =
PreferenceItemRequest.builder()
.id("1234")
.title("Produto 1")
.quantity(2)
.currencyId("BRL")
.unitPrice(new BigDecimal("100"))
.build();
PreferenceItemRequest item2 =
PreferenceItemRequest.builder()
.id("12")
.title("Produto 2")
.quantity(1)
.currencyId("BRL")
.unitPrice(new BigDecimal("100"))
.build();
items.add(item1);
items.add(item2);
PreferenceRequest request = PreferenceRequest.builder().items(items).build();
// Save and post the preference
client.create(request);
sdk = Mercadopago::SDK.new('ENV_ACCESS_TOKEN')
# Create preference data with items
preference_data = {
items: [
{
title: 'Mi producto 1',
quantity: 1,
currency_id: 'MXN',
unit_price: 75.56
},
{
title: 'Mi producto 2',
quantity: 2,
currency_id: 'MXN',
unit_price: 96.56
}
]
}
preference_response = sdk.preference.create(preference_data)
preference = preference_response[:response]
// Create the request with multiples items
var request = new PreferenceRequest
{
Items = new List<PreferenceItemRequest>
{
new PreferenceItemRequest
{
Title = "My product 1",
Quantity = 1,
CurrencyId = "MXN",
UnitPrice = 75.56m,
},
new PreferenceItemRequest
{
Title = "My product 2",
Quantity = 2,
CurrencyId = "MXN",
UnitPrice = 96.56m,
},
// ...
},
};
// Create a client object
var client = new PreferenceClient();
// Create the preference
Preference preference = await client.CreateAsync(request);
# Create items in the preference
preference_data = {
"items": [
{
"title": "Mi producto",
"quantity": 1,
"unit_price": 75.56
},
{
"title": "Mi producto2",
"quantity": 2,
"unit_price": 96.56
}
]
}
# Create a preference
preference_response = sdk.preference().create(preference_data)
preference = preference_response["response"]
curl -X POST \
'https://api.mercadopago.com/checkout/preferences' \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-H 'Authorization: Bearer PROD_ACCESS_TOKEN' \
-d '{
"items": [
{
"id_product":1,
"quantity":1,
"unit_price": 234.33,
"titulo":"Mi producto"
},
{
"id_product":2,
"quantity":2,
"unit_price": 255.33,
"titulo":"Mi producto 2"
}
]
}'
Keep in mind that the total value of the preference will be the sum of the unit price value of each item listed.
Show shipping cost
If your website already calculates the shipment value, you can display it separately from the total amount at the time of payment.
To configure such a scenario, add the item shipments
with the value you want to charge in the cost
attribute and the value not_specified
in the mode
attribute:
json
{
"shipments":{
"cost": 1000,
"mode": "not_specified",
}
}
Redirect the buyer to your site
At the end of the checkout process, you have the option to redirect the buyer to your site again. To do this, add the back_urls
attribute and define the desired page to redirect your buyer when he clicks on the Return to site
button, according to the payment status.
You can also add the auto_return
attribute with the approved
value if you want the redirect for approved payments to be automatic without rendering a return button.
Attribute | Description |
auto_return | Buyers are automatically redirected to the site when payment is approved. The default value is approved . |
back_urls | Return URL to site. Possible scenarios are:success : Return URL upon payment approved.pending : Return URL upon payment pending.failure : Return URL upon payment payment rejected. |
The back_urls
will return the following parameters:
Parameter | Description |
payment_id | ID (identifier) of the payment from Mercado Pago. |
status | Payment status. Ex.: approved for an approved payment or pending for pending payment. |
external_reference | Amount sent at the time when the payment preference was created. |
merchant_order_id | ID (identifier) of the payment order generated in Mercado Pago. |
For example:
<?php
$preference = new MercadoPago\Preference();
//...
$preference->back_urls = array(
"success" => "https://www.tu-sitio/success",
"failure" => "http://www.tu-sitio/failure",
"pending" => "http://www.tu-sitio/pending"
);
$preference->auto_return = "approved";
// ...
?>
var preference = {}
preference = {
// ...
"back_urls": {
"success": "https://www.tu-sitio/success",
"failure": "http://www.tu-sitio/failure",
"pending": "http://www.tu-sitio/pending"
},
"auto_return": "approved",
// ...
}
PreferenceBackUrlsRequest backUrls =
// ...
PreferenceBackUrlsRequest.builder()
.success("https://www.seu-site/success")
.pending("https://www.seu-site/pending")
.failure("https://www.seu-site/failure")
.build();
PreferenceRequest request = PreferenceRequest.builder().backUrls(backUrls).build();
// ...
# ...
preference_data = {
# ...
back_urls = {
success: 'https://www.tu-sitio/success',
failure: 'https://www.tu-sitio/failure',
pending: 'https://www.tu-sitio/pendings'
},
auto_return: 'approved'
# ...
}
# ...
var request = new PreferenceRequest
{
// ...
BackUrls = new PreferenceBackUrlsRequest
{
Success = "https://www.tu-sitio/success",
Failure = "http://www.tu-sitio/failure",
Pending = "http://www.tu-sitio/pendings",
},
AutoReturn = "approved",
};
preference_data = {
"back_urls": {
"success": "https://www.tu-sitio/success",
"failure": "https://www.tu-sitio/failure",
"pending": "https://www.tu-sitio/pendings"
},
"auto_return": "approved"
}