$ npm install mercadopago
Every method supports either promises and callbacks. For example:
var at = mp.getAccessToken ();
at.then (
function (accessToken) {
console.log (accessToken);
},
function (error) {
console.log (error);
});
is the same as:
mp.getAccessToken(function (err, accessToken){
if (err) {
console.log (err);
} else {
console.log (accessToken);
}
});
In order to use callbacks, simply pass a function as the last parameter.
- Get your CLIENT_ID and CLIENT_SECRET in the following address:
- Argentina: https://www.mercadopago.com/mla/herramientas/aplicaciones
- Brazil: https://www.mercadopago.com/mlb/ferramentas/aplicacoes
- México: https://www.mercadopago.com/mlm/herramientas/aplicaciones
- Venezuela: https://www.mercadopago.com/mlv/herramientas/aplicaciones
- Colombia: https://www.mercadopago.com/mco/herramientas/aplicaciones
- Chile: https://www.mercadopago.com/mlc/herramientas/aplicaciones
var MP = require ("mercadopago");
var mp = new MP ("CLIENT_ID", "CLIENT_SECRET");
mp.getPreference ("PREFERENCE_ID");
var preference = {
"items": [
{
"title": "Test",
"quantity": 1,
"currency_id": "USD",
"unit_price": 10.5
}
]
};
mp.createPreference (preference);
var preference = {
"items": [
{
"title": "Test Modified",
"quantity": 1,
"currency_id": "USD",
"unit_price": 20.4
}
]
};
mp.updatePreference ("PREFERENCE_ID", preference);
var filters = {
"id": null,
"site_id": null,
"external_reference": null
};
mp.searchPayment (filters)
.then (
function success (data) {
console.log (JSON.stringify (data, null, 4));
},
function error (err) {
console.log (err);
}
});
mp.getPayment (qs["id"])
.then (
function success (data) {
console.log (JSON.stringify (data, null, 4));
},
function error (err) {
console.log (err);
}
});
mp.cancelPayment ("ID");
mp.refundPayment ("ID");
- Get your ACCESS_TOKEN in the following address:
- Argentina: https://www.mercadopago.com/mla/account/credentials
- Brazil: https://www.mercadopago.com/mlb/account/credentials
- Mexico: https://www.mercadopago.com/mlm/account/credentials
- Venezuela: https://www.mercadopago.com/mlv/account/credentials
- Colombia: https://www.mercadopago.com/mco/account/credentials
var MP = require ("mercadopago");
var mp = new MP ("ACCESS_TOKEN");
mp.post ({
"uri": "/v1/payments",
"data": payment_data
}).then (...);
mp.post ({
"uri": "/v1/customers",
"data": {
"email": "email@test.com"
}
}).then (...);
mp.get ({
"uri": "/v1/customers/CUSTOMER_ID"
}).then (...);
- View more Custom checkout related APIs in Developers Site
- Argentina: https://www.mercadopago.com.ar/developers
- Brazil: https://www.mercadopago.com.br/developers
- Mexico: https://www.mercadopago.com.mx/developers
- Venezuela: https://www.mercadopago.com.ve/developers
- Colombia: https://www.mercadopago.com.co/developers
You can access any resource from the MercadoPago API using the generic methods. The basic structure is:
mp.method(request).then(...)
where request
can be:
{
"uri": "The resource URI, relative to https://api.mercadopago.com",
"params": "Optional. Key:Value object with parameters to be appended to the URL",
"data": "Optional. Object or String to be sent in POST and PUT requests",
"headers": "Optional. Key:Value object with custom headers, like content-type: application/x-www-form-urlencoded",
"authenticate": "Optional. Boolean to specify if the GET method has to authenticate with credentials before request. Set it to false when accessing public APIs"
}
Examples:
// Get a resource, with optional URL params. Also you can disable authentication for public APIs
mp.get ({
"uri": "/resource/uri",
"params": {params},
"authenticate": true
});
// Create a resource with "data" and optional URL params.
mp.post ({
"uri": "/resource/uri",
"data": data,
"params": {params}
});
// Update a resource with "data" and optional URL params.
mp.put ({
"uri": "/resource/uri",
"data": data,
"params": {params}
});
// Delete a resource with optional URL params.
mp.delete ({
"uri": "/resource/uri",
"params": {params}
});
For example, if you want to get the Sites list (no params and no authentication):
mp.get ({
"uri": "/sites",
"authenticate": false
}).then (function (sites) {
console.log (sites);
});