Skip to content

Commit 82179fe

Browse files
committed
add get transaction list based on a batch
1 parent 77cd0e9 commit 82179fe

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

lib/AuthorizeNet.js

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ AuthorizeNet.prototype.authCaptureTransaction = function authCaptureTransaction(
115115
assert(expirationYear, 'expirationYear is required');
116116
assert(expirationMonth, 'expirationMonth is required');
117117

118-
var creditCard = { cardNumber: cardNumber, expirationDate: expirationYear.toString() + '-' + expirationMonth.toString() };
118+
var creditCard = {
119+
cardNumber: cardNumber,
120+
expirationDate: expirationYear.toString() + '-' + expirationMonth.toString()
121+
};
119122
var transactionRequest = {
120123
transactionRequest: {
121124
amount: amount,
@@ -162,7 +165,10 @@ AuthorizeNet.prototype.authOnlyTransaction = function authOnlyTransaction(amount
162165
assert(expirationYear, 'expirationYear is required');
163166
assert(expirationMonth, 'expirationMonth is required');
164167

165-
var creditCard = { cardNumber: cardNumber, expirationDate: expirationYear.toString() + '-' + expirationMonth.toString() };
168+
var creditCard = {
169+
cardNumber: cardNumber,
170+
expirationDate: expirationYear.toString() + '-' + expirationMonth.toString()
171+
};
166172
var transactionRequest = {
167173
merchantAuthentication: self.merchantInfo,
168174
transactionRequest: {
@@ -221,6 +227,16 @@ AuthorizeNet.prototype.priorAuthCaptureTransaction = function captureOnlyTransac
221227
});
222228
};
223229

230+
/**
231+
* Refund an already settled transaction
232+
* @param refTransId - a reference to the transaction to refund
233+
* @param amount - the amount to refund
234+
* @param cardNumber - the card number used to process the transaction
235+
* @param expirationYear - the expiration year of the card used to process the transaction
236+
* @param expirationMonth - the expiration month of the transaction card used to process the transaction
237+
* @param other - some other fields to merge with the request
238+
* @returns {Promise}
239+
*/
224240
AuthorizeNet.prototype.refundTransaction = function refundTransaction(refTransId, amount, cardNumber, expirationYear, expirationMonth, other) {
225241
var self = this;
226242

@@ -232,7 +248,10 @@ AuthorizeNet.prototype.refundTransaction = function refundTransaction(refTransId
232248
assert(expirationYear, 'expirationYear is required');
233249
assert(expirationMonth, 'expirationMonth is required');
234250

235-
var creditCard = { cardNumber: cardNumber, expirationDate: expirationYear.toString() + '-' + expirationMonth.toString() };
251+
var creditCard = {
252+
cardNumber: cardNumber,
253+
expirationDate: expirationYear.toString() + '-' + expirationMonth.toString()
254+
};
236255
var transactionRequest = {
237256
merchantAuthentication: self.merchantInfo,
238257
transactionRequest: {
@@ -427,4 +446,20 @@ AuthorizeNet.prototype.getBatchStatistics = function getBatchStatistics(batchId)
427446
});
428447
};
429448

449+
AuthorizeNet.prototype.getTransactionList = function (batchId) {
450+
var self = this;
451+
452+
return new Promise(function (resolve, reject) {
453+
454+
assert(batchId, 'batchId is mandatory');
455+
456+
var batchRequest = {
457+
merchantAuthentication: self.merchantInfo,
458+
batchId: batchId
459+
};
460+
461+
request.post(generateRequestConfiguration(self, batchRequest, 'getTransactionListRequest'), requestCallBack(resolve, reject, 'getTransactionListResponse'));
462+
})
463+
};
464+
430465
module.exports = AuthorizeNet;

package.json

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

test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ describe('AuthorizeNet service', function () {
2626
});
2727

2828
it('should submit authorizationCapture request with some extra params', function (done) {
29-
service.authCaptureTransaction(randomAmount(), 4012888818888, 2016, 10, {transactionRequest: {payment: {creditCard: {cardCode: 999}}, billTo: {firstName: 'bob', lastName: 'Eponge'}}}).then(function (transaction) {
29+
service.authCaptureTransaction(randomAmount(), 4012888818888, 2016, 10, {
30+
transactionRequest: {
31+
payment: {creditCard: {cardCode: 999}},
32+
billTo: {firstName: 'bob', lastName: 'Eponge'}
33+
}
34+
}).then(function (transaction) {
3035
assert.equal(transaction.transactionResponse.responseCode, '1');
3136
done();
3237
});
@@ -284,4 +289,19 @@ describe('AuthorizeNet service', function () {
284289
});
285290
});
286291
});
292+
293+
describe('get transactions list', function () {
294+
295+
it('should get the transaction list of a given batch', function (done) {
296+
service.getSettledBatchList(true, new Date(Date.now() - 7 * 24 * 3600 * 1000), new Date()).then(function (response) {
297+
assert(response.batchList, 'batchList should be defined');
298+
var batchId = response.batchList.batch.length ? response.batchList.batch[0].batchId : response.batchList.batch.batchId;
299+
return service.getTransactionList(batchId);
300+
})
301+
.then(function (response) {
302+
assert(response.transactions.transaction, 'it should have a list of transactions');
303+
done();
304+
});
305+
});
306+
});
287307
});

0 commit comments

Comments
 (0)