Skip to content

Commit 61ea65c

Browse files
Merge pull request #4 from 2Checkout/CC-211
remove sandbox and depreciated functions
2 parents 944dd4a + abe7bbc commit 61ea65c

13 files changed

Lines changed: 61 additions & 354 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.swp
55
*.out
66
*.idea/*
7+
node_modules/

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ var tco = new Twocheckout({
2424
apiPass: "APIpass1817037", // Admin API Password, required for Admin API bindings
2525
sellerId: "1817037", // Seller ID, required for all non Admin API bindings
2626
privateKey: "3508079E-5383-44D4-BF69-DC619C0D9811", // Payment API private key, required for checkout.authorize binding
27-
secretWord: "tango", // Secret Word, required for response and notification checks
28-
demo: true, // Set to true if testing response with demo sales
29-
sandbox: false // Uses 2Checkout sandbox URL for all bindings
27+
secretWord: "tango" // Secret Word, required for response and notification checks
3028
});
3129
```
3230

lib/2checkout.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
var sales = require("./2checkout/sales"),
2-
products = require("./2checkout/products"),
3-
productOptions = require("./2checkout/productOptions"),
4-
coupons = require("./2checkout/coupons"),
5-
account = require("./2checkout/account"),
6-
payments = require("./2checkout/payments"),
7-
response = require("./2checkout/response"),
8-
notification = require("./2checkout/notification"),
9-
checkout = require("./2checkout/checkout");
10-
TwocheckoutError = require("./2checkout/error");
1+
var sales = require('./2checkout/sales'),
2+
products = require('./2checkout/products'),
3+
account = require('./2checkout/account'),
4+
payments = require('./2checkout/payments'),
5+
response = require('./2checkout/response'),
6+
notification = require('./2checkout/notification'),
7+
checkout = require('./2checkout/checkout');
8+
TwocheckoutError = require('./2checkout/error');
119

1210
var Twocheckout = module.exports = function (options) {
1311
// Setup Options
@@ -29,17 +27,11 @@ var Twocheckout = module.exports = function (options) {
2927
if (typeof options.demo !== 'undefined') {
3028
this.demo = options.demo;
3129
}
32-
if (typeof options.sandbox !== 'undefined' && options.sandbox === true) {
33-
this.domain = 'https://sandbox.2checkout.com';
34-
} else {
35-
this.domain = 'https://www.2checkout.com';
36-
}
30+
this.domain = 'https://www.2checkout.com';
3731

3832
// Setup Methods
3933
this.sales = new sales(this);
4034
this.products = new products(this);
41-
this.productOptions = new productOptions(this);
42-
this.coupons = new coupons(this);
4335
this.account = new account(this);
4436
this.payments = new payments(this);
4537
this.response = new response(this);

lib/2checkout/coupons.js

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

lib/2checkout/productOptions.js

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

lib/2checkout/sales.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,10 @@ sales.prototype.comment = function (args, callback) {
4848
return utils.execute(this.options, callback);
4949
};
5050

51-
sales.prototype.reauth = function (args, callback) {
52-
this.options.type = "admin";
53-
this.options.path = "/api/sales/reauth";
54-
this.options.method = "POST";
55-
this.options.payload = args;
56-
return utils.execute(this.options, callback);
57-
};
58-
5951
sales.prototype.stop = function (args, callback) {
6052
this.options.type = "admin";
6153
this.options.path = "/api/sales/stop_lineitem_recurring";
6254
this.options.method = "POST";
6355
this.options.payload = args;
6456
return utils.execute(this.options, callback);
65-
};
57+
};

lib/2checkout/utils.js

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,47 @@
1-
var request = require('request');
2-
var TwocheckoutError = require("./error");
3-
1+
var TwocheckoutError = require('./error');
2+
const got = require('got');
43
exports.execute = function (args, callback) {
5-
options = {
6-
uri: args.domain + args.path,
4+
var options = {
75
method: args.method,
8-
headers: { "Accept" : "application/json" },
9-
timeout: 30000
6+
responseType: 'json',
7+
prefixUrl: 'https://www.2checkout.com',
108
};
119

1210
if (args.type === "admin") {
13-
options.auth = {
14-
user: args.apiUser,
15-
pass: args.apiPass,
16-
sendImmediately: true
17-
};
11+
options.username = args.apiUser;
12+
options.password = args.apiPass;
1813

1914
if(args.method === "POST") {
2015
options.form = args.payload;
2116
} else {
22-
options.qs = args.payload;
17+
options.searchParams = args.payload;
2318
}
2419
} else {
2520
args.payload.privateKey = args.privateKey;
2621
args.payload.sellerId = args.sellerId;
2722
options.body = JSON.stringify(args.payload);
2823
}
2924

30-
request(options, function (error, response, body) {
31-
var parsedResponse;
32-
if (error) {
33-
callback(new TwocheckoutError('500', 'Unable to connect to 2Checkout API'));
34-
} else {
35-
36-
try {
37-
parsedResponse = JSON.parse(body);
38-
} catch (e) {
39-
callback(new TwocheckoutError('500', 'Error parsing JSON response from 2Checkout API.'));
40-
return;
41-
}
42-
43-
if (args.type === "admin") {
44-
if (parsedResponse.errors) {
45-
callback(new TwocheckoutError(parsedResponse.errors[0].code, parsedResponse.errors[0].message));
46-
return;
25+
let path = (args.path.charAt(0) === '/') ? args.path.substr(1) : args.path;
26+
(async () => {
27+
try {
28+
const response = await got(path, options);
29+
callback(null, response.body);
30+
} catch (error) {
31+
const parsedResponse = typeof error.response !== 'undefined' ? error.response.body : null;
32+
if (parsedResponse) {
33+
if (args.type === "admin") {
34+
if (parsedResponse.errors) {
35+
callback(new TwocheckoutError(parsedResponse.errors[0].code, parsedResponse.errors[0].message));
36+
}
37+
} else {
38+
if (parsedResponse.exception) {
39+
callback(new TwocheckoutError(parsedResponse.exception.errorCode, parsedResponse.exception.errorMsg));
40+
}
4741
}
4842
} else {
49-
if (parsedResponse.exception) {
50-
callback(new TwocheckoutError(parsedResponse.exception.errorCode, parsedResponse.exception.errorMsg));
51-
return;
52-
}
43+
callback(new TwocheckoutError('500', 'Error parsing JSON response from 2Checkout API.'));
5344
}
54-
55-
callback(null, parsedResponse);
56-
5745
}
58-
59-
});
46+
})();
6047
};

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
{
22
"name": "2checkout-node",
3-
"version": "1.0.0",
3+
"version": "2.0.0",
44
"description": "A node.js wrapper for the 2Checkout Payment API.",
5-
"author": "Craig Christenson <christensoncraig@gmail.com>",
65
"main": "lib/2checkout.js",
76
"repository": {
87
"type": "git",
98
"url": "http://github.com/2Checkout/2checkout-node.git"
109
},
1110
"engines": {
12-
"node": ">= v0.8.0"
11+
"node": ">=10.19.0"
1312
},
1413
"devDependencies": {
15-
"mocha": "~1.13.0"
14+
"mocha": "^1.13.0"
1615
},
1716
"dependencies": {
18-
"request": "2.x.x"
17+
"got": "11.*"
1918
}
2019
}

test/checkout_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ describe('checkout', function(){
66
it('should return a success or unauthorized response', function(done){
77
tco.checkout.authorize(authorize, function (error, data) {
88
if (error) {
9-
assert.equal("Error: Unauthorized", error);
9+
return assert.equal("Unauthorized", error.message);
1010
} else {
11-
assert.equal("APPROVED", data.response.responseCode);
11+
return assert.equal("APPROVED", data.response.responseCode);
1212
}
1313
done();
1414
});
1515
});
1616
});
17-
});
17+
});

test/coupon_spec.js

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

0 commit comments

Comments
 (0)