Receive Payments

Receive payments simply and securely using the Mercado Pago’s Checkout.

1. Create a payment preference

A payment preference contains all the information about the product or service to be paid. For example:

  • Description and amount.
  • Your buyer’s info (email, name, address, etc.).
  • Payment methods accepted.
  • Reference ID of your system.

To create a payment preference you must install Mercado Pago SDK and set up your credentials.

<?php  
  MercadoPago\SDK::setClientId("ENV_CLIENT_ID");
  MercadoPago\SDK::setClientSecret("ENV_CLIENT_SECRET");
?>
MercadoPago.SDK.setClientId("ENV_CLIENT_ID");
MercadoPago.SDK.setClientSecret("ENV_CLIENT_SECRET");
mercadopago.configure({
  client_id: 'ENV_CLIENT_ID',
  client_secret: 'ENV_CLIENT_SECRET'
});
MercadoPago::SDK.client_id = "ENV_CLIENT_ID"
MercadoPago::SDK.client_secret = "ENV_CLIENT_SECRET"
using MercadoPago;
// ...
MercadoPago.SDK.ClientId = "ENV_CLIENT_ID";
MercadoPago.SDK.ClientSecret = "ENV_CLIENT_SECRET";
// ...

Then, you must add the attributes of your payment preference and create a preference:

<?php
  # Create a preference object
  $preference = new MercadoPago\Preference();
  # Create an item object
  $item = new MercadoPago\Item();
  $item->id = "1234";
  $item->title = "Durable Paper Chair";
  $item->quantity = 2;
  $item->currency_id = "MXN";
  $item->unit_price = 5.61;
  # Create a payer object
  $payer = new MercadoPago\Payer();
  $payer->email = "rachelle@hotmail.com";
  # Setting preference properties
  $preference->items = array($item);
  $preference->payer = $payer;
  # Save and posting preference
  $preference->save();
?>
// Create a preference object
Preference preference = new Preference();
// Create an item object
Item item = new Item();
item.setId("1234")
    .setTitle("Durable Paper Chair")
    .setQuantity(2)
    .setCurrencyId("MXN")
    .setUnitPrice((float) 5.61);
// Create a payer object
Payer payer = new Payer();
payer.setEmail("rachelle@hotmail.com");
// Setting preference properties
preference.setPayer(payer);
preference.appendItem(item);
// Save and posting preference
preference.save();
// Create a preference structure
    var preference = {
    items: [
      item = {
        id: '1234',
        title: 'Durable Paper Chair',
        quantity: 2,
        currency_id: 'MXN',
        unit_price: 5.61
      }
    ],
    payer = {
      email: 'rachelle@hotmail.com'
    }
  };
 
  mercadopago.preferences.create(preference)
    .then(function (preference) {
      // Do something if preference has been created successfully
    }).catch(function (error) {
      // If an error has occurred
    });
# Create an item object
item = MercadoPago::Item.new({
  id:           "1234",
  title:        "Durable Paper Chair",
  quantity:     2,
  currency_id:  "MXN",
  unit_price:   5.61
})
# Create a payer object
payer = MercadoPago::Payer.new({
  email: "rachelle@hotmail.com"
}) 
# Create a preference object
preference = MercadoPago::Preference.new({
  items: [item],
  payer: payer
})
# Save and posting preference
preference.save()
using MercadoPago;
using MercadoPago.Resources;
using MercadoPago.DataStructures.Preference;
// ...
// Create a preference object
Preference preference = new Preference(); 
# Adding an item object
preference.Items.Add(
  new Item()
  {
    Id = "1234",
    Title = "Durable Paper Chair", 
    Quantity = 2,
    CurrencyId = "MXN",
    UnitPrice = (float)5.61
  }
);
// Setting a payer object as value for Payer property
preference.Payer = new Payer(){
  Email = "rachelle@hotmail.com"
}
// Save and posting preference
preference.Save();

Content of the preference

The more information you send us, the faster is the payment approval and the better is the experience for your users.

Payer

You must submit your buyer’s email. If you include information such as identification type or identification number, it will not be asked during the checkout.

<?php
  // ...
  $payer = new MercadoPago\Payer();
  $payer->name = "Charles";
  $payer->surname = "Bayer";
  $payer->email = "charles@hotmail.com";
  $payer->date_created = "2018-06-02T12:58:41.425-04:00";
  $payer->phone = array(
    "area_code" => "",
    "number" => "351-865-6389 x47018"
  );
  $payer->identification = array(
    "type" => "DNI",
    "number" => "12345678"
  );
  $payer->address = array(
    "street_name" => "Schuyler Islands",
    "street_number" => 1861,
    "zip_code" => "91114"
  );
  // ...
