Mercado Pago Wallet
The Mercado Pago Wallet is a payment method that allows you to accept payments only from registered users. By offering this option, users will be able to pay by card, available balance and Mercado Crédito.
Follow the steps below to configure the Mercado Pago Wallet as a payment method.
Create preference
Server-Side
The first step to configure payments with Mercado Pago Wallet is to create the preference. To do this, send a POST with the purpose
parameter and the wallet_purchase
value to the endpoint /checkout/preferences and execute the request or, if you prefer, use one of the SDKs below.
<?php
// Create a preference object
$preference = new MercadoPago\Preference();
// Create an item in the preference
$item = new MercadoPago\Item();
$item->title = 'My product';
$item->quantity = 1;
$item->unit_price = 75;
$preference->items = array($item);
$preference->purpose = 'wallet_purchase';
$preference->save();
?>
Wallet mode works by adding the purpose attribute to the preference.
// Create a preference object
let preference = {
items: [
{
title: 'My product',
unit_price: 100,
quantity: 1,
}
],
purpose: 'wallet_purchase'
};
Mercadopago.preferences.create(preference)
.then(function(response){
// This value will replace the string "<%= global.id %>" in your HTML
global.id = response.body.id;
}).catch(function(error){
console.log(error);
});
Wallet mode works by adding the purpose attribute to the preference.
// Create a preference object
PreferenceClient client = new PreferenceClient();
// Create an item in the preference
PreferenceItemRequest item =
PreferenceItemRequest.builder()
.title("My product")
.quantity(1)
.unitPrice(new BigDecimal("75"))
.build();
List<PreferenceItemRequest> items = new ArrayList<>();
items.add(item);
PreferenceRequest request =
PreferenceRequest.builder().items(items).purpose("wallet_purchase").build();
client.create(request);
Wallet mode works by adding the purpose attribute to the preference.
sdk = Mercadopago::SDK.new('ENV_ACCESS_TOKEN')
# Create a preference object
preference_data = {
items: [
{
title: 'My product',
unit_price: 100,
quantity: 1
}
],
purpose: 'wallet_purchase'
}
preference_response = sdk.preference.create(preference_data)
preference = preference_response[:response]
# This value will replace the string "<%= @preference_id %>" in your HTML
@preference_id = preference['id']
Wallet mode works by adding the purpose attribute to the preference.
// Create the preference request object
var request = new PreferenceRequest
{
Items = new List<PreferenceItemRequest>
{
new PreferenceItemRequest
{
Title = "My product,
quantity = 1,
CurrencyId = "CLP",
UnitPrice = 75m,
},
},
Purpose = "wallet_purchase",
};
// Create the preference
var client = new PreferenceClient();
Preference preference = await client.CreateAsync(request);
preference_data = {
"items": [
{
"title": "My product",
"unit_price": 100,
"quantity": 1
}
],
"purpose": "wallet_purchase"
}
preference_response = sdk.preference().create(preference_data)
preference = preference_response["response"]
Wallet mode works by adding the purpose attribute to the preference.
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": [
{
"title": "My product",
"quantity": 1,
"unit_price": 75
}
],
"purpose": "wallet_purchase"
}'
Add checkout
Client-Side
With the preference created, it is necessary to display the payment button that will allow the buyer to use the Mercado Pago Wallet as a payment method. To display the payment button, use the HTML below.
<div class="cho-container"></div>
<script src="https://sdk.mercadopago.com/js/v2"></script>
<script>
const mp = new MercadoPago('PUBLIC_KEY');
mp.checkout({
preference: {
id: 'YOUR_PREFERENCE_ID'
},
render: {
container: '.cho-container',
label: 'Pagar com Mercado Pago',
type: 'wallet',
}
});
</script>
Wallet mode works by adding the purpose attribute to the preference.