grability-mercadopago
v1.14.0
Published
library of connection with Mercadopago
Downloads
18
Readme
grability-mercadopago
librería de mercadopago
INSTALACION
yarn add grability-mercadopago o nmp install grability-mercadopago
CONFIGURACION
var config = {
access_token: 'APP_USR-1356144817810107-041315-666eb1a71c4992dddcbbf1959338c228-555555'
}
const mercadopago = new MercadopagoApiLibrary(config)
SERVICIOS
CREATE COSTUMER
var customer_data = { "email": "[email protected]" }
mercadopago.createCustomer(customer_data).then(function (customer) {
console.log("customer", customer)
}).catch(function (error) {
console.log(error)
});
GET CUSTOMER
var filters = {
id: "663680970-G5Exos6EA8yEzy"
//email: "[email protected]"
};
mercadopago.getCustomer(filters).then(function (data) {
console.log(data)
}).catch(function (error) {
console.log(error)
});
CREATE TOKEN CARD
var card_data = {
"cardNumber":"4013540682746260",
"cardholder":{
"name":"APRO"
},
"expirationYear":"2025",
"expirationMonth":"11",
"securityCode":"123"
}
mercadopago.createTokenCard(card_data).then(function (card) {
console.log("card", card)
}).catch(function (error) {
console.log(error)
});
REGISTRER CART TO CUSTOMER
var card_data = {
"token": "0428140938d9a0cf5bf875f2e942ae66",
"customer_id": "662569482-PUKyrlqZsEou9b"
}
mercadopago.registerCard(card_data).then(function (card) {
console.log("card", card)
}).catch(function (error) {
console.log(error)
});
GET CARD
var customerId = "662569482-PUKyrlqZsEou9b";
var cardId = "8949087302";
mercadopago.getCard(customerId, cardId).then(function (card) {
console.log("card", card)
}).catch(function (error) {
console.log(error)
});
GET CARDS CUSTOMER
var filters = {
//id: "662569482-PUKyrlqZsEou9b"
email: "[email protected]"
};
mercadopago.getCustomer(filters).then(function (data) {
console.log(data.response.results[0].cards)
}).catch(function (error) {
console.log(error)
});
PAYMENT WITH CARD TOKEN
var payment_data = {
"transaction_amount":7000,
"token":"0428140938d9a0cf5bf875f2e942ae66",
"description":"TEST",
"installments": 1,
"securityCode": 123,
"payment_method_id":"visa",
"payer":{
"email":"[email protected]"
},
"additional_info":{
"items":[
{
"id":"1",
"title":"Un super viaje con id 1",
"description":"Un super viaje para transportar mercancia",
"quantity":1,
"unit_price":5000
}
]
},
"statement_descriptor":"Merca"
}
mercadopago.paymentCreate(payment_data).then(function (response) {
console.log("response", response)
}).catch(function (error) {
console.log(error)
});
UPDATE CUSTOMER
var customer_data = {"id":"542014141-1o8M167znHgp5e", "first_name": "JESUS ALFONSO", "last_name": "ROMERO REVELO" }
mercadopago.updateCustomer(customer_data).then(function (customer) {
console.log("customer", customer)
}).catch(function (error) {
console.log(error)
});
DELETE CUSTOMER
mercadopago.removeCustomer("542014141-1o8M167znHgp5e").then(function (resp) {
console.log(resp)
}).catch(function (error) {
console.log(error)
});
PREFERENCE
var preference = {
"items": [
{
"id": "item-ID-1234",
"title": "Title of what you are paying for. It will be displayed in the payment process.",
"currency_id": "COP",
"picture_url": "https://www.mercadopago.com/org-img/MP3/home/logomp3.gif",
"description": "Item description",
"category_id": "art", // Available categories at https://api.mercadopago.com/item_categories
"quantity": 1,
"unit_price": 100
}
],
"payer": {
"name": "jesus",
"surname": "romero",
"email": "[email protected]",
"date_created": "2015-06-02T12:58:41.425-04:00",
"phone": {
"area_code": "11",
"number": 44444444
},
"identification": {
"type": "RUT", // Available ID types at https://api.mercadopago.com/v1/identification_types
"number": "12345678"
},
"address": {
"street_name": "Street",
"street_number": 123,
"zip_code": "5700"
}
},
"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,
"default_payment_method_id": "",
"default_installments": 2
},
"shipments": {
"receiver_address": {
"zip_code": "5700",
"street_number": 123,
"street_name": "Street",
"floor": "4",
"apartment": "C"
}
},
"notification_url": "https://www.your-site.com/ipn",
"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"
}
mercadopago.preferenceResponse(preference).then(function (data) {
console.log(data)
}).catch(function (error) {
console.log(error)
});
PAYMENT EFECTY
var payment_data = {
"transaction_amount": 5000,
"description": "Título del producto",
"payment_method_id": "efecty",
"payer": {
"email": "[email protected]"
}
};
mercadopago.paymentCreate(payment_data).then(function (resp) {
console.log(resp)
}).catch(function (error) {
console.log(error)
});
PAYMENT PSE
var payment_data = {
transaction_amount: 5000,
description: 'Título del producto',
payer: {
email: '[email protected]',
identification: {
type: "CC",
number: "76262349"
},
entity_type: "individual"
},
transaction_details: {
financial_institution: ""
},
additional_info: {
ip_address: "127.0.0.1"
},
callback_url: "http://www.tu-sitio.com",
payment_method_id: "pse"
}
mercadopago.paymentCreate(payment_data).then(function (resp) {
console.log(resp)
}).catch(function (error) {
console.log(error)
});
CANCEL PAYMENT
payment_data = {
id: 1230067887,
status: "cancelled"
}
mercadopago.cancelPayment(payment_data).then(function (resp) {
console.log(resp)
}).catch(function (error) {
console.log(error)
});
REFUND PAYMENT
var paymentId = 1230069151;
mercadopago.refundPayment(paymentId).then(function (resp) {
console.log(resp)
}).catch(function (error) {
console.log(error)
});
GET PAYMENT
var paymentId = 1230069151;
mercadopago.getPayment(paymentId).then(function (resp) {
console.log(resp)
}).catch(function (error) {
console.log(error)
});