Permalink
Browse files

0.4.1

  • Loading branch information...
1 parent f97f749 commit 463ab0575170669eebbd618c3efdb1791f04260b @braintreeps braintreeps committed Nov 14, 2011
View
@@ -8,6 +8,6 @@ connect = (config) ->
new BraintreeGateway(new Config(config))
exports.connect = connect
-exports.version = '0.4.0'
+exports.version = '0.4.1'
exports.Environment = Environment
exports.errorTypes = errorTypes
@@ -1,5 +1,6 @@
{Gateway} = require('./gateway')
{Address} = require('./address')
+exceptions = require('./exceptions')
class AddressGateway extends Gateway
constructor: (@gateway) ->
@@ -13,11 +14,14 @@ class AddressGateway extends Gateway
@gateway.http.delete("/customers/#{customerId}/addresses/#{id}", callback)
find: (customerId, id, callback) ->
- @gateway.http.get "/customers/#{customerId}/addresses/#{id}", (err, response) ->
- if err
- callback(err, null)
- else
- callback(null, response.address)
+ if(customerId.trim() == '' || id.trim() == '')
+ callback(exceptions.NotFoundError(), null)
+ else
+ @gateway.http.get "/customers/#{customerId}/addresses/#{id}", (err, response) ->
+ if err
+ callback(err, null)
+ else
+ callback(null, response.address)
update: (customerId, id, attributes, callback) ->
@gateway.http.put("/customers/#{customerId}/addresses/#{id}", {address: attributes}, @responseHandler(callback))
@@ -1,5 +1,6 @@
{Gateway} = require('./gateway')
{CreditCard} = require('./credit_card')
+exceptions = require('./exceptions')
class CreditCardGateway extends Gateway
constructor: (@gateway) ->
@@ -11,11 +12,14 @@ class CreditCardGateway extends Gateway
@gateway.http.delete("/payment_methods/#{token}", callback)
find: (token, callback) ->
- @gateway.http.get "/payment_methods/#{token}", (err, response) ->
- if err
- callback(err, null)
- else
- callback(null, new CreditCard(response.creditCard))
+ if(token.trim() == '')
+ callback(exceptions.NotFoundError(), null)
+ else
+ @gateway.http.get "/payment_methods/#{token}", (err, response) ->
+ if err
+ callback(err, null)
+ else
+ callback(null, new CreditCard(response.creditCard))
update: (token, attributes, callback) ->
@gateway.http.put("/payment_methods/#{token}", {creditCard: attributes}, @responseHandler(callback))
@@ -1,5 +1,6 @@
{Gateway} = require('./gateway')
{Customer} = require('./customer')
+exceptions = require('./exceptions')
class CustomerGateway extends Gateway
constructor: (@gateway) ->
@@ -11,11 +12,14 @@ class CustomerGateway extends Gateway
@gateway.http.delete("/customers/#{customerId}", callback)
find: (customerId, callback) ->
- @gateway.http.get "/customers/#{customerId}", (err, response) ->
- if err
- callback(err, null)
- else
- callback(null, new Customer(response.customer))
+ if(customerId.trim() == '')
+ callback(exceptions.NotFoundError(), null)
+ else
+ @gateway.http.get "/customers/#{customerId}", (err, response) ->
+ if err
+ callback(err, null)
+ else
+ callback(null, new Customer(response.customer))
update: (customerId, attributes, callback) ->
@gateway.http.put("/customers/#{customerId}", {customer: attributes}, @responseHandler(callback))
@@ -1,6 +1,7 @@
{Gateway} = require('./gateway')
{Subscription} = require('./subscription')
{TransactionGateway} = require('./transaction_gateway')
+exceptions = require('./exceptions')
class SubscriptionGateway extends Gateway
constructor: (@gateway) ->
@@ -12,11 +13,14 @@ class SubscriptionGateway extends Gateway
@gateway.http.put("/subscriptions/#{subscriptionId}/cancel", null, @responseHandler(callback))
find: (subscriptionId, callback) ->
- @gateway.http.get "/subscriptions/#{subscriptionId}", (err, response) ->
- if err
- callback(err, null)
- else
- callback(null, new Subscription(response.subscription))
+ if(subscriptionId.trim() == '')
+ callback(exceptions.NotFoundError(), null)
+ else
+ @gateway.http.get "/subscriptions/#{subscriptionId}", (err, response) ->
+ if err
+ callback(err, null)
+ else
+ callback(null, new Subscription(response.subscription))
responseHandler: (callback) ->
@createResponseHandler("subscription", Subscription, callback)
@@ -1,6 +1,7 @@
{Gateway} = require('./gateway')
{Transaction} = require('./transaction')
{ErrorResponse} = require('./error_response')
+exceptions = require('./exceptions')
class TransactionGateway extends Gateway
constructor: (@gateway) ->
@@ -16,11 +17,14 @@ class TransactionGateway extends Gateway
@create(attributes, callback)
find: (transactionId, callback) ->
- @gateway.http.get "/transactions/#{transactionId}", (err, response) ->
- if err
- callback(err, null)
- else
- callback(null, new Transaction(response.transaction))
+ if(transactionId.trim() == '')
+ callback(exceptions.NotFoundError(), null)
+ else
+ @gateway.http.get "/transactions/#{transactionId}", (err, response) ->
+ if err
+ callback(err, null)
+ else
+ callback(null, new Transaction(response.transaction))
refund: (transactionId, amount..., callback) ->
@gateway.http.post("/transactions/#{transactionId}/refund", {transaction: {amount: amount[0]}}, @responseHandler(callback))
@@ -25,6 +25,8 @@ class XmlParser
obj[name] = []
else if child.attributes.length is 1 && child.attributes[0].name is 'type' && child.attributes[0].value is 'array'
obj[name] = (@convertNodeToObject(arrayItem)[Util.toCamelCase(arrayItem.nodeName)] for arrayItem in child.childNodes when arrayItem.nodeType isnt TEXT_NODE)
+ else if child.childNodes.length is 0 && child.attributes.length is 0
+ obj[name] = ''
else
obj[name] = @convertNodeToObject(child)[Util.toCamelCase(child.nodeName)]
object[Util.toCamelCase(node.nodeName)] = obj
View
@@ -1,6 +1,6 @@
{
"name" : "braintree",
- "version" : "0.4.0",
+ "version" : "0.4.1",
"description" : "A library for integrating with Braintree.",
"keywords" : ["payments"],
"homepage" : "http://github.com/braintree/braintree_node",
@@ -138,7 +138,26 @@ vows.describe('AddressGateway').addBatch({
'does not return an address': function (err, address) {
assert.isNull(address);
}
+ },
+
+ 'when the customer id is whitespace': {
+ topic: function () {
+ specHelper.defaultGateway.address.find(" ", "id", this.callback);
+ },
+ 'returns a not found error': function (err, address) {
+ assert.equal(err.type, braintree.errorTypes.notFoundError);
+ }
+ },
+
+ 'when the address id is whitespace': {
+ topic: function () {
+ specHelper.defaultGateway.address.find("blah", "\t ", this.callback);
+ },
+ 'returns a not found error': function (err, address) {
+ assert.equal(err.type, braintree.errorTypes.notFoundError);
+ }
}
+
},
'update': {
@@ -5,8 +5,8 @@ var braintree = specHelper.braintree;
vows.describe('Braintree').addBatch({
'version': {
topic: braintree.version,
- 'is 0.4.0': function (version) {
- assert.equal(version, '0.4.0');
+ 'is 0.4.1': function (version) {
+ assert.equal(version, '0.4.1');
}
},
@@ -202,6 +202,15 @@ vows.describe('CreditCardGateway').addBatch({
assert.equal(err.type, braintree.errorTypes.notFoundError);
}
},
+
+ 'when the id is whitespace': {
+ topic: function () {
+ specHelper.defaultGateway.creditCard.find(" ", this.callback);
+ },
+ 'returns a not found error': function (err, address) {
+ assert.equal(err.type, braintree.errorTypes.notFoundError);
+ }
+ },
},
'update': {
@@ -302,7 +302,18 @@ vows.describe('CustomerGateway').addBatch({
specHelper.defaultGateway.customer.create(
{
firstName: 'John',
- lastName: 'Smith'
+ lastName: 'Smith',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/2014',
+ billingAddress: {
+ company: '',
+ streetAddress: '123 E Fake St',
+ locality: 'Chicago',
+ region: 'IL',
+ postalCode: '60607'
+ }
+ }
},
function (err, response) {
specHelper.defaultGateway.customer.find(response.customer.id, callback);
@@ -313,7 +324,12 @@ vows.describe('CustomerGateway').addBatch({
'returns customer details': function (err, customer) {
assert.equal(customer.firstName, 'John');
assert.equal(customer.lastName, 'Smith');
- }
+ },
+ 'returns the billing address details, including empty strings': function (err, customer) {
+ var billingAddress = customer.creditCards[0].billingAddress;
+ assert.equal(billingAddress.streetAddress, '123 E Fake St');
+ assert.equal(billingAddress.company, '');
+ },
},
'when not found': {
@@ -324,6 +340,15 @@ vows.describe('CustomerGateway').addBatch({
assert.equal(err.type, braintree.errorTypes.notFoundError);
}
},
+
+ 'when the id is whitespace': {
+ topic: function () {
+ specHelper.defaultGateway.customer.find(" ", this.callback);
+ },
+ 'returns a not found error': function (err, address) {
+ assert.equal(err.type, braintree.errorTypes.notFoundError);
+ }
+ },
},
'update': {
@@ -440,7 +465,7 @@ vows.describe('CustomerGateway').addBatch({
assert.equal(billingAddress.region, 'IL');
assert.equal(billingAddress.postalCode, '60607');
assert.equal(response.customer.addresses[0].streetAddress, '123 E Fake St');
- }
+ },
},
'with updating an existing card': {
@@ -301,7 +301,16 @@ vows.describe('SubscriptionGateway').addBatch({
'has a not found error': function (err, response) {
assert.equal(err.type, braintree.errorTypes.notFoundError);
},
- }
+ },
+
+ 'when the id is whitespace': {
+ topic: function () {
+ specHelper.defaultGateway.subscription.find(" ", this.callback);
+ },
+ 'returns a not found error': function (err, address) {
+ assert.equal(err.type, braintree.errorTypes.notFoundError);
+ }
+ },
},
'retryCharge': {
@@ -327,6 +327,15 @@ vows.describe('TransactionGateway').addBatch({
assert.equal(err.type, braintree.errorTypes.notFoundError);
}
},
+
+ 'when the id is whitespace': {
+ topic: function () {
+ specHelper.defaultGateway.transaction.find(" ", this.callback);
+ },
+ 'returns a not found error': function (err, address) {
+ assert.equal(err.type, braintree.errorTypes.notFoundError);
+ }
+ },
},
'refund': {
@@ -8,7 +8,7 @@ var CUSTOMER_XML = [
' <merchant-id>integration_merchant_id</merchant-id>',
' <first-name>Dan</first-name>',
' <last-name nil="true"></last-name>',
-' <company nil="true"></company>',
+' <company></company>',
' <email nil="true"></email>',
' <phone nil="true"></phone>',
' <fax nil="true"></fax>',
@@ -86,6 +86,9 @@ vows.describe('XmlParser').addBatch({
'parses nil values': function (result) {
assert.equal(result.customer.lastName, null);
},
+ 'parses empty values': function (result) {
+ assert.equal(result.customer.company, '');
+ },
'parses boolean values': function (result) {
assert.equal(result.customer.creditCards[0].default, true);
assert.equal(result.customer.creditCards[0].expired, false);

0 comments on commit 463ab05

Please sign in to comment.