Permalink
Browse files

Implemented submitting transactions for settlement

  • Loading branch information...
1 parent 810399f commit a641cf5ce186bf0c62926b125ee5438c90b109e6 @braintreeps braintreeps committed Aug 25, 2010
Showing with 80 additions and 2 deletions.
  1. +6 −2 lib/braintree/transaction_gateway.js
  2. +74 −0 spec/braintree/transaction_spec.js
@@ -29,12 +29,16 @@ var TransactionGateway = function(gateway) {
};
return {
- sale: function(attributes, callback) {
+ sale: function (attributes, callback) {
attributes.type = 'sale';
return create(attributes, callback);
},
- void: function(transaction_id, callback) {
+ submitForSettlement: function (transaction_id, callback) {
+ my.gateway.http.put('/transactions/' + transaction_id + '/submit_for_settlement', null, responseHandler(callback));
+ },
+
+ void: function (transaction_id, callback) {
my.gateway.http.put('/transactions/' + transaction_id + '/void', null, responseHandler(callback));
}
};
@@ -79,6 +79,55 @@ vows.describe('Transaction').addBatch({
}
},
+ 'submitForSettlement': {
+ 'when submitting an authorized transaction for settlement': {
+ topic: function () {
+ var callback = this.callback;
+ specHelper.defaultGateway.transaction.sale(
+ {
+ amount: '5.00',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/12'
+ }
+ },
+ function (err, response) {
+ specHelper.defaultGateway.transaction.submitForSettlement(response.transaction.id, callback);
+ }
+ )
+ },
+ 'does not have an error': function (err, response) { assert.isNull(err); },
+ 'is succesful': function (err, response) { assert.equal(response.success, true); },
+ 'sets the status to submitted_for_settlement': function (err, response) { assert.equal(response.transaction.status, 'submitted_for_settlement'); },
+ },
+
+ 'when transaction cannot be submitted for settlement': {
+ topic: function () {
+ var callback = this.callback;
+ specHelper.defaultGateway.transaction.sale(
+ {
+ amount: '5.00',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/12'
+ },
+ options: {
+ submitForSettlement: true
+ }
+ },
+ function (err, response) {
+ specHelper.defaultGateway.transaction.submitForSettlement(response.transaction.id, callback);
+ }
+ )
+ },
+ 'does not have an error': function (err, response) { assert.isNull(err); },
+ 'is not succesful': function (err, response) { assert.equal(response.success, false); },
+ 'has error 91507 on base': function (err, response) {
+ assert.equal(response.errors.for('transaction').on('base').code, '91507');
+ }
+ }
+ },
+
'void': {
'when voiding an authorized transaction': {
topic: function () {
@@ -99,6 +148,31 @@ vows.describe('Transaction').addBatch({
'does not have an error': function (err, response) { assert.isNull(err); },
'is succesful': function (err, response) { assert.equal(response.success, true); },
'sets the status to voided': function (err, response) { assert.equal(response.transaction.status, 'voided'); },
+ },
+
+ 'when transaction cannot be voided': {
+ topic: function () {
+ var callback = this.callback;
+ specHelper.defaultGateway.transaction.sale(
+ {
+ amount: '5.00',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/12'
+ }
+ },
+ function (err, response) {
+ specHelper.defaultGateway.transaction.void(response.transaction.id, function (err, response) {
+ specHelper.defaultGateway.transaction.void(response.transaction.id, callback);
+ });
+ }
+ )
+ },
+ 'does not have an error': function (err, response) { assert.isNull(err); },
+ 'is not succesful': function (err, response) { assert.equal(response.success, false); },
+ 'has error 91504 on base': function (err, response) {
+ assert.equal(response.errors.for('transaction').on('base').code, '91504');
+ }
}
}
}).export(module);

0 comments on commit a641cf5

Please sign in to comment.