Skip to content
This repository was archived by the owner on Feb 15, 2022. It is now read-only.

Commit b2923f0

Browse files
authored
Merge pull request #26 from ndaidong/v2.0.0
v2.0.0rc1
2 parents 9367d99 + 407f2b9 commit b2923f0

File tree

14 files changed

+195
-176
lines changed

14 files changed

+195
-176
lines changed

.github/workflows/ci-test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# GitHub actions
2+
# https://docs.github.com/en/free-pro-team@latest/actions
3+
4+
name: ci-test
5+
6+
on: [push, pull_request]
7+
8+
jobs:
9+
test:
10+
11+
runs-on: ubuntu-20.04
12+
13+
strategy:
14+
matrix:
15+
node_version: [10.14.2, 14.x, 15.x]
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: setup Node.js v${{ matrix.node_version }}
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: ${{ matrix.node_version }}
24+
25+
- name: run npm scripts
26+
run: |
27+
npm install
28+
npm run lint
29+
npm run build --if-present
30+
npm run citest
31+
32+
- name: sync to coveralls
33+
uses: coverallsapp/github-action@v1.1.2
34+
with:
35+
github-token: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: cache node modules
38+
uses: actions/cache@v2
39+
with:
40+
path: ~/.npm
41+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
42+
restore-keys: |
43+
${{ runner.os }}-node-

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ coverage
1414
yarn.lock
1515
coverage.lcov
1616
package-lock.json
17+
pnpm-lock.yaml

.travis.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
Node.js wrapper for the Paypal Name-Value Pair — NVP
33

