# MD for: https://www.mercadopago.com.pe/developers/pt/docs/checkout-bricks/payment-brick/advanced-features/preferences.md \# Preference configurations You can adapt the Payment Brick integration to your business model by setting \[preference attributes\](https://www.mercadopago.com.pe/developers/en/reference/online-payments/checkout-pro/preferences/create-preference/post). If you offer high-value purchases, for example, you can \[exclude undesired payment methods\](#bookmark\_define\_the\_desired\_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": "", "surname": "", "email": "", "phone": { "area\_code": "", "number": "" }, "identification": { "type": "", "number": "" }, "address": { "street\_name": "Street", "street\_number": 123, "zip\_code": "" } }, "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, 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: * [csharp ](#editor%5F5) * [java ](#editor%5F3) * [node ](#editor%5F2) * [php ](#editor%5F1) * [python ](#editor%5F6) * [ruby ](#editor%5F4) php node java ruby csharp python ``` payment_methods = array( "excluded_payment_methods" => array( array("id" => "master") ), "excluded_payment_types" => array( array("id" => "ticket") ), "installments" => 12 ); // ... ?> ``` Copiar ``` var preference = {} preference = { //... "payment_methods": { "excluded_payment_methods": [ { "id": "master" } ], "excluded_payment_types": [ { "id": "ticket" } ], "installments": 12 } //... } ``` Copiar ``` PreferenceClient client = new PreferenceClient(); //... List excludedPaymentMethods = new ArrayList<>(); excludedPaymentMethods.add(PreferencePaymentMethodRequest.builder().id("master").build()); excludedPaymentMethods.add(PreferencePaymentMethodRequest.builder().id("amex").build()); List 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); //... ``` Copiar ``` #... preference_data = { # ... payment_methods: { excluded_payment_methods: [ { id: 'master' } ], excluded_payment_types: [ { id: 'ticket' } ], installments: 12 } # ... } #... ``` Copiar ``` var paymentMethods = new PreferencePaymentMethodsRequest { ExcludedPaymentMethods = new List { new PreferencePaymentMethodRequest { Id = "master", }, }, ExcludedPaymentTypes = new List { new PreferencePaymentTypeRequest { Id = "ticket", }, }, Installments = 12, }; var request = new PreferenceRequest { // ... PaymentMethods = paymentMethods, }; ``` Copiar ``` #... preference_data = { "excluded_payment_methods": [ { "id": "master" } ], "excluded_payment_types": [ { "id": "ticket" } ], "installments": 12 } #... ``` Copiar \## 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. > WARNING > > Important > > By adding this option, you will not be able to receive payments from users who do not have a Mercado Pago or Mercado Livre account, as well as you will not be able to receive payments via cash or transfer. 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 \`\`\` > WARNING > > Important > > Activating the binary mode simplifies the integration with Payment Brick, but it can cause a decrease in the percentage rate of approved payments. That is because pending and in-processing payments will automatically be rejected by default. ## 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: * [csharp ](#editor%5F11) * [curl ](#editor%5F13) * [java ](#editor%5F9) * [node ](#editor%5F8) * [php ](#editor%5F7) * [python ](#editor%5F12) * [ruby ](#editor%5F10) php node java ruby csharp python curl ``` 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(); ?> ``` Copiar ``` // Set your preference var preference = { items: [ { title: 'Mi producto', quantity: 1, currency_id: 'PEN', unit_price: 75.56 }, { title: 'Mi producto 2’, quantity: 2, currency_id: 'PEN', 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); }); ``` Copiar ``` // Create a preference object PreferenceClient client = new PreferenceClient(); // Create items in the preference List 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); ``` Copiar ``` sdk = Mercadopago::SDK.new('ENV_ACCESS_TOKEN') # Create preference data with items preference_data = { items: [ { title: 'Mi producto 1', quantity: 1, currency_id: 'PEN', unit_price: 75.56 }, { title: 'Mi producto 2', quantity: 2, currency_id: 'PEN', unit_price: 96.56 } ] } preference_response = sdk.preference.create(preference_data) preference = preference_response[:response] ``` Copiar ``` // Create the request with multiples items var request = new PreferenceRequest { Items = new List { new PreferenceItemRequest { Title = "My product 1", Quantity = 1, CurrencyId = "PEN", UnitPrice = 75.56m, }, new PreferenceItemRequest { Title = "My product 2", Quantity = 2, CurrencyId = "PEN", UnitPrice = 96.56m, }, // ... }, }; // Create a client object var client = new PreferenceClient(); // Create the preference Preference preference = await client.CreateAsync(request); ``` Copiar ``` # 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"] ``` Copiar ``` 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" } ] }' ``` Copiar 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. > WARNING > > Do not use local domains in the \`back\_urls\` value, such as 'localhost/' or '127.0.0.1' with or without a specified port. We recommend using a server with a named domain (DNS) or development IPs to be able to return to the site after payment. Otherwise, the "Something went wrong" message will appear when the purchase process is completed. 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. | > NOTE > > Note > > Some parameters hold purchase information only if the buyer has completed the entire payment in Payment Brick and has not abandoned the flow before returning to your site via the \`failure\` \`back\_urls\`. For example: * [csharp ](#editor%5F18) * [java ](#editor%5F16) * [node ](#editor%5F15) * [php ](#editor%5F14) * [python ](#editor%5F19) * [ruby ](#editor%5F17) php node java ruby csharp python ``` 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"; // ... ?> ``` Copiar ``` 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", // ... } ``` Copiar ``` 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(); // ... ``` Copiar ``` # ... 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' # ... } # ... ``` Copiar ``` 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", }; ``` Copiar ``` 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" } ``` Copiar