Permalink
Browse files

0.4.0

  • Loading branch information...
1 parent fa8d8fb commit f97f7492e7b13f4989bc535eeef7a41647c90bbc @braintreeps braintreeps committed Oct 7, 2011
View
@@ -3,3 +3,4 @@
/node_modules/o3-xml
/node_modules/underscore
/node_modules/vows
+/tags
View
@@ -8,6 +8,6 @@ connect = (config) ->
new BraintreeGateway(new Config(config))
exports.connect = connect
-exports.version = '0.3.0'
+exports.version = '0.4.0'
exports.Environment = Environment
exports.errorTypes = errorTypes
@@ -5,6 +5,9 @@
class TransactionGateway extends Gateway
constructor: (@gateway) ->
+ cloneTransaction: (transactionId, attributes, callback) ->
+ @gateway.http.post("/transactions/#{transactionId}/clone", {transactionClone: attributes}, @responseHandler(callback))
+
create: (attributes, callback) ->
@gateway.http.post('/transactions', {transaction: attributes}, @responseHandler(callback))
View
@@ -1,6 +1,6 @@
{
"name" : "braintree",
- "version" : "0.3.0",
+ "version" : "0.4.0",
"description" : "A library for integrating with Braintree.",
"keywords" : ["payments"],
"homepage" : "http://github.com/braintree/braintree_node",
@@ -16,6 +16,6 @@
},
"devDependencies" : {
"underscore" : "=1.1.6",
- "vows" : "=0.5.8"
+ "vows" : "=0.5.11"
}
}
@@ -88,7 +88,7 @@ vows.describe('AddressGateway').addBatch({
);
},
'deletes the address': function (err, address) {
- assert.isUndefined(address);
+ assert.isNull(address);
assert.equal(err.type, braintree.errorTypes.notFoundError);
}
}
@@ -136,7 +136,7 @@ vows.describe('AddressGateway').addBatch({
assert.equal(err.type, braintree.errorTypes.notFoundError);
},
'does not return an address': function (err, address) {
- assert.isUndefined(address);
+ assert.isNull(address);
}
}
},
@@ -5,8 +5,8 @@ var braintree = specHelper.braintree;
vows.describe('Braintree').addBatch({
'version': {
topic: braintree.version,
- 'is 0.3.0': function (version) {
- assert.equal(version, '0.3.0');
+ 'is 0.4.0': function (version) {
+ assert.equal(version, '0.4.0');
}
},
@@ -51,7 +51,7 @@ vows.describe('SettlementBatchSummaryGateway').addBatch({
}
}, function (err, response) {
specHelper.settleTransaction(response.transaction.id, function (err, response) {
- formattedDate = specHelper.dateToMdy(new Date());
+ formattedDate = specHelper.dateToMdy(specHelper.nowInEastern());
specHelper.defaultGateway.settlementBatchSummary.generate(
{settlementDate: formattedDate},
callback
@@ -89,7 +89,7 @@ vows.describe('SettlementBatchSummaryGateway').addBatch({
}
}, function (err, response) {
specHelper.settleTransaction(response.transaction.id, function (err, response) {
- formattedDate = specHelper.dateToMdy(new Date);
+ formattedDate = specHelper.dateToMdy(specHelper.nowInEastern());
specHelper.defaultGateway.settlementBatchSummary.generate(
{settlementDate: formattedDate, groupByCustomField: "store_me"},
callback
@@ -289,6 +289,9 @@ vows.describe('SubscriptionGateway').addBatch({
assert.equal(subscription.planId, specHelper.plans.trialless.id);
assert.equal(subscription.price, specHelper.plans.trialless.price);
assert.equal(subscription.status, 'Active');
+ },
+ 'contains the current billing cycle': function(err, subscription) {
+ assert.equal(subscription.currentBillingCycle, 1);
}
},
'when the subscription cannot be found': {
@@ -522,5 +522,70 @@ vows.describe('TransactionGateway').addBatch({
assert.equal(response.errors.for('transaction').on('base')[0].code, '91504');
}
}
+ },
+ 'cloneTransaction': {
+ 'for a minimal case': {
+ topic: function () {
+ var callback = this.callback;
+ specHelper.defaultGateway.transaction.sale({
+ amount: '5.00',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/12'
+ }
+ }, function (err, result) {
+ specHelper.defaultGateway.transaction.cloneTransaction(result.transaction.id, {amount: "123.45", options: {submitForSettlement: "false"}}, callback);
+ });
+ },
+ 'is successful': function (err, response) {
+ assert.equal(response.success, true);
+ assert.equal(response.transaction.status, "authorized");
+ },
+ 'it copies fields': function(err, response) {
+ transaction = response.transaction;
+ assert.equal(transaction.amount, "123.45");
+ assert.equal(transaction.creditCard.maskedNumber, "510510******5100");
+ assert.equal(transaction.creditCard.expirationDate, "05/2012");
+ }
+ },
+ 'with validation errors': {
+ topic: function () {
+ var callback = this.callback;
+ specHelper.defaultGateway.transaction.credit({
+ amount: '5.00',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/12'
+ }
+ }, function (err, result) {
+ specHelper.defaultGateway.transaction.cloneTransaction(result.transaction.id, {amount: "123.45"}, callback);
+ });
+ },
+ 'is unsuccessful': function (err, response) { assert.equal(response.success, false); },
+ 'has an error on base': function (err, response) {
+ assert.equal(
+ response.errors.for('transaction').on('base')[0].code,
+ '91543'
+ );
+ }
+ },
+ 'with submitForSettlement': {
+ topic: function () {
+ var callback = this.callback;
+ specHelper.defaultGateway.transaction.sale({
+ amount: '5.00',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/12'
+ }
+ }, function (err, result) {
+ specHelper.defaultGateway.transaction.cloneTransaction(result.transaction.id, {amount: "123.45", options: {submitForSettlement: "true"}}, callback);
+ });
+ },
+ 'is successful': function (err, response) {
+ assert.equal(response.success, true);
+ assert.equal(response.transaction.status, "submitted_for_settlement");
+ }
+ }
}
}).export(module);
View
@@ -86,6 +86,11 @@ dateToMdy = (date) ->
formattedDate = year + '-' + month + '-' + day
return formattedDate
+nowInEastern = ->
+ now = new Date
+ eastern = now.getTime() - (5*60*60*1000)
+ return new Date(eastern)
+
GLOBAL.specHelper = {
addOns: addOns
braintree: braintree
@@ -94,6 +99,7 @@ GLOBAL.specHelper = {
defaultGateway: defaultGateway
makePastDue: makePastDue
multiplyString: multiplyString
+ nowInEastern: nowInEastern
plans: plans
settleTransaction: settleTransaction
simulateTrFormPost: simulateTrFormPost

0 comments on commit f97f749

Please sign in to comment.