44
[![NPM](https://badge.fury.io/js/paypal-nvp-api.svg)](https://badge.fury.io/js/paypal-nvp-api)
5-
[![Build Status](https://travis-ci.org/ndaidong/paypal-nvp-api.svg?branch=master)](https://travis-ci.org/ndaidong/paypal-nvp-api)
5+
![CI test](https://github.com/ndaidong/paypal-nvp-api/workflows/ci-test/badge.svg)
6+
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/paypal-nvp-api/badge.svg)](https://coveralls.io/github/ndaidong/paypal-nvp-api)
7+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ndaidong_paypal-nvp-api&metric=alert_status)](https://sonarcloud.io/dashboard?id=ndaidong_paypal-nvp-api)
68

79

810

package.json

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.3.0",
2+
"version": "2.0.0rc1",
33
"name": "paypal-nvp-api",
44
"description": "Node.js wrapper for the Paypal Name-Value Pair — NVP ",
55
"homepage": "https://www.npmjs.com/package/paypal-nvp-api",
@@ -10,24 +10,23 @@
1010
"author": "@ndaidong",
1111
"main": "./index.js",
1212
"engines": {
13-
"node": ">= 8.6"
13+
"node": ">= 10.14.2"
1414
},
1515
"scripts": {
16-
"lint": "eslint ./src ./test",
16+
"lint": "eslint ./src ./tests",
1717
"pretest": "npm run lint",
18-
"test": "tap test/start.js --coverage --reporter=spec",
18+
"test": "tap tests/start.js --coverage --reporter=spec --coverage-report=html --no-browser",
19+
"citest": "tap tests/start.js --coverage --reporter=spec --coverage-report=lcov --no-browser",
1920
"reset": "node reset"
2021
},
2122
"dependencies": {
22-
"bellajs": "^7.5.0",
23-
"promise-wtf": "^1.2.4",
24-
"request": "^2.86.0"
23+
"bellajs": "^9.2.2",
24+
"node-fetch": "^2.6.1"
2525
},
2626
"devDependencies": {
27-
"codecov": "^3.0.1",
28-
"eslint-config-goes": "^1.1.6",
29-
"nock": "^9.2.5",
30-
"tap": "^14.5.0"
27+
"eslint-config-goes": "^1.1.8",
28+
"nock": "^13.0.4",
29+
"tap": "^14.10.8"
3130
},
3231
"keywords": [
3332
"Paypal",

src/helpers/parse.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
* @ndaidong
44
**/
55

6-
const {
7-
decode,
8-
} = require('bellajs');
9-
106
const parse = (s) => {
117
const d = {};
128
const a = s.split('&');
139
if (a.length > 0) {
1410
a.forEach((item) => {
1511
const b = item.split('=');
1612
if (b.length === 2) {
17-
d[b[0]] = decode(b[1]);
13+
d[b[0]] = decodeURIComponent(b[1]);
1814
}
1915
});
2016
}

src/helpers/stringify.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const {
88
isArray,
99
isObject,
1010
hasProperty,
11-
encode,
1211
} = require('bellajs');
1312

1413
const stringify = (data) => {
@@ -21,11 +20,11 @@ const stringify = (data) => {
2120
if (hasProperty(data, k)) {
2221
let val = data[k];
2322
if (isString(val)) {
24-
val = encode(val);
23+
val = encodeURIComponent(val);
2524
} else if (isArray(val) || isObject(val)) {
2625
val = JSON.stringify(val);
2726
}
28-
ar.push(encode(k) + '=' + val);
27+
ar.push(encodeURIComponent(k) + '=' + val);
2928
}
3029
}
3130
if (ar.length > 0) {

src/main.js

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ const BASE_API_SANDBOX = 'https://api-3t.sandbox.paypal.com/nvp';
1010
const TRACKING_URL_LIVE = 'https://www.paypal.com';
1111
const TRACKING_URL_SANDBOX = 'https://www.sandbox.paypal.com';
1212

13-
global.Promise = require('promise-wtf');
14-
1513
const {
1614
isObject,
1715
copies,
1816
} = require('bellajs');
1917

20-
const request = require('request');
18+
const fetch = require('node-fetch');
2119

2220
const {
2321
stringify,
@@ -43,39 +41,35 @@ const Paypal = (opts = {}) => {
4341
VERSION,
4442
};
4543

46-
const sendRequest = (method, params = {}) => {
47-
return new Promise((resolve, reject) => {
48-
if (!isObject(params)) {
49-
return reject(new Error('Params must be an object'));
50-
}
44+
const sendRequest = async (method, params = {}) => {
45+
if (!isObject(params)) {
46+
return new Error('Params must be an object');
47+
}
5148

52-
const o = copies(payload, params);
53-
o.METHOD = method;
49+
try {
50+
const query = copies(payload, params);
51+
query.METHOD = method;
5452

55-
return request.post({
56-
url: baseURL,
53+
const res = await fetch(baseURL, {
54+
method: 'POST',
5755
headers: {
58-
'X-PAYPAL-SECURITY-USERID': o.USER,
59-
'X-PAYPAL-SECURITY-PASSWORD': o.PWD,
60-
'X-PAYPAL-SECURITY-SIGNATURE': o.SIGNATURE,
56+
'X-PAYPAL-SECURITY-USERID': query.USER,
57+
'X-PAYPAL-SECURITY-PASSWORD': query.PWD,
58+
'X-PAYPAL-SECURITY-SIGNATURE': query.SIGNATURE,
6159
'X-PAYPAL-RESPONSE-DATA-FORMAT': 'JSON',
6260
},
63-
body: stringify(params),
64-
}, (err, response, body) => {
65-
if (err) {
66-
return reject(err);
67-
}
68-
const {
69-
statusCode,
70-
} = response;
71-
if (statusCode !== 200) {
72-
return reject(new Error(`Error: Response error with code: ${statusCode}`));
73-
}
74-
const r = parse(body);
75-
return resolve(r);
61+
body: stringify(query),
7662
});
77-
});
63+
if (!res.ok) {
64+
return new Error(`Error: Response error with code: ${res.statusText}`);
65+
}
66+
const data = await res.text();
67+
return parse(data);
68+
} catch (err) {
69+
return err;
70+
}
7871
};
72+
7973
return {
8074
request: sendRequest,
8175
formatCurrency,

test/specs/Paypal/request.js

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)