paypal-nvp-api
Advanced tools
Comparing version 1.2.33 to 1.3.0
{ | ||
"extends": "eslint-config-ggc" | ||
"extends": "eslint-config-goes" | ||
} |
@@ -6,5 +6,5 @@ /** | ||
var main = require('./src/main'); | ||
const main = require('./src/main'); | ||
main.version = require('./package').version; | ||
module.exports = main; |
{ | ||
"version": "1.2.33", | ||
"version": "1.3.0", | ||
"name": "paypal-nvp-api", | ||
@@ -13,28 +13,20 @@ "description": "Node.js wrapper for the Paypal Name-Value Pair — NVP ", | ||
"engines": { | ||
"node": ">= 6.0" | ||
"node": ">= 8.6" | ||
}, | ||
"scripts": { | ||
"lint": "eslint ./src ./test", | ||
"nsp": "nsp check --output checkstyle", | ||
"tape": "nyc tape test/start.js | tap-spec", | ||
"report": "nyc report --reporter=lcov > coverage.lcov && codecov", | ||
"pretest": "npm run lint && npm run nsp", | ||
"test": "npm run tape", | ||
"posttest": "CODECOV_TOKEN=0ad639d1-d519-4946-a361-725e22ec53d6 npm run report", | ||
"pretest": "npm run lint", | ||
"test": "tap test/start.js --coverage --reporter=spec", | ||
"reset": "node reset" | ||
}, | ||
"dependencies": { | ||
"bellajs": "7.x.x", | ||
"promise-wtf": "1.x.x", | ||
"request": "2.x.x" | ||
"bellajs": "^7.5.0", | ||
"promise-wtf": "^1.2.4", | ||
"request": "^2.86.0" | ||
}, | ||
"devDependencies": { | ||
"codecov": "2.x.x", | ||
"eslint": "4.x.x", | ||
"eslint-config-ggc": "1.x.x", | ||
"nock": "9.x.x", | ||
"nsp": "2.x.x", | ||
"nyc": "11.x.x", | ||
"tap-spec": "4.x.x", | ||
"tape": "4.x.x" | ||
"codecov": "^3.0.1", | ||
"eslint-config-goes": "^1.1.6", | ||
"nock": "^9.2.5", | ||
"tap": "^14.5.0" | ||
}, | ||
@@ -41,0 +33,0 @@ "keywords": [ |
@@ -6,7 +6,5 @@ # paypal-nvp-api | ||
[![Build Status](https://travis-ci.org/ndaidong/paypal-nvp-api.svg?branch=master)](https://travis-ci.org/ndaidong/paypal-nvp-api) | ||
[![codecov](https://codecov.io/gh/ndaidong/paypal-nvp-api/branch/master/graph/badge.svg)](https://codecov.io/gh/ndaidong/paypal-nvp-api) | ||
[![Dependency Status](https://gemnasium.com/badges/github.com/ndaidong/paypal-nvp-api.svg)](https://gemnasium.com/github.com/ndaidong/paypal-nvp-api) | ||
[![NSP Status](https://nodesecurity.io/orgs/techpush/projects/b6471f27-370b-4f79-badd-75cd5401d826/badge)](https://nodesecurity.io/orgs/techpush/projects/b6471f27-370b-4f79-badd-75cd5401d826) | ||
### Usage | ||
@@ -17,5 +15,6 @@ | ||
```js | ||
var Paypal = require('paypal-nvp-api'); | ||
const Paypal = require('paypal-nvp-api'); | ||
let config = { | ||
const config = { | ||
mode: 'sandbox', // or 'live' | ||
@@ -27,3 +26,3 @@ username: 'someone.itravellocal.com', | ||
let paypal = Paypal(config); | ||
const paypal = Paypal(config); | ||
``` | ||
@@ -57,4 +56,5 @@ | ||
```js | ||
let query = { | ||
const query = { | ||
'PAYMENTREQUEST_0_AMT': '20.00', | ||
@@ -120,3 +120,3 @@ 'PAYMENTREQUEST_0_CURRENCYCODE': 'USD', | ||
``` | ||
```bash | ||
git clone https://github.com/ndaidong/paypal-nvp-api.git | ||
@@ -123,0 +123,0 @@ cd paypal-nvp-api |
22
reset.js
#!/usr/bin/env node | ||
var { | ||
const { | ||
existsSync, | ||
unlinkSync | ||
unlinkSync, | ||
} = require('fs'); | ||
var exec = require('child_process').execSync; | ||
var dirs = [ | ||
const {execSync} = require('child_process'); | ||
const dirs = [ | ||
'dist', | ||
'docs', | ||
'.nyc_output', | ||
'coverage', | ||
'node_modules' | ||
'node_modules', | ||
'.nuxt', | ||
]; | ||
var files = [ | ||
const files = [ | ||
'yarn.lock', | ||
'package-lock.json', | ||
'coverage.lcov' | ||
'coverage.lcov', | ||
]; | ||
dirs.forEach((d) => { | ||
exec(`rm -rf ${d}`); | ||
execSync(`rm -rf ${d}`); | ||
}); | ||
@@ -30,3 +34,1 @@ | ||
}); | ||
@@ -6,8 +6,8 @@ /** | ||
var { | ||
isNumber | ||
const { | ||
isNumber, | ||
} = require('bellajs'); | ||
var formatCurrency = (num) => { | ||
let n = Number(num); | ||
const formatCurrency = (num) => { | ||
const n = Number(num); | ||
if (!n || !isNumber(n) || n < 0) { | ||
@@ -14,0 +14,0 @@ return '0.00'; |
module.exports = { | ||
formatCurrency: require('./formatCurrency'), | ||
parse: require('./parse'), | ||
stringify: require('./stringify') | ||
stringify: require('./stringify'), | ||
}; |
@@ -6,12 +6,12 @@ /** | ||
var { | ||
decode | ||
const { | ||
decode, | ||
} = require('bellajs'); | ||
var parse = (s) => { | ||
let d = {}; | ||
let a = s.split('&'); | ||
const parse = (s) => { | ||
const d = {}; | ||
const a = s.split('&'); | ||
if (a.length > 0) { | ||
a.forEach((item) => { | ||
let b = item.split('='); | ||
const b = item.split('='); | ||
if (b.length === 2) { | ||
@@ -26,1 +26,2 @@ d[b[0]] = decode(b[1]); | ||
module.exports = parse; | ||
@@ -6,3 +6,3 @@ /** | ||
var { | ||
const { | ||
isString, | ||
@@ -12,6 +12,6 @@ isArray, | ||
hasProperty, | ||
encode | ||
encode, | ||
} = require('bellajs'); | ||
var stringify = (data) => { | ||
const stringify = (data) => { | ||
let s = ''; | ||
@@ -21,4 +21,4 @@ if (isString(data)) { | ||
} else if (isArray(data) || isObject(data)) { | ||
let ar = []; | ||
for (let k in data) { | ||
const ar = []; | ||
for (const k in data) { | ||
if (hasProperty(data, k)) { | ||
@@ -33,3 +33,2 @@ let val = data[k]; | ||
} | ||
} | ||
@@ -44,1 +43,2 @@ if (ar.length > 0) { | ||
module.exports = stringify; | ||
@@ -15,37 +15,35 @@ /** | ||
var { | ||
const { | ||
isObject, | ||
copies | ||
copies, | ||
} = require('bellajs'); | ||
var request = require('request'); | ||
const request = require('request'); | ||
var { | ||
const { | ||
stringify, | ||
parse, | ||
formatCurrency | ||
formatCurrency, | ||
} = require('./helpers'); | ||
var Paypal = (opts = {}) => { | ||
let { | ||
const Paypal = (opts = {}) => { | ||
const { | ||
mode = 'sandbox', | ||
username = '', | ||
password = '', | ||
signature = '' | ||
signature = '', | ||
} = opts; | ||
let baseURL = mode === 'live' ? BASE_API_LIVE : BASE_API_SANDBOX; | ||
const baseURL = mode === 'live' ? BASE_API_LIVE : BASE_API_SANDBOX; | ||
opts.track = mode === 'live' ? TRACKING_URL_LIVE : TRACKING_URL_SANDBOX; | ||
let payload = { | ||
const payload = { | ||
USER: username, | ||
PWD: password, | ||
SIGNATURE: signature, | ||
VERSION | ||
VERSION, | ||
}; | ||
let sendRequest = (method, params = {}) => { | ||
const sendRequest = (method, params = {}) => { | ||
return new Promise((resolve, reject) => { | ||
if (!isObject(params)) { | ||
@@ -55,3 +53,3 @@ return reject(new Error('Params must be an object')); | ||
let o = copies(payload, params); | ||
const o = copies(payload, params); | ||
o.METHOD = method; | ||
@@ -65,5 +63,5 @@ | ||
'X-PAYPAL-SECURITY-SIGNATURE': o.SIGNATURE, | ||
'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON' | ||
'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON', | ||
}, | ||
body: stringify(params) | ||
body: stringify(params), | ||
}, (err, response, body) => { | ||
@@ -73,4 +71,4 @@ if (err) { | ||
} | ||
let { | ||
statusCode | ||
const { | ||
statusCode, | ||
} = response; | ||
@@ -80,3 +78,3 @@ if (statusCode !== 200) { | ||
} | ||
let r = parse(body); | ||
const r = parse(body); | ||
return resolve(r); | ||
@@ -88,3 +86,3 @@ }); | ||
request: sendRequest, | ||
formatCurrency | ||
formatCurrency, | ||
}; | ||
@@ -94,1 +92,2 @@ }; | ||
module.exports = Paypal; | ||
@@ -6,3 +6,3 @@ module.exports = { | ||
password: 'DYKNJZZE42ASU699', | ||
signature: 'A0aEilikhBmwfK.NlduDjCbsdgRdA8VDPMDksDhGsHmLQECu80Qtru09' | ||
signature: 'A0aEilikhBmwfK.NlduDjCbsdgRdA8VDPMDksDhGsHmLQECu80Qtru09', | ||
}; |
@@ -8,16 +8,16 @@ /** | ||
var test = require('tape'); | ||
var nock = require('nock'); | ||
const test = require('tap').test; | ||
const nock = require('nock'); | ||
var { | ||
const { | ||
isObject, | ||
hasProperty | ||
hasProperty, | ||
} = require('bellajs'); | ||
var config = require('../config'); | ||
const config = require('../config'); | ||
var nvp = config.main; | ||
var paypal = nvp(config); | ||
const nvp = config.main; | ||
const paypal = nvp(config); | ||
var hasRequiredKey = (o, k) => { | ||
const hasRequiredKey = (o, k) => { | ||
return hasProperty(o, k); | ||
@@ -27,3 +27,3 @@ }; | ||
test('.GetBalance()', (assert) => { | ||
let props = [ | ||
const props = [ | ||
'L_AMT0', | ||
@@ -35,3 +35,3 @@ 'L_CURRENCYCODE0', | ||
'VERSION', | ||
'BUILD' | ||
'BUILD', | ||
]; | ||
@@ -44,3 +44,2 @@ | ||
}); | ||
}).catch((e) => { | ||
@@ -50,8 +49,6 @@ console.log(e); | ||
}).finally(assert.end); | ||
}); | ||
test('.SetExpressCheckout()', (assert) => { | ||
let query = { | ||
const query = { | ||
PAYMENTREQUEST_0_AMT: '20.00', | ||
@@ -61,6 +58,6 @@ PAYMENTREQUEST_0_CURRENCYCODE: 'USD', | ||
RETURNURL: 'http://google.com/test/onreturn', | ||
CANCELURL: 'http://google.com/test/oncancel' | ||
CANCELURL: 'http://google.com/test/oncancel', | ||
}; | ||
let props = [ | ||
const props = [ | ||
'TOKEN', | ||
@@ -71,3 +68,3 @@ 'TIMESTAMP', | ||
'VERSION', | ||
'BUILD' | ||
'BUILD', | ||
]; | ||
@@ -88,3 +85,2 @@ | ||
test('Call a unexist method', (assert) => { | ||
paypal.request('CallUnexistMethod', {}).then((re) => { | ||
@@ -97,7 +93,5 @@ assert.ok(isObject(re), 'Result should be an object'); | ||
}).finally(assert.end); | ||
}); | ||
test('Call with invalid params', (assert) => { | ||
paypal.request('GetBalance', 'noop').then((re) => { | ||
@@ -110,7 +104,6 @@ assert.ok(isObject(re), 'Result should be an object'); | ||
}).finally(assert.end); | ||
}); | ||
test('Call with instance initialized from the bad configs', (assert) => { | ||
let fakePaypal = nvp(); | ||
const fakePaypal = nvp(); | ||
fakePaypal.request('GetBalance', {}).then((re) => { | ||
@@ -123,3 +116,2 @@ assert.ok(isObject(re), 'Result should be an object'); | ||
}).finally(assert.end); | ||
}); | ||
@@ -132,11 +124,10 @@ | ||
.reply(500, 'Server error'); | ||
let fakePaypal = nvp(); | ||
const fakePaypal = nvp(); | ||
fakePaypal.request('xMethod', {}).then((re) => { | ||
console.log(re); | ||
}).catch((e) => { | ||
let msg = 'Error: Response error with code: 500'; | ||
const msg = 'Error: Response error with code: 500'; | ||
assert.equals(e.message, msg, `It must throw: ${msg}`); | ||
return false; | ||
}).finally(assert.end); | ||
}); |
@@ -6,93 +6,92 @@ /** | ||
var test = require('tape'); | ||
const test = require('tap').test; | ||
var { | ||
isString | ||
const { | ||
isString, | ||
} = require('bellajs'); | ||
var config = require('../config'); | ||
const config = require('../config'); | ||
var nvp = config.main; | ||
var paypal = nvp(config); | ||
const nvp = config.main; | ||
const paypal = nvp(config); | ||
test('.formatCurrency()', (assert) => { | ||
let sample = [ | ||
const sample = [ | ||
{ | ||
value: 1234567, | ||
result: '1,234,567.00' | ||
result: '1,234,567.00', | ||
}, | ||
{ | ||
value: 123456, | ||
result: '123,456.00' | ||
result: '123,456.00', | ||
}, | ||
{ | ||
value: 12345, | ||
result: '12,345.00' | ||
result: '12,345.00', | ||
}, | ||
{ | ||
value: 1234, | ||
result: '1,234.00' | ||
result: '1,234.00', | ||
}, | ||
{ | ||
value: 123, | ||
result: '123.00' | ||
result: '123.00', | ||
}, | ||
{ | ||
value: 12, | ||
result: '12.00' | ||
result: '12.00', | ||
}, | ||
{ | ||
value: 1, | ||
result: '1.00' | ||
result: '1.00', | ||
}, | ||
{ | ||
value: 0.1, | ||
result: '0.10' | ||
result: '0.10', | ||
}, | ||
{ | ||
value: 0.12, | ||
result: '0.12' | ||
result: '0.12', | ||
}, | ||
{ | ||
value: 0.123, | ||
result: '0.12' | ||
result: '0.12', | ||
}, | ||
{ | ||
value: 12345.12345, | ||
result: '12,345.12' | ||
result: '12,345.12', | ||
}, | ||
{ | ||
value: 12.5, | ||
result: '12.50' | ||
result: '12.50', | ||
}, | ||
{ | ||
value: '12', | ||
result: '12.00' | ||
result: '12.00', | ||
}, | ||
{ | ||
value: '', | ||
result: '0.00' | ||
result: '0.00', | ||
}, | ||
{ | ||
value: '0', | ||
result: '0.00' | ||
result: '0.00', | ||
}, | ||
{ | ||
value: '-1', | ||
result: '0.00' | ||
result: '0.00', | ||
}, | ||
{ | ||
value: -1, | ||
result: '0.00' | ||
result: '0.00', | ||
}, | ||
{ | ||
value: 'ABC', | ||
result: '0.00' | ||
} | ||
result: '0.00', | ||
}, | ||
]; | ||
sample.forEach((item) => { | ||
let v = item.value; | ||
let result = paypal.formatCurrency(v); | ||
const v = item.value; | ||
const result = paypal.formatCurrency(v); | ||
assert.deepEquals(result, item.result, ' / paypal.formatCurrency(' + (isString(v) ? `'${v}'` : v) + ')'); | ||
@@ -99,0 +98,0 @@ }); |
@@ -6,28 +6,27 @@ /** | ||
var test = require('tape'); | ||
const test = require('tap').test; | ||
var { | ||
isFunction | ||
const { | ||
isFunction, | ||
} = require('bellajs'); | ||
var {stringify} = require('../../../src/helpers'); | ||
const {stringify} = require('../../../src/helpers'); | ||
test('.stringify()', (assert) => { | ||
assert.ok(isFunction(stringify), 'stringify() must be a function'); | ||
let v1 = 'Just a string'; | ||
let e1 = v1; | ||
const v1 = 'Just a string'; | ||
const e1 = v1; | ||
assert.equals(stringify(v1), e1, `stringify('${v1}') must be '${e1}'`); | ||
let v2 = { | ||
const v2 = { | ||
a: { | ||
b: 1, | ||
c: { | ||
d: 2 | ||
} | ||
} | ||
d: 2, | ||
}, | ||
}, | ||
}; | ||
let e2 = 'a={"b":1,"c":{"d":2}}'; | ||
const e2 = 'a={"b":1,"c":{"d":2}}'; | ||
assert.equals(stringify(v2), e2, `stringify('${v2}') must be '${e2}'`); | ||
@@ -37,1 +36,2 @@ | ||
}); | ||
@@ -1,4 +0,11 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
const { | ||
existsSync, | ||
readdirSync, | ||
} = require('fs'); | ||
const { | ||
join, | ||
extname, | ||
} = require('path'); | ||
/** | ||
@@ -8,9 +15,9 @@ * Import specs | ||
var dirs = ['', 'Paypal', 'utils']; | ||
const dirs = ['', 'Paypal', 'utils']; | ||
dirs.forEach((dir) => { | ||
let where = './test/specs/' + dir; | ||
if (fs.existsSync(where)) { | ||
fs.readdirSync(where).forEach((file) => { | ||
if (path.extname(file) === '.js') { | ||
require(path.join('.' + where, file)); | ||
const where = './test/specs/' + dir; | ||
if (existsSync(where)) { | ||
readdirSync(where).forEach((file) => { | ||
if (extname(file) === '.js') { | ||
require(join('.' + where, file)); | ||
} | ||
@@ -17,0 +24,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
4
441
15159
18
2
Updatedbellajs@^7.5.0
Updatedpromise-wtf@^1.2.4
Updatedrequest@^2.86.0