Skip to content

Commit 736f0db

Browse files
committed
Merge branch 'qwales1-master'
2 parents 82179fe + 2e71b52 commit 736f0db

File tree

6 files changed

+176
-21
lines changed

6 files changed

+176
-21
lines changed

config.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
2-
"API_LOGIN_ID": "2msN9nrBG8K",
3-
"TRANSACTION_KEY": "43jNykM6kC8v87Nb"
4-
};
2+
"API_LOGIN_ID": "2msN9nrBG8K",
3+
"TRANSACTION_KEY": "43jNykM6kC8v87Nb"
4+
};

documentation/AuthorizeNet.md

+19
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@
7777

7878
**other**: object, a json object you want to mix with the transactionRequest field before transformation into xml. Note it will override already assigned properties
7979

80+
**Returns**: Promise,
81+
#### refundTransaction(refTransId, amount, cardNumber, expirationYear, expirationMonth, other)
82+
83+
Refund an already settled transaction
84+
85+
**Parameters**
86+
87+
**refTransId**: a reference to the transaction to refund
88+
89+
**amount**: the amount to refund
90+
91+
**cardNumber**: the card number used to process the transaction
92+
93+
**expirationYear**: the expiration year of the card used to process the transaction
94+
95+
**expirationMonth**: the expiration month of the transaction card used to process the transaction
96+
97+
**other**: some other fields to merge with the request
98+
8099
**Returns**: Promise,
81100
#### voidTransaction(refTransId, other)
82101

lib/applySchema.js

+71-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//xsd schema expects a sequence of fields, Javascript json object (map) does not ensure an order in the keys, we have to use arrays
22

