mercadopago
Advanced tools
Comparing version 0.5.0 to 1.0.0
@@ -1,25 +0,24 @@ | ||
var MP = require ("mercadopago"), | ||
config = require ("../../config"); | ||
var mercadopago = require('../../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
var preference = { | ||
items: [ | ||
{ | ||
title: 'Test', | ||
quantity: 1, | ||
currency_id: 'ARS', | ||
unit_price: 10.5 | ||
} | ||
] | ||
}; | ||
var preference = { | ||
"items": [ | ||
{ | ||
"title": "Test", | ||
"quantity": 1, | ||
"currency_id": "ARS", | ||
"unit_price": 10.5 | ||
} | ||
] | ||
}; | ||
mp.createPreference (preference, function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("checkout-buttons/basic-preference/button", {"preference": data}); | ||
} | ||
mercadopago.preferences.create(preference).then(function (data) { | ||
res.render('checkout-buttons/basic-preference/button', { | ||
preference: data | ||
}); | ||
}; | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; |
{ | ||
"client_id": "CLIENT_ID", | ||
"client_secret": "CLIENT_SECRET" | ||
"client_id": "545545474996086", | ||
"client_secret": "GaQGhYj58qsRWhp9CSQgsuyV2Mk3ONVg", | ||
"access_token": "TEST-545545474996086-010315-04b0f100ed5aeb57304e2926cebde76a__LB_LC__-239656545", | ||
"port": 8080 | ||
} |
@@ -1,19 +0,43 @@ | ||
var package = require("./package"), | ||
express = require("express"), | ||
app = express(), | ||
fs = require("fs"); | ||
var config = require('./config'); | ||
var express = require('express'); | ||
var fs = require('fs'); | ||
var bodyParser = require('body-parser'); | ||
var mercadopago = require('../index'); | ||
app.use(express.bodyParser()); | ||
// Create Express Application | ||
var app = express(); | ||
app.set("view engine", "jade"); | ||
// Add Body Parser Middleware | ||
app.use(bodyParser.urlencoded({ | ||
extended: true | ||
})); | ||
app.use(bodyParser.json()); | ||
// Set Jade as View Engine | ||
app.set('view engine', 'jade'); | ||
// Iniialize mercadopago SDK | ||
mercadopago.configure({ | ||
client_id: config.client_id, | ||
client_secret: config.client_secret | ||
}); | ||
app.get(/\/(.+)/, function (req, res) { | ||
if (fs.existsSync(req.params[0]+".js")) { | ||
require("./"+req.params[0]).run(req, res); | ||
} else { | ||
res.status(404).send(""); | ||
} | ||
var fileFromParameter = req.params[0] + '.js'; | ||
if (fs.existsSync(fileFromParameter)) { | ||
// Execute the file found | ||
require('./' + fileFromParameter).run(req, res); | ||
} else { | ||
// Return 404 | ||
res.status(404).render('404', { | ||
file: fileFromParameter | ||
}); | ||
} | ||
}); | ||
app.listen(8080); | ||
console.log("Running on port 8080"); | ||
// Start Express Application | ||
app.listen(config.port); | ||
console.log('Server running on port:', config.port); |
@@ -1,40 +0,13 @@ | ||
var MP = require ("../../project/lib/mercadopago"), | ||
config = require ("../config"); | ||
var mercadopago = require('../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
switch (req.param("topic")) { | ||
case "payment": | ||
mp.getPayment (req.param("id"), function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("jsonOutput", {"result": data}); | ||
} | ||
}); | ||
break; | ||
case "authorized_payment": | ||
mp.getAuthorizedPayment (req.param("id"), function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("jsonOutput", {"result": data}); | ||
} | ||
}); | ||
break; | ||
case "preapproval": | ||
mp.getPreapprovalPayment (req.param("id"), function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("jsonOutput", {"result": data}); | ||
} | ||
}); | ||
break; | ||
} | ||
}; | ||
mercadopago.ipn.manage(req).then(function (data) { | ||
res.render('jsonOutput', { | ||
result: data | ||
}); | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; |
@@ -5,11 +5,10 @@ { | ||
"repository": "", | ||
"author": "hcasatti <horacio.casatti@mercadolibre.com>", | ||
"author": "Ariel Rey <ariel.rey@mercadolibre.com>", | ||
"license": "BSD", | ||
"main": "index.js", | ||
"dependencies": { | ||
"mercadopago": "*", | ||
"jade": ">=0.27.0", | ||
"express": ">=3.0.0", | ||
"MD5": ">= 1.0.0" | ||
}, | ||
"main": "index.js" | ||
"body-parser": "^1.15.1", | ||
"jade": "^1.11.0", | ||
"express": "^4.14.0" | ||
} | ||
} |
@@ -1,22 +0,23 @@ | ||
var MP = require ("mercadopago"), | ||
config = require ("../config"); | ||
var mercadopago = require('../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
var filters = { | ||
range: 'date_created', | ||
begin_date: 'NOW-1MONTH', | ||
end_date: 'NOW', | ||
status: 'approved', | ||
operation_type: 'regular_payment' | ||
}; | ||
var filters = { | ||
"range": "date_created", | ||
"begin_date": "NOW-1MONTH", | ||
"end_date": "NOW", | ||
"status": "approved", | ||
"operation_type": "regular_payment" | ||
}; | ||
mp.searchPayment (filters, function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("payment-search/search-result", {"result": data}); | ||
} | ||
mercadopago.payment.search({ | ||
qs: filters | ||
}).then(function (data) { | ||
res.render('payment-search/search-result', { | ||
result: data | ||
}); | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; |
@@ -1,22 +0,23 @@ | ||
var MP = require ("mercadopago"), | ||
config = require ("../config"); | ||
var mercadopago = require('../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
var filters = { | ||
range: 'date_created', | ||
begin_date: mercadopago.utils.date.now().subtract(60).toString(), | ||
end_date: mercadopago.utils.date.now().toString(), | ||
payment_type_id: 'credit_card', | ||
operation_type: 'regular_payment' | ||
}; | ||
var filters = { | ||
"range": "date_created", | ||
"begin_date": "2011-10-21T00:00:00Z", | ||
"end_date": "2011-10-25T24:00:00Z", | ||
"payment_type": "credit_card", | ||
"operation_type": "regular_payment" | ||
}; | ||
mp.searchPayment (filters, function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("payment-search/search-result", {"result": data}); | ||
} | ||
mercadopago.payment.search({ | ||
qs: filters | ||
}).then(function (data) { | ||
res.render('payment-search/search-result', { | ||
result: data | ||
}); | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; |
@@ -1,20 +0,21 @@ | ||
var MP = require ("mercadopago"), | ||
config = require ("../config"); | ||
var mercadopago = require('../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
var filters = { | ||
installments: '12', | ||
description: 'product_name', | ||
operation_type: 'regular_payment' | ||
}; | ||
var filters = { | ||
"installments": "12", | ||
"reason": "product_name", | ||
"operation_type": "regular_payment" | ||
}; | ||
mp.searchPayment (filters, function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("payment-search/search-result", {"result": data}); | ||
} | ||
mercadopago.payment.search({ | ||
qs: filters | ||
}).then(function (data) { | ||
res.render('payment-search/search-result', { | ||
result: data | ||
}); | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; |
@@ -1,21 +0,21 @@ | ||
var MP = require ("mercadopago"), | ||
config = require ("../config"); | ||
var mercadopago = require('../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
var filters = { | ||
payer_email: 'test_user_3931694@testuser.com', | ||
begin_date: mercadopago.utils.date.now().subtract(60).toString(), | ||
end_date: mercadopago.utils.date.now().toString() | ||
}; | ||
var filters = { | ||
"payer_email": "mail02@mail02.com%20mail01@mail01.com", | ||
"begin_date": "2011-01-01T00:00:00Z", | ||
"end_date": "2011-02-01T00:00:00Z" | ||
}; | ||
mp.searchPayment (filters, function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("payment-search/search-result", {"result": data}); | ||
} | ||
mercadopago.searchPayment({ | ||
qs: filters | ||
}).then(function (data) { | ||
res.render('payment-search/search-result', { | ||
result: data | ||
}); | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; | ||
@@ -1,19 +0,20 @@ | ||
var MP = require ("mercadopago"), | ||
config = require ("../config"); | ||
var mercadopago = require('../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
var filters = { | ||
site_id: 'MLA', | ||
external_reference: 'BILL_001' | ||
}; | ||
var filters = { | ||
"site_id": "MLA", // Argentina: MLA; Brasil: MLB | ||
"external_reference": "BILL_001" | ||
}; | ||
mp.searchPayment (filters, function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("payment-search/search-result", {"result": data}); | ||
} | ||
mercadopago.payment.search({ | ||
qs: filters | ||
}).then(function (data) { | ||
res.render('payment-search/search-result', { | ||
result: data | ||
}); | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; |
@@ -1,29 +0,28 @@ | ||
var MP = require ("mercadopago"), | ||
config = require ("../config"); | ||
var mercadopago = require('../../index'); | ||
exports.run = function (req, res) { | ||
var mp = new MP (config.client_id, config.client_secret); | ||
var preapprovalPayment = { | ||
payer_email: 'test_user_3931694@testuser.com', | ||
back_url: 'http://www.google.com', | ||
reason: 'Monthly subscription to premium package', | ||
external_reference: 'OP-1234', | ||
auto_recurring: { | ||
frequency: 1, | ||
frequency_type: 'months', | ||
transaction_amount: 60, | ||
currency_id: 'ARS', | ||
start_date: mercadopago.utils.date.now().add(1).toString(), | ||
end_date: mercadopago.utils.date.now().add(3).toString() | ||
} | ||
}; | ||
var preapprovalPayment = { | ||
"payer_email": "my_customer@my_site.com", | ||
"back_url": "http://www.my_site.com", | ||
"reason": "Monthly subscription to premium package", | ||
"external_reference": "OP-1234", | ||
"auto_recurring": { | ||
"frequency": 1, | ||
"frequency_type": "months", | ||
"transaction_amount": 60, | ||
"currency_id": "BRL", | ||
"start_date": "2012-12-10T14:58:11.778-03:00", | ||
"end_date": "2013-06-10T14:58:11.778-03:00" | ||
} | ||
}; | ||
mp.createPreapprovalPayment (preapprovalPayment, function (err, data){ | ||
if (err) { | ||
res.send (err); | ||
} else { | ||
res.render ("preapproval-payments/button", {"preapproval": data}); | ||
} | ||
mercadopago.preapproval.create(preapprovalPayment).then(function (data) { | ||
res.render('preapproval-payments/button', { | ||
preapproval: data | ||
}); | ||
}; | ||
}).catch(function (error) { | ||
res.render('500', { | ||
error: error | ||
}); | ||
}); | ||
}; |
@@ -1,577 +0,74 @@ | ||
"use strict"; | ||
var configurations = require('./configurations'); | ||
var backwardSupport = require('./mercadopago-support')(); | ||
var utilsModule = require('./utils'); | ||
var paymentModule = require('./resources/payment'); | ||
var preferencesModule = require('./resources/preferences'); | ||
var preapprovalModule = require('./resources/preapproval'); | ||
var merchantOrdersModule = require('./resources/merchantOrders'); | ||
var moneyRequestsModule = require('./resources/moneyRequests'); | ||
var customersModule = require('./resources/customers'); | ||
var ipnModule = require('./resources/ipn'); | ||
var connectModule = require('./resources/connect'); | ||
var sdk; | ||
var resources; | ||
var p = require("../package"), | ||
request = require ("request"), | ||
Q = require ("q"); | ||
var config = { | ||
API_BASE_URL: "https://api.mercadopago.com", | ||
MIME_JSON: "application/json", | ||
MIME_FORM: "application/x-www-form-urlencoded" | ||
}; | ||
function MercadoPagoError(message, status) { | ||
this.name = "MercadoPagoError"; | ||
this.message = message || "MercadoPago Unknown error"; | ||
this.stack = (new Error()).stack; | ||
this.status = status || 500; | ||
function configure(options) { | ||
configurations.configure(options); | ||
} | ||
MercadoPagoError.prototype = Object.create(Error.prototype); | ||
MercadoPagoError.prototype.constructor = MercadoPagoError; | ||
// Backward compatibility method initialization | ||
sdk = module.exports = function () { | ||
var options = { | ||
// If it is the old version of the SDK, this support callbacks with Q library. This error isnt shown | ||
show_promise_error: false | ||
}; | ||
var MP = function () { | ||
var __llAccessToken, | ||
__clientId, | ||
__clientSecret, | ||
__sandbox = false; | ||
console.warn('This way of initializing the SDK is deprecated. Please change following the documentation'); | ||
if (arguments.length > 2 || arguments.length < 1) { | ||
throw new MercadoPagoError("Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN", 400); | ||
} | ||
if (arguments.length === 1) { | ||
options.access_token = arguments[0]; | ||
} else if (arguments.length === 2) { | ||
options.client_id = arguments[0]; | ||
options.client_secret = arguments[1]; | ||
} else { | ||
throw new Error('Invalid arguments. Use CLIENT_ID and CLIENT SECRET, or ACCESS_TOKEN'); | ||
} | ||
if (arguments.length == 1) { | ||
__llAccessToken = arguments[0]; | ||
} | ||
// Configure the SDK | ||
try { | ||
this.configure(options); | ||
} catch (error) { | ||
// Prevent double initialization error on client_id and client_secret | ||
} | ||
}; | ||
if (arguments.length == 2) { | ||
__clientId = arguments[0]; | ||
__clientSecret = arguments[1]; | ||
} | ||
// Instance creation | ||
var mp = {}; | ||
/** | ||
* Switch or get Sandbox Mode for Basic Checkout | ||
*/ | ||
mp.sandboxMode = function (enable) { | ||
if (enable !== null && enable !== undefined) { | ||
__sandbox = enable === true; | ||
} | ||
return __sandbox; | ||
}; | ||
/** | ||
* Get Access Token for API use | ||
*/ | ||
mp.getAccessToken = function () { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
var deferred = Q.defer(); | ||
if (__llAccessToken) { | ||
next && next(null, __llAccessToken); | ||
deferred.resolve (__llAccessToken); | ||
} else { | ||
MPRestClient.post({ | ||
"uri": "/oauth/token", | ||
"data": { | ||
"client_id": __clientId, | ||
"client_secret": __clientSecret, | ||
"grant_type": "client_credentials" | ||
}, | ||
"headers": { | ||
"Content-type": config.MIME_FORM | ||
} | ||
}).then ( | ||
function success (data) { | ||
next && next(null, data.response.access_token); | ||
deferred.resolve (data.response.access_token); | ||
}, | ||
function error (err) { | ||
next && next(err); | ||
deferred.reject (err); | ||
} | ||
); | ||
} | ||
return deferred.promise; | ||
}; | ||
/** | ||
Generic resource get | ||
@param req | ||
@param params (deprecated) | ||
@param authenticate = true (deprecated) | ||
*/ | ||
mp.get = function (req) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
var deferred = Q.defer(); | ||
if (typeof req == "string") { | ||
req = { | ||
"uri": req, | ||
"params": arguments[1], | ||
"authenticate": arguments[2] | ||
}; | ||
} | ||
req.authenticate = req.authenticate !== false; | ||
var auth = Q.Promise(function(resolve, reject) { | ||
if (req.authenticate) { | ||
resolve(mp.getAccessToken()); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
auth.then(function success(at) { | ||
if (at) { | ||
req.params || (req.params = {}); | ||
req.params.access_token = at; | ||
} | ||
MPRestClient.get(req).then ( | ||
function success (data) { | ||
next && next(null, data); | ||
deferred.resolve (data); | ||
}, | ||
function error (err) { | ||
next && next(err); | ||
deferred.reject (err); | ||
} | ||
); | ||
}, | ||
deferred.reject); | ||
return deferred.promise; | ||
}; | ||
/** | ||
Generic resource post | ||
@param req | ||
@param data (deprecated) | ||
@param params (deprecated) | ||
*/ | ||
mp.post = function (req) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
var deferred = Q.defer(); | ||
if (typeof req == "string") { | ||
req = { | ||
"uri": req, | ||
"data": arguments[1], | ||
"params": arguments[2] | ||
}; | ||
} | ||
req.authenticate = req.authenticate !== false; | ||
var auth = Q.Promise(function(resolve, reject) { | ||
if (req.authenticate) { | ||
resolve(mp.getAccessToken()); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
auth.then(function success(at) { | ||
if (at) { | ||
req.params || (req.params = {}); | ||
req.params.access_token = at; | ||
} | ||
MPRestClient.post(req).then ( | ||
function success (data) { | ||
next && next(null, data); | ||
deferred.resolve (data); | ||
}, | ||
function error (err) { | ||
next && next(err); | ||
deferred.reject (err); | ||
} | ||
); | ||
}, | ||
deferred.reject); | ||
return deferred.promise; | ||
}; | ||
/** | ||
Generic resource put | ||
@param req | ||
@param data (deprecated) | ||
@param params (deprecated) | ||
*/ | ||
mp.put = function (req) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
var deferred = Q.defer(); | ||
if (typeof req == "string") { | ||
req = { | ||
"uri": req, | ||
"data": arguments[1], | ||
"params": arguments[2] | ||
}; | ||
} | ||
req.authenticate = req.authenticate !== false; | ||
var auth = Q.Promise(function(resolve, reject) { | ||
if (req.authenticate) { | ||
resolve(mp.getAccessToken()); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
auth.then(function success(at) { | ||
if (at) { | ||
req.params || (req.params = {}); | ||
req.params.access_token = at; | ||
} | ||
MPRestClient.put(req).then ( | ||
function success (data) { | ||
next && next(null, data); | ||
deferred.resolve (data); | ||
}, | ||
function error (err) { | ||
next && next(err); | ||
deferred.reject (err); | ||
} | ||
); | ||
}, | ||
deferred.reject); | ||
return deferred.promise; | ||
}; | ||
/** | ||
Generic resource delete | ||
@param req | ||
@param params (deprecated) | ||
*/ | ||
mp.delete = function (req) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
var deferred = Q.defer(); | ||
if (typeof req == "string") { | ||
req = { | ||
"uri": req, | ||
"params": arguments[1] | ||
}; | ||
} | ||
req.authenticate = req.authenticate !== false; | ||
var auth = Q.Promise(function(resolve, reject) { | ||
if (req.authenticate) { | ||
resolve(mp.getAccessToken()); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
auth.then(function success(at) { | ||
if (at) { | ||
req.params || (req.params = {}); | ||
req.params.access_token = at; | ||
} | ||
MPRestClient.delete(req).then ( | ||
function success (data) { | ||
next && next(null, data); | ||
deferred.resolve (data); | ||
}, | ||
function error (err) { | ||
next && next(err); | ||
deferred.reject (err); | ||
} | ||
); | ||
}, | ||
deferred.reject); | ||
return deferred.promise; | ||
}; | ||
// Backward compatibility | ||
/** | ||
Create a checkout preference | ||
@param preference | ||
@return json | ||
*/ | ||
mp.createPreference = function (preference){ | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.post ({ | ||
"uri": "/checkout/preferences", | ||
"data": preference | ||
}, next); | ||
}; | ||
/** | ||
Update a checkout preference | ||
@param id | ||
@param preference | ||
@return json | ||
*/ | ||
mp.updatePreference = function (id, preference) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.put ({ | ||
"uri": "/checkout/preferences/"+id, | ||
"data": preference | ||
}, next); | ||
}; | ||
/** | ||
Get a checkout preference | ||
@param id | ||
@return json | ||
*/ | ||
mp.getPreference = function (id) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.get ({ | ||
"uri": "/checkout/preferences/"+id | ||
},next); | ||
}; | ||
/** | ||
Create a preapproval payment | ||
@param preapprovalPayment | ||
@return json | ||
*/ | ||
mp.createPreapprovalPayment = function (preapprovalPayment){ | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.post ({ | ||
"uri": "/preapproval", | ||
"data": preapprovalPayment | ||
}, next) | ||
}; | ||
/** | ||
Update a preapproval payment | ||
@param preapprovalPayment | ||
@return json | ||
*/ | ||
mp.updatePreapprovalPayment = function (id, preapprovalPayment){ | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.put ({ | ||
"uri": "/preapproval/"+id, | ||
"data": preapprovalPayment | ||
}, next) | ||
}; | ||
/** | ||
Get a preapproval payment | ||
@param id | ||
@return json | ||
*/ | ||
mp.getPreapprovalPayment = function (id) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.get ({ | ||
"uri": "/preapproval/"+id | ||
}, next); | ||
}; | ||
/** | ||
Search payments according to filters, with pagination | ||
@param filters | ||
@param offset | ||
@param limit | ||
@return json | ||
*/ | ||
mp.searchPayment = function (filters, offset, limit) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
if (!isNaN(offset)) { | ||
filters.offset = offset; | ||
} | ||
if (!isNaN(limit)) { | ||
filters.limit = limit; | ||
} | ||
var uriPrefix = this.__sandbox ? "/sandbox" : ""; | ||
return mp.get ({ | ||
"uri": uriPrefix+"/collections/search", | ||
"params": filters | ||
}, next); | ||
}; | ||
/** | ||
Get information for specific payment | ||
@param id | ||
@return json | ||
*/ | ||
mp.getPayment = mp.getPaymentInfo = function (id) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
var uriPrefix = this.__sandbox ? "/sandbox" : ""; | ||
return mp.get ({ | ||
"uri": uriPrefix+"/collections/notifications/"+id | ||
}, next); | ||
}; | ||
/** | ||
Get information for specific authorized payment | ||
@param id | ||
@return json | ||
*/ | ||
mp.getAuthorizedPayment = function (id) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.get ({ | ||
"uri": "/authorized_payments/"+id | ||
}, next); | ||
}; | ||
/** | ||
Refund accredited payment | ||
@param id | ||
@return json | ||
*/ | ||
mp.refundPayment = function (id) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.put ({ | ||
"uri": "/collections/"+id, | ||
"data": { | ||
"status": "refunded" | ||
} | ||
}, next); | ||
}; | ||
/** | ||
Cancel pending payment | ||
@param id | ||
@return json | ||
*/ | ||
mp.cancelPayment = function (id) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.put ({ | ||
"uri": "/collections/"+id, | ||
"data": { | ||
"status": "cancelled" | ||
} | ||
}, next); | ||
}; | ||
/** | ||
Cancel preapproval payment | ||
@param id | ||
@return json | ||
*/ | ||
mp.cancelPreapprovalPayment = function (id) { | ||
var next = typeof (arguments[arguments.length -1]) == "function" ? arguments[arguments.length -1] : null; | ||
return mp.put ({ | ||
"uri": "/preapproval/"+id, | ||
"data": { | ||
"status": "cancelled" | ||
} | ||
}, next); | ||
}; | ||
// Instance return | ||
return mp; | ||
// When support is gone this is going to be the return literal from this class | ||
resources = { | ||
configure: configure, | ||
utils: utilsModule, | ||
configurations: configurations, | ||
payment: paymentModule, | ||
preferences: preferencesModule, | ||
preapproval: preapprovalModule, | ||
merchant_orders: merchantOrdersModule, | ||
customers: customersModule, | ||
ipn: ipnModule, | ||
connect: connectModule, | ||
money_requests: moneyRequestsModule | ||
}; | ||
MP.version = p.version; | ||
// Adding modules to prototype and a static method - This is going to be delete | ||
Object.keys(resources).forEach(function (key) { | ||
sdk[key] = resources[key]; | ||
// /*************************************************************************/ | ||
/* istanbul ignore next */ | ||
sdk.prototype[key] = resources[key]; | ||
}); | ||
var MPRestClient = (function() { | ||
function buildRequest (req) { | ||
var request = {}; | ||
// Adding modules to prototype and a static method from support module - This is going to be delete | ||
Object.keys(backwardSupport).forEach(function (key) { | ||
sdk[key] = backwardSupport[key]; | ||
request.uri = config.API_BASE_URL + req.uri; | ||
request.method = req.method || "GET"; | ||
req.headers || (req.headers = {}); | ||
request.headers = { | ||
"user-agent": "MercadoPago Node.js SDK v"+MP.version, | ||
"accept": config.MIME_JSON, | ||
"content-type": config.MIME_JSON | ||
}; | ||
Object.keys(req.headers).map(function (h) { | ||
request.headers[h.toLowerCase()] = req.headers[h]; | ||
}); | ||
if (req.data) { | ||
if (request.headers["content-type"] == config.MIME_JSON) { | ||
request.json = req.data; | ||
} else { | ||
request.form = req.data; | ||
} | ||
} | ||
if (req.params) { | ||
request.qs = req.params; | ||
} | ||
request.strictSSL = true; | ||
return request; | ||
} | ||
function exec (req) { | ||
var deferred = Q.defer(); | ||
req = buildRequest(req); | ||
request(req, function(error, response, body) { | ||
if (error) { | ||
deferred.reject (new MercadoPagoError(error)); | ||
} else if (response.statusCode < 200 || response.statusCode >= 300) { | ||
deferred.reject (new MercadoPagoError(body ? body.message || body : "Unknown", response.statusCode)); | ||
} else { | ||
try { | ||
(typeof body == "string") && (body = JSON.parse(body)); | ||
} catch (e) { | ||
deferred.reject(new MercadoPagoError ("Bad response")); | ||
} | ||
deferred.resolve ({ | ||
"status": response.statusCode, | ||
"response": body | ||
}); | ||
} | ||
}); | ||
return deferred.promise; | ||
} | ||
// Instance creation | ||
var restclient = {}; | ||
restclient.get = function (req) { | ||
req.method = "GET"; | ||
return exec(req); | ||
}; | ||
restclient.post = function (req) { | ||
req.method = "POST"; | ||
return exec(req); | ||
}; | ||
restclient.put = function (req) { | ||
req.method = "PUT"; | ||
return exec(req); | ||
}; | ||
restclient.delete = function (req) { | ||
req.method = "DELETE"; | ||
return exec(req); | ||
}; | ||
return restclient; | ||
})(); | ||
module.exports = MP; | ||
module.exports.MercadoPagoError = MercadoPagoError; | ||
/* istanbul ignore next */ | ||
sdk.prototype[key] = backwardSupport[key]; | ||
}); |
{ | ||
"name": "mercadopago", | ||
"version": "0.5.0", | ||
"author": "Horacio Casatti <horacio.casatti@mercadolibre.com>", | ||
"description": "Mercadopago SDK module for Payments integration", | ||
"main": "./lib/mercadopago.js", | ||
"scripts": { | ||
"test": "./node_modules/.bin/istanbul test ./node_modules/.bin/_mocha -- -R spec" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mercadopago/sdk-nodejs.git" | ||
}, | ||
"keywords": [ | ||
"api", | ||
"mercadopago", | ||
"checkout", | ||
"payment", | ||
"ipn", | ||
"sdk", | ||
"integration" | ||
], | ||
"dependencies": { | ||
"q": ">=1.1.2", | ||
"request": ">=2.48.0" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "^0.3.17", | ||
"mocha": "^2.2.5" | ||
}, | ||
"engine": { | ||
"node": ">=0.6" | ||
} | ||
} | ||
"name": "mercadopago", | ||
"version": "1.0.0", | ||
"publishConfig": { | ||
"tag": "beta" | ||
}, | ||
"description": "Mercadopago SDK for Node.js", | ||
"main": "index.js", | ||
"scripts": { | ||
"lint": "NODE_ENV=test eslint lib/*.js", | ||
"coverage": "NODE_ENV=test istanbul cover ./node_modules/mocha/bin/_mocha ./test/*.*", | ||
"coveralls": "npm run coverage -- --report lcovonly && cat ./coverage/lcov.info | coveralls", | ||
"test": "NODE_ENV=test mocha ./test/*.*" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mercadopago/px-nodejs.git" | ||
}, | ||
"keywords": [ | ||
"api", | ||
"mercadopago", | ||
"checkout", | ||
"payment", | ||
"ipn", | ||
"sdk", | ||
"integration" | ||
], | ||
"author": "Ariel Rey <ariel.rey@mercadolibre.com>", | ||
"bugs": { | ||
"url": "https://github.com/mercadopago/px-nodejs/issues" | ||
}, | ||
"homepage": "https://github.com/mercadopago/px-nodejs#readme", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.15", | ||
"eslint": "^3.13.1", | ||
"eslint-config-airbnb-base": "^11.0.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^3.2.0", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"sinon": "^1.17.7" | ||
}, | ||
"dependencies": { | ||
"ajv": "^4.10.3", | ||
"bluebird": "^3.4.7", | ||
"chai-as-promised": "^6.0.0", | ||
"moment": "^2.17.1", | ||
"request": "^2.79.0", | ||
"request-etag": "^2.0.3", | ||
"uuid": "^3.0.1" | ||
} | ||
} |
280
README.md
@@ -1,266 +0,94 @@ | ||
# MercadoPago SDK module for Payments integration | ||
[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/mercadopago/px-nodejs) | ||
[![Build Status](https://img.shields.io/travis/mercadopago/px-nodejs/master.svg)](https://travis-ci.org/mercadopago/px-nodejs) | ||
[![Coverage Status](https://coveralls.io/repos/github/mercadopago/px-nodejs/badge.svg?branch=master)](https://coveralls.io/github/mercadopago/px-nodejs?branch=master) | ||
[![NPM Version](https://img.shields.io/npm/v/mercadopago.svg)](http://npmjs.com/package/mercadopago) | ||
[![Downloads](https://img.shields.io/npm/dt/mercadopago.svg)](http://npmjs.com/package/mercadopago) | ||
* [Install](#install) | ||
* [Basic checkout](#basic-checkout) | ||
* [Customized checkout](#custom-checkout) | ||
* [Generic methods](#generic-methods) | ||
![](http://i66.tinypic.com/2nw1q28.png) | ||
<a name="install"></a> | ||
## Install | ||
# MercadoPago Node.js SDK | ||
``` | ||
$ npm install mercadopago | ||
``` | ||
This library provides developers with a simple set of bindings to the MercadoPago API. You can read the full [documentation here](https://github.com/mercadopago/px-nodejs/wiki). | ||
### Promises and Callbacks support | ||
### Node.js Versions Support | ||
Every method supports either promises and callbacks. For example: | ||
The SDK Supports Node.js from version v0 to latest (v7). | ||
```javascript | ||
var at = mp.getAccessToken (); | ||
### Backward Compatiblity | ||
at.then ( | ||
function (accessToken) { | ||
console.log (accessToken); | ||
}, | ||
function (error) { | ||
console.log (error); | ||
}); | ||
``` | ||
is the same as: | ||
If you implemented the [previous SDK](https://github.com/mercadopago/sdk-nodejs), you don't need to do **anything**. Just update the NPM Package and you will received all of the [previous methods](https://github.com/mercadopago/px-nodejs/wiki/Backward-Compatibility). | ||
```javascript | ||
mp.getAccessToken(function (err, accessToken){ | ||
if (err) { | ||
console.log (err); | ||
} else { | ||
console.log (accessToken); | ||
} | ||
}); | ||
``` | ||
### Installation | ||
In order to use callbacks, simply pass a function as the last parameter. | ||
<a name="basic-checkout"></a> | ||
## Basic checkout | ||
### Configure your credentials | ||
* Get your **CLIENT_ID** and **CLIENT_SECRET** in the following address: | ||
* Argentina: [https://www.mercadopago.com/mla/herramientas/aplicaciones](https://www.mercadopago.com/mla/herramientas/aplicaciones) | ||
* Brazil: [https://www.mercadopago.com/mlb/ferramentas/aplicacoes](https://www.mercadopago.com/mlb/ferramentas/aplicacoes) | ||
* México: [https://www.mercadopago.com/mlm/herramientas/aplicaciones](https://www.mercadopago.com/mlm/herramientas/aplicaciones) | ||
* Venezuela: [https://www.mercadopago.com/mlv/herramientas/aplicaciones](https://www.mercadopago.com/mlv/herramientas/aplicaciones) | ||
* Colombia: [https://www.mercadopago.com/mco/herramientas/aplicaciones](https://www.mercadopago.com/mco/herramientas/aplicaciones) | ||
* Chile: [https://www.mercadopago.com/mlc/herramientas/aplicaciones](https://www.mercadopago.com/mlc/herramientas/aplicaciones) | ||
```javascript | ||
var MP = require ("mercadopago"); | ||
var mp = new MP ("CLIENT_ID", "CLIENT_SECRET"); | ||
``` | ||
### Preferences | ||
#### Get an existent Checkout preference | ||
```javascript | ||
mp.getPreference ("PREFERENCE_ID"); | ||
$ npm install mercadopago@beta | ||
``` | ||
#### Create a Checkout preference | ||
or saving your dependency on your package.json | ||
```javascript | ||
var preference = { | ||
"items": [ | ||
{ | ||
"title": "Test", | ||
"quantity": 1, | ||
"currency_id": "USD", | ||
"unit_price": 10.5 | ||
} | ||
] | ||
}; | ||
mp.createPreference (preference); | ||
``` | ||
#### Update an existent Checkout preference: | ||
```javascript | ||
var preference = { | ||
"items": [ | ||
{ | ||
"title": "Test Modified", | ||
"quantity": 1, | ||
"currency_id": "USD", | ||
"unit_price": 20.4 | ||
} | ||
] | ||
}; | ||
mp.updatePreference ("PREFERENCE_ID", preference); | ||
$ npm install --save mercadopago@beta | ||
``` | ||
### Payments/Collections | ||
### Credentials | ||
#### Search for payments | ||
Before you use the SDK, you need to get your credentials from the following address: | ||
```javascript | ||
var filters = { | ||
"id": null, | ||
"site_id": null, | ||
"external_reference": null | ||
}; | ||
* Argentina: [https://www.mercadopago.com/mla/account/credentials](https://www.mercadopago.com/mla/account/credentials) | ||
* Brazil: [https://www.mercadopago.com/mlb/account/credentials](https://www.mercadopago.com/mlb/account/credentials) | ||
* Mexico: [https://www.mercadopago.com/mlm/account/credentials](https://www.mercadopago.com/mlm/account/credentials) | ||
* Venezuela: [https://www.mercadopago.com/mlv/account/credentials](https://www.mercadopago.com/mlv/account/credentials) | ||
* Colombia: [https://www.mercadopago.com/mco/account/credentials](https://www.mercadopago.com/mco/account/credentials) | ||
mp.searchPayment (filters) | ||
.then ( | ||
function success (data) { | ||
console.log (JSON.stringify (data, null, 4)); | ||
}, | ||
function error (err) { | ||
console.log (err); | ||
} | ||
}); | ||
``` | ||
> We highly recomend using only the access_token. If you provide the client_id and client_secret it's going to generate the access_token anyway (only on Production, for Sandbox use access_token). | ||
#### Get payment data | ||
### Quick Start | ||
```javascript | ||
mp.getPayment (qs["id"]) | ||
.then ( | ||
function success (data) { | ||
console.log (JSON.stringify (data, null, 4)); | ||
}, | ||
function error (err) { | ||
console.log (err); | ||
} | ||
}); | ||
``` | ||
First you need to require the library | ||
#### Cancel (only for pending payments) | ||
```javascript | ||
mp.cancelPayment ("ID"); | ||
var mercadopago = require('mercadopago'); | ||
``` | ||
#### Refund (only for accredited payments) | ||
Then you need to configure it with your credentials: | ||
```javascript | ||
mp.refundPayment ("ID"); | ||
mercadopago.configure({ | ||
access_token: 'ACCESS_TOKEN' | ||
}); | ||
``` | ||
<a name="custom-checkout"></a> | ||
## Customized checkout | ||
You **don't need to instantiate** mercadopago. It's a global singleton accross your application. Just require the sdk in any other file and it's already configure with your credentials. | ||
### Configure your credentials | ||
## Operations & Resources | ||
* Get your **ACCESS_TOKEN** in the following address: | ||
* Argentina: [https://www.mercadopago.com/mla/account/credentials](https://www.mercadopago.com/mla/account/credentials) | ||
* Brazil: [https://www.mercadopago.com/mlb/account/credentials](https://www.mercadopago.com/mlb/account/credentials) | ||
* Mexico: [https://www.mercadopago.com/mlm/account/credentials](https://www.mercadopago.com/mlm/account/credentials) | ||
* Venezuela: [https://www.mercadopago.com/mlv/account/credentials](https://www.mercadopago.com/mlv/account/credentials) | ||
* Colombia: [https://www.mercadopago.com/mco/account/credentials](https://www.mercadopago.com/mco/account/credentials) | ||
* [Payment](https://github.com/mercadopago/px-nodejs/wiki/Payment) | ||
* [Preferences](https://github.com/mercadopago/px-nodejs/wiki/Preferences) | ||
* [Pre Approval](https://github.com/mercadopago/px-nodejs/wiki/Pre-Approval) | ||
* [Customers & Cards](https://github.com/mercadopago/px-nodejs/wiki/Customers-&-Cards) | ||
* [Merchant Orders](https://github.com/mercadopago/px-nodejs/wiki/Merchant-Orders) | ||
* [Money Requests](https://github.com/mercadopago/px-nodejs/wiki/Money-Requests) | ||
* [MercadoPago Connect](https://github.com/mercadopago/px-nodejs/wiki/MercadoPago-Connect) | ||
* [IPN Notifications](https://github.com/mercadopago/px-nodejs/wiki/IPN-Notifications) | ||
```javascript | ||
var MP = require ("mercadopago"); | ||
## Examples | ||
var mp = new MP ("ACCESS_TOKEN"); | ||
``` | ||
In the examples folder you will find a web application. In this you can try some examples. For more information read the documentation [here](https://github.com/mercadopago/px-nodejs/tree/master/examples) | ||
### Create payment | ||
### Testing | ||
```javascript | ||
mp.post ({ | ||
"uri": "/v1/payments", | ||
"data": payment_data | ||
}).then (...); | ||
``` | ||
This project is tested using: | ||
### Create customer | ||
- Mocha | ||
- Chai | ||
- Sinon | ||
```javascript | ||
mp.post ({ | ||
"uri": "/v1/customers", | ||
"data": { | ||
"email": "email@test.com" | ||
} | ||
}).then (...); | ||
``` | ||
You can see the current covertura [here](https://coveralls.io/github/mercadopago/px-nodejs?branch=master). | ||
### Get customer | ||
### Links | ||
* [Documentation](https://github.com/mercadopago/px-nodejs/wiki) | ||
* [API Documentation](http://developers.mercadopago.com) | ||
```javascript | ||
mp.get ({ | ||
"uri": "/v1/customers/CUSTOMER_ID" | ||
}).then (...); | ||
``` | ||
### License | ||
* View more Custom checkout related APIs in Developers Site | ||
* Argentina: [https://www.mercadopago.com.ar/developers](https://www.mercadopago.com.ar/developers) | ||
* Brazil: [https://www.mercadopago.com.br/developers](https://www.mercadopago.com.br/developers) | ||
* Mexico: [https://www.mercadopago.com.mx/developers](https://www.mercadopago.com.mx/developers) | ||
* Venezuela: [https://www.mercadopago.com.ve/developers](https://www.mercadopago.com.ve/developers) | ||
* Colombia: [https://www.mercadopago.com.co/developers](https://www.mercadopago.com.co/developers) | ||
<a name="generic-methods"></a> | ||
## Generic methods | ||
You can access any resource from the [MercadoPago API](https://api.mercadopago.com) using the generic methods. | ||
The basic structure is: | ||
`mp.method(request).then(...)` | ||
where `request` can be: | ||
```javascript | ||
{ | ||
"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: | ||
```javascript | ||
// 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): | ||
```javascript | ||
mp.get ({ | ||
"uri": "/sites", | ||
"authenticate": false | ||
}).then (function (sites) { | ||
console.log (sites); | ||
}); | ||
``` | ||
Copyright © 2017. |
@@ -1,87 +0,127 @@ | ||
var MP = require("../lib/mercadopago"), | ||
assert = require("assert"), | ||
credentials = require("./credentials"); | ||
/* eslint-env node, mocha */ | ||
var chai = require('chai'); | ||
var sinon = require('sinon'); | ||
var chaiAsPromised = require('chai-as-promised'); | ||
var Promise = require('bluebird'); | ||
var assert = chai.assert; | ||
var preapprovalModule = require('../lib/resources/preapproval'); | ||
process.setMaxListeners(0); | ||
chai.use(chaiAsPromised); | ||
describe("Preapproval", function(){ | ||
var mp; | ||
before ("Instantitate MP", function () { | ||
mp = new MP(credentials.client_id, credentials.client_secret); | ||
}); | ||
describe('Preapproval Resource', function () { | ||
it('Cancel', function () { | ||
var promise; | ||
var promiseCallback; | ||
var promiseObjectArg; | ||
var callback = sinon.spy(); | ||
it("Should create, get and update a preapproval", function(done) { | ||
this.timeout(10000); | ||
var stub = sinon.stub(preapprovalModule, 'update', function (id, putCallback) { | ||
return new Promise(function (resolve) { | ||
resolve({}); | ||
return putCallback.apply(null, [null, {}]); | ||
}); | ||
}); | ||
var preferenceData = { | ||
"payer_email": "my_customer@my_site.com", | ||
"back_url": "https://www.testpreapproval.com/back_url", | ||
"reason": "Preapproval preference", | ||
"external_reference": "OP-1234", | ||
"auto_recurring": { | ||
"frequency": 1, | ||
"frequency_type": "months", | ||
"transaction_amount": 60, | ||
"currency_id": "ARS" | ||
} | ||
}; | ||
promise = preapprovalModule.cancel(1); | ||
mp.createPreapprovalPayment(preferenceData).then( | ||
function (preference) { | ||
try { | ||
assert.equal(preference.status, 201); | ||
assert.isFulfilled(promise); | ||
assert.equal(preference.response.payer_email, "my_customer@my_site.com", "Payer email"); | ||
assert.equal(preference.response.reason, "Preapproval preference", "Reason"); | ||
assert.equal(preference.response.external_reference, "OP-1234", "External reference"); | ||
} catch(e) { | ||
return done(e); | ||
} | ||
promise.then(function(response){ | ||
var stubArgs = stub.args[0][0]; | ||
mp.getPreapprovalPayment(preference.response.id).then ( | ||
function (preference) { | ||
try { | ||
assert.equal(preference.status, 200); | ||
} catch(e) { | ||
return done(e); | ||
} | ||
assert.isTrue(stub.called); | ||
assert.equal(JSON.stringify(response), JSON.stringify({})); | ||
assert.equal(stubArgs.id, 1); | ||
assert.equal(stubArgs.status, 'cancelled'); | ||
}); | ||
var preferenceData = { | ||
"reason": "Preapproval preference updated", | ||
"external_reference": "OP-5678" | ||
}; | ||
promiseCallback = preapprovalModule.cancel(1, callback); | ||
mp.updatePreapprovalPayment(preference.response.id, preferenceData).then ( | ||
function (preference) { | ||
try { | ||
assert.equal(preference.status, 200); | ||
} catch(e) { | ||
return done(e); | ||
} | ||
assert.isFulfilled(promiseCallback); | ||
mp.getPreapprovalPayment(preference.response.id).then ( | ||
function (preference) { | ||
try { | ||
assert.equal(preference.response.payer_email, "my_customer@my_site.com", "Payer email"); | ||
assert.equal(preference.response.reason, "Preapproval preference updated", "Reason"); | ||
assert.equal(preference.response.external_reference, "OP-5678", "External reference"); | ||
} catch(e) { | ||
return done(e); | ||
} | ||
promiseCallback.then(function(response){ | ||
var callbackResponse = callback.args[0][1]; | ||
done (); | ||
}, | ||
done | ||
); | ||
}, | ||
done | ||
); | ||
}, | ||
done | ||
); | ||
}, | ||
done | ||
); | ||
}); | ||
}); | ||
assert.equal(JSON.stringify(callbackResponse), JSON.stringify({})); | ||
assert.isTrue(callback.called); | ||
assert.isTrue(stub.called); | ||
assert.equal(JSON.stringify(response), JSON.stringify({})); | ||
}); | ||
promiseObjectArg = preapprovalModule.cancel({ | ||
id: 1 | ||
}); | ||
assert.isFulfilled(promiseObjectArg); | ||
promise.then(function(response){ | ||
var stubArgs = stub.args[0][0]; | ||
assert.isTrue(stub.called); | ||
assert.equal(JSON.stringify(response), JSON.stringify({})); | ||
assert.equal(stubArgs.id, 1); | ||
assert.equal(stubArgs.status, 'cancelled'); | ||
}); | ||
stub.restore(); | ||
}); | ||
it('Refund', function () { | ||
var promise; | ||
var promiseCallback; | ||
var promiseObjectArg; | ||
var callback = sinon.spy(); | ||
var stub = sinon.stub(preapprovalModule, 'update', function (id, putCallback) { | ||
return new Promise(function (resolve) { | ||
resolve({}); | ||
return putCallback.apply(null, [null, {}]); | ||
}); | ||
}); | ||
promise = preapprovalModule.pause(1); | ||
assert.isFulfilled(promise); | ||
promise.then(function(response){ | ||
var stubArgs = stub.args[0][0]; | ||
assert.isTrue(stub.called); | ||
assert.equal(JSON.stringify(response), JSON.stringify({})); | ||
assert.equal(stubArgs.id, 1); | ||
assert.equal(stubArgs.status, 'paused'); | ||
}); | ||
promiseCallback = preapprovalModule.pause(1, callback); | ||
assert.isFulfilled(promiseCallback); | ||
promiseCallback.then(function(response){ | ||
var callbackResponse = callback.args[0][1]; | ||
assert.equal(JSON.stringify(callbackResponse), JSON.stringify({})); | ||
assert.isTrue(callback.called); | ||
assert.isTrue(stub.called); | ||
assert.equal(JSON.stringify(response), JSON.stringify({})); | ||
}); | ||
promiseObjectArg = preapprovalModule.pause({ | ||
id: 1 | ||
}); | ||
assert.isFulfilled(promiseObjectArg); | ||
promise.then(function(response){ | ||
var stubArgs = stub.args[0][0]; | ||
assert.isTrue(stub.called); | ||
assert.equal(JSON.stringify(response), JSON.stringify({})); | ||
assert.equal(stubArgs.id, 1); | ||
assert.equal(stubArgs.status, 'paused'); | ||
}); | ||
stub.restore(); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
239942
76
5543
0
0
7
9
95
6
3
+ Addedajv@^4.10.3
+ Addedbluebird@^3.4.7
+ Addedchai-as-promised@^6.0.0
+ Addedmoment@^2.17.1
+ Addedrequest-etag@^2.0.3
+ Addeduuid@^3.0.1
+ Addedajv@4.11.8(transitive)
+ Addedassertion-error@1.1.0(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedchai@3.5.0(transitive)
+ Addedchai-as-promised@6.0.0(transitive)
+ Addedcheck-error@1.0.3(transitive)
+ Addedco@4.6.0(transitive)
+ Addeddeep-eql@0.1.3(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-func-name@2.0.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedjson-stable-stringify@1.1.1(transitive)
+ Addedjsonify@0.0.1(transitive)
+ Addedlodash.assign@4.2.0(transitive)
+ Addedlodash.clonedeep@4.5.0(transitive)
+ Addedlru-cache@4.1.5(transitive)
+ Addedmoment@2.30.1(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedpseudomap@1.0.2(transitive)
+ Addedrequest-etag@2.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedtype-detect@0.1.11.0.0(transitive)
+ Addedyallist@2.1.2(transitive)
- Removedq@>=1.1.2
- Removedasap@2.0.6(transitive)
- Removedpop-iterate@1.0.1(transitive)
- Removedq@2.0.3(transitive)
- Removedweak-map@1.0.8(transitive)
Updatedrequest@^2.79.0