Create preferences - Checkout Pro - Mercado Pago Developers
Which documentation are you looking for?

Do not know how to start integrating? 

Check the first steps

Integrate Checkout Pro

The integration with Checkout Pro allows you to receive payments via our web form from any device in a simple, fast and secure way.

In this documentation you will find all the necessary steps to integrate Checkout Pro through our SDKs. To do this, follow the steps described below.

Try our Checkout Pro

Build the Checkout Pro visual experience in real-time. When you are all set, download or copy the generated code to add it to your website or share it with a developer.

Element for view
Demo

Install Mercado Pago SDK

Server-Side

The first step to integrate Checkout Pro is to install the Mercado Pago SDK in your project. To do this, use one of the codes available below.

To install the SDK, you must run the following code in your terminal command line using Composer:

          
php composer.phar require "mercadopago/dx-php"

        

To install the SDK, you must run the following code in your terminal command line using npm:

          
npm install Mercadopago

        

To install the SDK in your Maven project, you must add the following dependency to your pom.xml file and run the code maven install in your terminal command line:

          
<dependency>
<groupId>com.mercadopago</groupId>
<artifactId>sdk-java</artifactId>
<version>2.1.7</version>
</dependency>

        

To install the SDK, you must run the following code in your terminal command line using gem:

          
gem install Mercadopago-sdk

        

To install the SDK, you must run the following code in the command line of your terminal using NuGet:

          
nuget install Mercadopago-sdk

        

To install the SDK, you must run the following code in the command line of your terminal using pip:

          
pip3 install MercadoPago

        
          
go get -u github.com/mercadopago/sdk-go

        

Create preference

Server-Side

Preferences are sets of information that allow you to configure a product or service that you want to charge, such as price and quantity, as well as other settings related to the defined payment flow.

To create a preference, use one of the SDKs available below, filling in the attributes with the respective information.

          
<?php
// Mercado Pago SDK
use MercadoPago\MercadoPagoConfig;
// Add Your credentials
MercadoPagoConfig::setAccessToken("PROD_ACCESS_TOKEN");
?>

        
          
// Mercado Pago SDK
import { MercadoPagoConfig } from 'mercadopago';
// Add Your credentials
const client = new MercadoPagoConfig({ accessToken: 'YOUR_ACCESS_TOKEN' });

        
          
// Mercado Pago SDK
import com.mercadopago.MercadoPagoConfig;
// Add Your credentials
MercadoPagoConfig.setAccessToken("PROD_ACCESS_TOKEN");

        
          
# Mercado Pago SDK
require 'mercadopago'
# Add Your credentials
sdk = Mercadopago::SDK.new('PROD_ACCESS_TOKEN')

        
          
// Mercado Pago SDK
 using MercadoPago.Config;
 // Add Your credentials
MercadoPagoConfig.AccessToken = "PROD_ACCESS_TOKEN";

        
          
# Mercado Pago SDK
import mercadopago
# Add Your credentials
sdk = mercadopago.SDK("PROD_ACCESS_TOKEN")

        
          
import (
	"github.com/mercadopago/sdk-go/pkg/config"
)

cfg, err := config.New("{{ACCESS_TOKEN}}")
if err != nil {
	fmt.Println(err)
}

        

When you finish creating the preference, you need to configure it according to your product or service. To do so, use one of the codes available below, filling in the attributes with the respective information.

          
<?php
<?php
$client = new PreferenceClient();
$preference = $client->create([
  "items"=> array(
    array(
      "title" => "My product",
      "quantity" => 1,
      "unit_price" => 20000
    )
  )
]);
?>

        
          
const preference = new Preference(client);

preference.create({
  body: {
    items: [
      {
        title: 'My product',
        quantity: 1,
        unit_price: 20000
      }
    ],
  }
})
.then(console.log)
.catch(console.log);

        
          
 PreferenceItemRequest itemRequest =
       PreferenceItemRequest.builder()
           .id("1234")
           .title("Games")
           .description("PS5")
           .pictureUrl("http://picture.com/PS5")
           .categoryId("games")
           .quantity(2)
           .currencyId("BRL")
           .unitPrice(new BigDecimal("4000"))
           .build();
   List<PreferenceItemRequest> items = new ArrayList<>();
   items.add(itemRequest);
PreferenceRequest preferenceRequest = PreferenceRequest.builder()
.items(items).build();
PreferenceClient client = new PreferenceClient();
Preference preference = client.create(request);

        
          
# Create a preference request
preference_data = {
  items: [
    {
      title: 'My Item',
      unit_price: 75,
      quantity: 1
    }
  ]
}
preference_response = sdk.preference.create(preference_data)
preference = preference_response[:response]

# This value replaces the String "<%= @preference_id %>" in your HTML
@preference_id = preference['id']

        
          
// Create the preference request object
var request = new PreferenceRequest
{
    Items = new List<PreferenceItemRequest>
    {
        new PreferenceItemRequest
        {
            Title = "My Item",
            Quantity = 1,
            CurrencyId = "COP",
            UnitPrice = 75m,
        },
    },
};

// Create the preference using the client
var client = new PreferenceClient();
Preference preference = await client.CreateAsync(request);

        
          
# Create a preference object
preference_data = {
    "items": [
        {
            "title": "My Item",
            "quantity": 1,
            "unit_price": 75
            
        }
    ]
}

preference_response = sdk.preference().create(preference_data)
preference = preference_response["response"]

        
          
client := preference.NewClient(cfg)

request := preference.Request{
	Items: []preference.ItemRequest{
		{
			Title:       "My product",
			Quantity:    1,
			UnitPrice:   75.76,
		},
	},
}

resource, err := client.Create(context.Background(), request)
if err != nil {
	fmt.Println(err)
	return
}

fmt.Println(resource)

        
Important
The value of unit_price must be an integer.

Choosing the type of integration

Client-Side

With the SDK installed and configured correctly in your project, you are ready to proceed with the integration. To isso, choose the type of integration that best suits your needs, choose Web or Mobile, and follow the steps detailed in the section corresponding to the type of solution chosen

Checkout Pro for Web
Offer different payment methods to customers on a website in a simple, fast, and secure manner.
Checkout Pro for Mobile
Offer various payment methods to customers in your mobile application, using the language that best suits your project.