Skip to content

Commit

Permalink
Adds Axios as http client
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko committed Oct 25, 2023
1 parent ca24797 commit 38b3109
Show file tree
Hide file tree
Showing 111 changed files with 13,636 additions and 13,588 deletions.
25,697 changes: 12,871 additions & 12,826 deletions package-lock.json

Large diffs are not rendered by default.

115 changes: 59 additions & 56 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
{
"name": "checkout-sdk-node",
"version": "2.2.5",
"description": "",
"main": "./dist/index.js",
"devDependencies": {
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/eslint-plugin": "^7.16.5",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.8",
"chai": "^4.3.4",
"codecov": "^3.8.2",
"eslint": "^8.34.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-chai-friendly": "^0.7.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"esm": "^3.2.25",
"mocha": "^8.4.0",
"mocha-junit-reporter": "^2.0.0",
"nock": "^13.0.11",
"nyc": "^15.1.0",
"prettier": "^2.1.2",
"uuid": "^8.3.2"
},
"runkitExampleFilename": "example.js",
"scripts": {
"start": "nodemon --exec babel-node ./src/index.js",
"lint": "eslint --fix --ext .js src/",
"test": "nyc --reporter=html mocha --timeout 300000 'test/**/*.js' --require esm",
"posttest": "nyc report --reporter=json",
"test:watch": "mocha --timeout 300000 'test/**/*.js' --watch --require esm",
"build": "babel src --out-dir ./dist --source-maps",
"codecov": "codecov -f coverage/*.json",
"tsc": "tsc"
},
"dependencies": {
"form-data": "^4.0.0",
"node-fetch": "^2.6.12"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": 6
}
}
]
]
},
"author": "Ioan Ghisoi",
"license": "MIT"
"name": "checkout-sdk-node",
"version": "2.2.5",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"devDependencies": {
"@babel/cli": "^7.16.8",
"@babel/core": "^7.16.7",
"@babel/eslint-parser": "^7.16.5",
"@babel/eslint-plugin": "^7.16.5",
"@babel/node": "^7.16.8",
"@babel/preset-env": "^7.16.8",
"chai": "^4.3.4",
"codecov": "^3.8.2",
"eslint": "^8.34.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-chai-friendly": "^0.7.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.4.0",
"esm": "^3.2.25",
"mocha": "^8.4.0",
"mocha-junit-reporter": "^2.0.0",
"nock": "^13.0.11",
"nyc": "^15.1.0",
"prettier": "^2.1.2",
"uuid": "^8.3.2"
},
"runkitExampleFilename": "example.js",
"scripts": {
"start": "nodemon --exec babel-node ./src/index.js",
"lint": "eslint --fix --ext .js src/",
"test": "nyc --reporter=html mocha --timeout 300000 'test/**/*.js' --require esm",
"posttest": "nyc report --reporter=json",
"test:watch": "mocha --timeout 300000 'test/**/*.js' --watch --require esm",
"build": "babel src --out-dir ./dist --source-maps",
"codecov": "codecov -f coverage/*.json",
"tsc": "tsc"
},
"dependencies": {
"axios": "^0.21.1",
"form-data": "^4.0.0",
"node-fetch": "^2.6.12"
},
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": 6
}
}
]
]
},
"author": "Ioan Ghisoi",
"license": "MIT"
}
5 changes: 3 additions & 2 deletions src/Checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class Checkout {
} else {
// For MBC or NAS with static keys with declared vars
auth = {
sk: determineSecretKey(key, options),
sk: determineSecretKey(key),
pk: determinePublicKey(options),
host: determineHost(determineSecretKey(key), options),
};
Expand All @@ -132,6 +132,7 @@ export default class Checkout {
agent: options && options.agent ? options.agent : undefined,
headers: options && options.headers ? options.headers : {},
access: undefined,
httpClient: options && options.httpClient ? options.httpClient : undefined,
};

this.payments = new ENDPOINTS.Payments(this.config);
Expand Down Expand Up @@ -170,4 +171,4 @@ export default class Checkout {
this.financial = new ENDPOINTS.Financial(this.config);
this.issuing = new ENDPOINTS.Issuing(this.config);
}
}
}
7 changes: 5 additions & 2 deletions src/api/access/access.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { createAccessToken } from '../../services/http';