?>
// ...
Payer payer = new Payer();
payer.setName("Charles")
     .setSurname("Bayer")
     .setEmail("charles@hotmail.com")
     .setDateCreated("2018-06-02T12:58:41.425-04:00")
     .setPhone(new Phone()
        .setAreaCode("")
        .setPhoneNumber("351-865-6389 x47018"))
     .setIdentification(new Identification()
        .setType("DNI")
        .setNumber("12345678"))
     .setAddress(new Address()
        .setStreetName("Schuyler Islands")
        .setBuildingNumber("1861")
        .setZipCode("91114"));
// ...
// ...
var payer = {
  name: "Charles",
  surname: "Bayer",
  email: "charles@hotmail.com",
  date_created: "2015-06-02T12:58:41.425-04:00",
  phone: {
    area_code: "",
    number: "351-865-6389 x47018"
  },
  identification: {
    type: "DNI",
    number: "12345678"
  },
  address: {
    street_name: "Schuyler Islands",
    street_number: "1861",
    zip_code: "91114"
  }
}
// ...
# ...
payer = MercadoPago::Payer.new({
  name: "Charles"
  surname: "Bayer"
  email: "charles@hotmail.com"
  date_created: Time.now
  phone: MercadoPago::Phone.new({
    area_code: "",
    number: "351-865-6389 x47018"
  })
  identification: MercadoPago::Identification.new({
    type: "DNI",
    number: "12345678"
  })
  address: MercadoPago::Address.new ({
    street_name: "Schuyler Islands",
    street_number: "1861",
    zip_code: "91114"
  })
})
# ...
using MercadoPago;
using MercadoPago.Resources;
using MercadoPago.DataStructures.Preference;
// ...
Payer payer = new Payer()
{
    Name = "Charles",
    Surname = "Bayer",
    Email = "charles@hotmail.com",
    Phone = new Phone()
    {
        AreaCode = "",
        Number = "351-865-6389 x47018"
    },
    Identification = new Identification() 
    {
        Type = "DNI",
        Number = "12345678"
    },
    Address = new Address()
    {
        StreetName = "Schuyler Islands",
        StreetNumber = int.Parse("1861"),
        ZipCode = "91114"
    }
};
// ...

Shipments

<?php
  // ...
  $shipments = new MercadoPago\Shipments();
  $shipments->receiver_address = array(
        "zip_code" => "91114",
        "street_number" => 1861,
        "street_name" => "Schuyler Islands",
        "floor" => 3,
        "apartment" => "C"
  );
  // ...
?>
// ...
Shipments shipments = new Shipments();
shipments.setReceiverAddress(new ReceiverAddress()
  .setZipCode("91114")
  .setBuildingNumber("1861")
  .setStreetName("Schuyler Islands")
  .setFloor("3")
  .setApartment("C"));
// ...
// ...
var shipments = {
    receiver_address: {
        zip_code: 91114",
        street_number: 1861,
        street_name: "Schuyler Islands",
        floor: 3,
        apartment: "C"
    }
};
// ...
# ...
shipment = MercadoPago::Shipment.new(
  receiver_address: new MercadoPago::ReceiverAddress.new({
    zip_code: "91114",
    street_number: 1861,
    street_name: "Schuyler Islands",
    floor: 3,
    apartment: "C"
  })
})
# ... 
using MercadoPago;
using MercadoPago.Resources;
using MercadoPago.DataStructures.Preference;
// ...
Shipment shipment = new Shipment()
{
    ReceiverAddress = new ReceiverAddress()
    {
        ZipCode = "91114",
        StreetName = "Schuyler Islands",
        StreetNumber = int.Parse("1861"),
        Floor = "8",
        Apartment = "C"
    }
};
// ...

2. Take the buyer to checkout

Once the preference has been created, use the URL found in the attribute init_point of the response to create a payment button:

Html

<!DOCTYPE html>
<html>
    <head>
        <title>Pagar</title>
    </head>
    <body>
        <a href="<?php echo $preference->init_point; ?>">Pay</a>
    </body>
</html>

You can also customize the checkout by entering this Link

3. Enable payment notifications

Notifications are automatically sent to inform you of any new payments and status updates.

This will allow you to manage your inventories and keep your system synced.

To learn more about it, go to Notifications.

4. Cancel a payment

The payment methods available for payments in cash must be paid from 3 to 5 days depending on each one.

They do not expire automatically, so you’re required to cancel the payment after expiration.

5. Test the integration

You can test the integration before going into production, in order to check the operation and make all the adjustments you need.

For that, you must use test users and cards.

For more information, go to the Tests section.

La búsqueda no arrojó ningún resultado.

Verifica la la ortografía de los términos de búsqueda o prueba con otras palabras clave.