3-
//schema not complete ...
43
var transactionRequestSchema = [
54
{node: 'merchantAuthentication', value: [
65
{node: 'name'},
@@ -21,6 +20,50 @@ var transactionRequestSchema = [
2120
{node: 'cardCode'}
2221
]}
2322
]},
23+
{node : 'profile', value : [
24+
{node: 'createProfile'},
25+
{node: 'customerProfileId'},
26+
{node: 'paymentProfile', value: [
27+
{node: 'paymentProfileId'},
28+
{node: 'cardCode'},
29+
{node: 'shippingProfileId'}
30+
]}
31+
]},
32+
{node: 'order', value : [
33+
{node: 'invoiceNumber'},
34+
{node: 'description'}
35+
]},
36+
{node : 'lineItems', value: [
37+
[{node: 'lineItem', value: [
38+
{node: 'itemId'},
39+
{node: 'name'},
40+
{node: 'description'},
41+
{node: 'quantity'},
42+
{node: 'unitPrice'}
43+
]}]
44+
]},
45+
{node: 'tax', value: [
46+
{node: 'amount'},
47+
{node: 'name'},
48+
{node: 'description'}
49+
]},
50+
{node: 'duty', value: [
51+
{node: 'amount'},
52+
{node: 'name'},
53+
{node: 'description'}
54+
]},
55+
{node: 'shipping', value: [
56+
{node: 'amount'},
57+
{node: 'name'},
58+
{node: 'description'},
59+
{node: 'taxExempt'},
60+
]},
61+
{node: 'poNumber'},
62+
{node : 'customer', value: [
63+
{node: 'type'},
64+
{node: 'id'},
65+
{node: 'email'}
66+
]},
2467
{node: 'billTo', value: [
2568
{node: 'firstName'},
2669
{node: 'lastName'},
@@ -29,7 +72,9 @@ var transactionRequestSchema = [
2972
{node: 'city'},
3073
{node: 'state'},
3174
{node: 'zip'},
32-
{node: 'country'}
75+
{node: 'country'},
76+
{node: 'phoneNumber'},
77+
{node: 'faxNumber'}
3378
]},
3479
{node: 'shipTo', value: [
3580
{node: 'firstName'},
@@ -39,7 +84,29 @@ var transactionRequestSchema = [
3984
{node: 'city'},
4085
{node: 'state'},
4186
{node: 'zip'},
42-
{node: 'country'}
87+
{node: 'country'},
88+
{node: 'customerIP'}
89+
]},
90+
{node: 'cardholderAuthentication', value: [
91+
{node: 'Authentication Indicator'},
92+
{node: 'Cardholder Authentication Value'}
93+
]},
94+
{node: 'retail', value: [
95+
{node: 'marketType'},
96+
{node: 'deviceType'}
97+
]},
98+
{node: 'transactionSettings', value: [
99+
[{node: 'setting', value: [
100+
{node: 'settingName'},
101+
{node: 'settingValue'}
102+
103+
]}]
104+
]},
105+
{node: 'userFields', value: [
106+
[{node: 'userField', value: [
107+
{node: 'name'},
108+
{node: 'value'}
109+
]}]
43110
]}
44111
]}
45112
];
@@ -51,7 +118,7 @@ function applySchema(schema, obj) {
51118
var value = val.value;
52119
var node = {};
53120

54-
if (!value) {
121+
if (!value || !(value.constructor === Array && value.length > 1)) {
55122
//leaf
56123
if (obj[key]) {
57124
node[key] = obj[key];

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-authorize-net",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "nodejs sdk to communicate with authorize.net payement gateway",
55
"main": "index.js",
66
"scripts": {

readme.md

+19
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,25 @@
107107

108108
**other**: object, a json object you want to mix with the transactionRequest field before transformation into xml. Note it will override already assigned properties
109109

110+
**Returns**: Promise,
111+
#### refundTransaction(refTransId, amount, cardNumber, expirationYear, expirationMonth, other)
112+
113+
Refund an already settled transaction
114+
115+
**Parameters**
116+
117+
**refTransId**: a reference to the transaction to refund
118+
119+
**amount**: the amount to refund
120+
121+
**cardNumber**: the card number used to process the transaction
122+
123+
**expirationYear**: the expiration year of the card used to process the transaction
124+
125+
**expirationMonth**: the expiration month of the transaction card used to process the transaction
126+
127+
**other**: some other fields to merge with the request
128+
110129
**Returns**: Promise,
111130
#### voidTransaction(refTransId, other)
112131

test.js

+63-13
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,51 @@ describe('AuthorizeNet service', function () {
2222
service.authCaptureTransaction(randomAmount(), 4012888818888, 2017, 1).then(function (transaction) {
2323
assert.equal(transaction.transactionResponse.responseCode, '1');
2424
done();
25+
}, function(rejection){
26+
done(JSON.stringify(rejection));
2527
});
2628
});
2729

2830
it('should submit authorizationCapture request with some extra params', function (done) {
2931
service.authCaptureTransaction(randomAmount(), 4012888818888, 2016, 10, {
3032
transactionRequest: {
3133
payment: {creditCard: {cardCode: 999}},
32-
billTo: {firstName: 'bob', lastName: 'Eponge'}
34+
lineItems : [
35+
{lineItem: {itemId:1, name: 'Test Item', quantity:2, unitPrice: 4.99}},
36+
{lineItem: {itemId:2, name: 'Test Item2', quantity:3, unitPrice: 5.99}}
37+
],
38+
tax : {
39+
amount: 2.13,
40+
name: 'city tax',
41+
description: 'some text here'
42+
},
43+
duty : {
44+
amount: 1.21,
45+
name: 'duty name',
46+
description: 'duty description'
47+
},
48+
shipping : {
49+
amount: 12.99,
50+
name: '2 Day Shipping',
51+
description: 'UPS'
52+
},
53+
poNumber : 'abcd-1234',
54+
billTo: {firstName: 'bob', lastName: 'Eponge'},
55+
customer : {
56+
id : 12345678
57+
},
58+
userFields : [
59+
{userField: {name: 'cartId', value: 'xyx1234'}},
60+
{userField: {name: 'discountCode', value: 'xcxcx'}}
61+
]
3362
}
3463
}).then(function (transaction) {
3564
assert.equal(transaction.transactionResponse.responseCode, '1');
3665
done();
66+
}, function(rejection){
67+
done(JSON.stringify(rejection));
3768
});
38-
});
69+
});
3970

4071
it('should reject the promise when web service send an error code', function (done) {
4172
service.authCaptureTransaction(randomAmount(), 234234, 2016, 10).then(function () {
@@ -66,13 +97,17 @@ describe('AuthorizeNet service', function () {
6697
service.authOnlyTransaction(randomAmount(), 4007000000027, 2016, 2).then(function (transaction) {
6798
assert.equal(transaction.transactionResponse.responseCode, '1');
6899
done();
69-
});
100+
}).catch(function(rejection){
101+
done(JSON.stringify(rejection));
102+
})
70103
});
71104

72105
it('should submit authorization only request with extra params', function (done) {
73106
service.authOnlyTransaction(randomAmount(), 4007000000027, 2017, 11, {transactionRequest: {payment: {creditCard: {cardCode: 666}}}}).then(function (transaction) {
74107
assert.equal(transaction.transactionResponse.responseCode, '1');
75108
done();
109+
}).catch(function(rejection){
110+
done(JSON.stringify(rejection));
76111
});
77112
});
78113

@@ -112,8 +147,8 @@ describe('AuthorizeNet service', function () {
112147
assert.equal(trans.transactionResponse.responseCode, '1');
113148
done();
114149
})
115-
.catch(function (err) {
116-
console.log(err);
150+
.catch(function (rejection) {
151+
done(JSON.stringify(rejection));
117152
});
118153
});
119154

@@ -178,6 +213,9 @@ describe('AuthorizeNet service', function () {
178213
.then(function (trans) {
179214
assert.equal(trans.transactionResponse.responseCode, '1');
180215
done();
216+
})
217+
.catch(function(rejection){
218+
done(JSON.stringify(rejection));
181219
});
182220
});
183221

@@ -218,6 +256,9 @@ describe('AuthorizeNet service', function () {
218256
assert.equal(trans.transaction.responseCode, '1');
219257
assert.equal(trans.transaction.transId, transId);
220258
done();
259+
})
260+
.catch(function(rejection){
261+
done(JSON.stringify(rejection));
221262
});
222263
});
223264

@@ -250,6 +291,8 @@ describe('AuthorizeNet service', function () {
250291
service.getUnsettledTransactionList().then(function (response) {
251292
assert(response.transactions, 'transactions field should be defined');
252293
done();
294+
}).catch(function(rejection){
295+
done(JSON.stringify(rejection));
253296
});
254297
});
255298

@@ -261,6 +304,8 @@ describe('AuthorizeNet service', function () {
261304
service.getSettledBatchList(true, new Date(Date.now() - 7 * 24 * 3600 * 1000), new Date()).then(function (response) {
262305
assert(response.batchList, 'batchList should be defined');
263306
done();
307+
}).catch(function(rejection){
308+
done(JSON.stringify(rejection));
264309
});
265310
});
266311

@@ -273,10 +318,12 @@ describe('AuthorizeNet service', function () {
273318
var batchId = response.batchList.batch.length ? response.batchList.batch[0].batchId : response.batchList.batch.batchId;
274319
return service.getBatchStatistics(batchId);
275320
})
276-
.then(function (response) {
277-
assert(response.batch, 'batch should be defined');
278-
done();
279-
});
321+
.then(function (response) {
322+
assert(response.batch, 'batch should be defined');
323+
done();
324+
}).catch(function(rejection){
325+
done(JSON.stringify(rejection));
326+
});
280327
});
281328

282329
it('should reject the promise if any error happens', function (done) {
@@ -298,10 +345,13 @@ describe('AuthorizeNet service', function () {
298345
var batchId = response.batchList.batch.length ? response.batchList.batch[0].batchId : response.batchList.batch.batchId;
299346
return service.getTransactionList(batchId);
300347
})
301-
.then(function (response) {
302-
assert(response.transactions.transaction, 'it should have a list of transactions');
303-
done();
304-
});
348+
.then(function (response) {
349+
assert(response.transactions.transaction, 'it should have a list of transactions');
350+
done();
351+
}).catch(function(rejection){
352+
done(JSON.stringify(rejection));
353+
});
305354
});
306355
});
356+
307357
});

0 commit comments

Comments
 (0)