Expand All @@ -21,7 +20,11 @@ export default class Access {
*/
async request(body) {
try {
const response = await createAccessToken(this.config, fetch, body);
const response = await createAccessToken(
this.config,
this.config.httpClient,
body
);
return await response.json;
} catch (err) {
const error = await determineError(err);
Expand Down
5 changes: 2 additions & 3 deletions src/api/apm-specific/baloto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { post } from '../../services/http';

Expand All @@ -25,7 +24,7 @@ export default class Baloto {
async succeed(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/baloto/payments/${id}/succeed`,
this.config,
this.config.sk
Expand All @@ -48,7 +47,7 @@ export default class Baloto {
async expire(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/baloto/payments/${id}/expire`,
this.config,
this.config.sk
Expand Down
5 changes: 2 additions & 3 deletions src/api/apm-specific/boleto.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { post } from '../../services/http';

Expand All @@ -25,7 +24,7 @@ export default class Boleto {
async succeed(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/boleto/payments/${id}/succeed`,
this.config,
this.config.sk
Expand All @@ -48,7 +47,7 @@ export default class Boleto {
async expire(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/boleto/payments/${id}/expire`,
this.config,
this.config.sk
Expand Down
5 changes: 2 additions & 3 deletions src/api/apm-specific/fawry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { put } from '../../services/http';

Expand Down Expand Up @@ -26,7 +25,7 @@ export default class Fawry {
async approve(reference) {
try {
const response = await put(
fetch,
this.config.httpClient,
`${this.config.host}/fawry/payments/${reference}/approval`,
this.config,
this.config.sk
Expand All @@ -49,7 +48,7 @@ export default class Fawry {
async cancel(reference) {
try {
const response = await put(
fetch,
this.config.httpClient,
`${this.config.host}/fawry/payments/${reference}/cancellation`,
this.config,
this.config.sk
Expand Down
5 changes: 2 additions & 3 deletions src/api/apm-specific/giropay.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { get } from '../../services/http';

Expand All @@ -24,7 +23,7 @@ export default class Giropay {
async getEpsBanks() {
try {
const response = await get(
fetch,
this.config.httpClient,
`${this.config.host}/giropay/eps/banks`,
this.config,
this.config.sk
Expand All @@ -46,7 +45,7 @@ export default class Giropay {
async getBanks() {
try {
const response = await get(
fetch,
this.config.httpClient,
`${this.config.host}/giropay/banks`,
this.config,
this.config.sk
Expand Down
5 changes: 2 additions & 3 deletions src/api/apm-specific/ideal.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { get } from '../../services/http';

Expand All @@ -22,7 +21,7 @@ export default class Ideal {
async get() {
try {
const response = await get(
fetch,
this.config.httpClient,
`${this.config.host}/ideal-external`,
this.config,
this.config.sk
Expand All @@ -43,7 +42,7 @@ export default class Ideal {
async getIssuers() {
try {
const response = await get(
fetch,
this.config.httpClient,
`${this.config.host}/ideal-external/issuers`,
this.config,
this.config.sk
Expand Down
32 changes: 27 additions & 5 deletions src/api/apm-specific/klarna.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { get, post } from '../../services/http';

Expand All @@ -24,7 +23,13 @@ export default class Klarna {
? `${this.config.host}/klarna-external/credit-sessions`
: `${this.config.host}/klarna/credit-sessions`;
try {
const response = await post(fetch, url, this.config, this.config.sk, body);
const response = await post(
this.config.httpClient,
url,
this.config,
this.config.sk,
body
);
return await response.json;
} catch (err) {
const error = await determineError(err);
Expand All @@ -43,7 +48,12 @@ export default class Klarna {
? `${this.config.host}/klarna-external/credit-sessions/${id}`
: `${this.config.host}/klarna/credit-sessions/${id}`;
try {
const response = await get(fetch, url, this.config, this.config.sk);
const response = await get(
this.config.httpClient,
url,
this.config,
this.config.sk
);
return await response.json;
} catch (err) {
const error = await determineError(err);
Expand All @@ -63,7 +73,13 @@ export default class Klarna {
? `${this.config.host}/klarna-external/orders/${id}/captures`
: `${this.config.host}/klarna/orders/${id}/captures`;
try {
const response = await post(fetch, url, this.config, this.config.sk, body);
const response = await post(
this.config.httpClient,
url,
this.config,
this.config.sk,
body
);
return await response.json;
} catch (err) {
const error = await determineError(err);
Expand All @@ -83,7 +99,13 @@ export default class Klarna {
? `${this.config.host}/klarna-external/orders/${id}/voids`
: `${this.config.host}/klarna/orders/${id}/voids`;
try {
const response = await post(fetch, url, this.config, this.config.sk, body);
const response = await post(
this.config.httpClient,
url,
this.config,
this.config.sk,
body
);
return await response.json;
} catch (err) {
const error = await determineError(err);
Expand Down
5 changes: 2 additions & 3 deletions src/api/apm-specific/oxxo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { post } from '../../services/http';

Expand All @@ -25,7 +24,7 @@ export default class Oxxo {
async succeed(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/oxxo/payments/${id}/succeed`,
this.config,
this.config.sk
Expand All @@ -48,7 +47,7 @@ export default class Oxxo {
async expire(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/oxxo/payments/${id}/expire`,
this.config,
this.config.sk
Expand Down
5 changes: 2 additions & 3 deletions src/api/apm-specific/pagofacil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import { determineError } from '../../services/errors';
import { post } from '../../services/http';

Expand All @@ -25,7 +24,7 @@ export default class PagoFacil {
async succeed(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/pagofacil/payments/${id}/succeed`,
this.config,
this.config.sk
Expand All @@ -48,7 +47,7 @@ export default class PagoFacil {
async expire(id) {
try {
const response = await post(
fetch,
this.config.httpClient,
`${this.config.host}/apms/pagofacil/payments/${id}/expire`,
this.config,
this.config.sk
Expand Down
Loading

0 comments on commit 38b3109

Please sign in to comment.