Permalink
Browse files

0.2.0

  • Loading branch information...
1 parent a641cf5 commit b0aa0209ccbc0870a2648560f806beef6851acbf @braintreeps braintreeps committed May 29, 2011
Showing with 4,350 additions and 543 deletions.
  1. +4 −0 .gitignore
  2. +22 −0 LICENSE
  3. +58 −39 README.md
  4. +1 −1 Rakefile
  5. +17 −10 lib/braintree.js
  6. +43 −0 lib/braintree/address_gateway.coffee
  7. +11 −0 lib/braintree/config.coffee
  8. +0 −11 lib/braintree/config.js
  9. +9 −0 lib/braintree/credit_card.coffee
  10. +0 −13 lib/braintree/credit_card.js
  11. +47 −0 lib/braintree/credit_card_gateway.coffee
  12. +10 −0 lib/braintree/customer.coffee
  13. +47 −0 lib/braintree/customer_gateway.coffee
  14. +20 −0 lib/braintree/digest.coffee
  15. +15 −0 lib/braintree/environment.coffee
  16. +0 −13 lib/braintree/environment.js
  17. +13 −0 lib/braintree/error_response.coffee
  18. +0 −16 lib/braintree/error_response.js
  19. +8 −0 lib/braintree/error_types.coffee
  20. +58 −0 lib/braintree/exceptions.coffee
  21. +0 −10 lib/braintree/exceptions/authentication_error.js
  22. +0 −2 lib/braintree/exceptions/error_types.js
  23. +0 −10 lib/braintree/exceptions/unexpected_error.js
  24. +9 −0 lib/braintree/gateway.coffee
  25. +0 −10 lib/braintree/gateway.js
  26. +69 −0 lib/braintree/http.coffee
  27. +0 −62 lib/braintree/http.js
  28. +10 −0 lib/braintree/subscription.coffee
  29. +53 −0 lib/braintree/subscription_gateway.coffee
  30. +10 −0 lib/braintree/transaction.coffee
  31. +0 −14 lib/braintree/transaction.js
  32. +58 −0 lib/braintree/transaction_gateway.coffee
  33. +0 −47 lib/braintree/transaction_gateway.js
  34. +85 −0 lib/braintree/transparent_redirect_gateway.coffee
  35. +26 −0 lib/braintree/util.coffee
  36. +8 −0 lib/braintree/validation_error.coffee
  37. +0 −9 lib/braintree/validation_error.js
  38. +39 −0 lib/braintree/validation_errors_collection.coffee
  39. +0 −54 lib/braintree/validation_errors_collection.js
  40. +41 −0 lib/braintree/xml_parser.coffee
  41. +1 −0 node_modules/.bin/cake
  42. +1 −0 node_modules/.bin/coffee
  43. +1 −0 node_modules/.bin/vows
  44. +64 −0 node_modules/dateformat/Readme.md
  45. +135 −0 node_modules/dateformat/lib/dateformat.js
  46. +14 −0 node_modules/dateformat/package.json
  47. +19 −10 package.json
  48. +234 −0 spec/braintree/address_gateway_spec.js
  49. +6 −4 spec/braintree/braintree_spec.js
  50. +338 −0 spec/braintree/credit_card_gateway_spec.js
  51. +596 −0 spec/braintree/customer_gateway_spec.js
  52. +20 −0 spec/braintree/digest_spec.js
  53. +52 −7 spec/braintree/http_spec.js
  54. +443 −0 spec/braintree/subscription_gateway_spec.js
  55. +530 −0 spec/braintree/transaction_gateway_spec.js
  56. +0 −178 spec/braintree/transaction_spec.js
  57. +316 −0 spec/braintree/transparent_redirect_gateway_spec.js
  58. +78 −0 spec/braintree/util_spec.js
  59. +21 −0 spec/braintree/validation_errors_collection_spec.js
  60. +131 −0 spec/braintree/xml_parser_spec.js
  61. +80 −0 spec/spec_helper.coffee
  62. +0 −23 spec/spec_helper.js
  63. +17 −0 vendor/querystring.node.js.511d6a2/LICENSE.md
  64. +51 −0 vendor/querystring.node.js.511d6a2/README.md
  65. +132 −0 vendor/querystring.node.js.511d6a2/querystring-parse.js
  66. +75 −0 vendor/querystring.node.js.511d6a2/querystring-stringify.js
  67. +27 −0 vendor/querystring.node.js.511d6a2/querystring.js
  68. +126 −0 vendor/querystring.node.js.511d6a2/test.js
  69. +51 −0 vendor/querystring.node.js.511d6a2/util.js
View
@@ -0,0 +1,4 @@
+/node_modules/coffee-script
+/node_modules/o3-xml
+/node_modules/underscore
+/node_modules/vows
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2010-2011 Braintree
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,25 +1,43 @@
## Overview
-This is a node.js library for integrating with the Braintree gateway. It is a work in progress, very much alpha. Feedback is appreciated.
-It can be used in the sandbox environment, [contact us](mailto:support@getbraintree.com) if you're interested in using
-it in production.
+This is a Node.js library for integrating with the [Braintree](http://www.braintreepayments.com) gateway.
+
+The library is a work in progress and a few features are still missing. Until
+we hit version 1.0 we may break backwards compatibility, but the changes
+should be minimal. We're using [semantic versioning](http://semver.org/).
+[Email us](mailto:support@braintreepayments.com) if you have any questions.
## Installing
-* clone this repo somewhere in your require.paths
-* require 'braintree-node/lib/braintree'
-* npm coming soon!
+### From NPM
+
+* npm install braintree
+* var braintree = require('braintree')
+
+### From Source
+
+* clone the latest tag somewhere in your require.paths
+* var braintree = require('braintree-node/lib/braintree')
+
+### Dependencies
+
+* node ~0.4.7
+* coffee-script ~1.1
+* o3-xml ~0.1.0
+
+## Not Yet Implemented
+
+* search APIs (transactions, vault, subscriptions, expired cards)
-## Dependencies
+## Links
-* node 0.2.0
-* underscore.js
+* [Documentation](http://www.braintreepayments.com/docs/node)
+* [Bug Tracker](http://github.com/braintree/braintree_node/issues)
## Quick Start
var sys = require('sys'),
- _ = require('underscore')._,
- braintree = require('braintree-node/lib/braintree');
+ braintree = require('braintree');
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
@@ -28,32 +46,33 @@ it in production.
privateKey: 'your_private_key'
});
- gateway.transaction.sale(
- {
- amount: '5.00',
- creditCard: {
- number: '5105105105105100',
- expirationDate: '05/12'
- }
- },
- function (err, response) {
- if (err) {
- sys.puts(err.message);
- return;
- }
-
- if (response.success) {
- sys.puts('Transaction id: ' + response.transaction.id);
- sys.puts('Transaction status: ' + response.transaction.status);
- sys.puts('Transaction amount: ' + response.transaction.amount);
- } else {
- if (response.transaction) {
- sys.puts('Transaction status: ' + response.transaction.status);
- } else {
- _.each(response.errors.deepErrors(), function (error) {
- sys.puts(error.message);
- });
- }
- }
+ gateway.transaction.sale({
+ amount: '5.00',
+ creditCard: {
+ number: '5105105105105100',
+ expirationDate: '05/12'
}
- );
+ }, function (err, result) {
+ if (err) throw err;
+
+ if (result.success) {
+ sys.puts('Transaction ID: ' + result.transaction.id);
+ } else {
+ sys.puts(result.message);
+ }
+ });
+
+## Maintainers
+
+The Braintree Node library is maintained by the Braintree dev team.
+
+* [Dan Manges](https://github.com/dan-manges)
+* [Patrick Schless](https://github.com/plainlystated)
+* [Paul Gross](https://github.com/pgr0ss)
+* [Drew Olson](https://github.com/drewolson)
+* [Hammer](https://github.com/thehammer)
+* [Paul Hinze](https://github.com/phinze)
+* [Ali Aghareza](https://github.com/aghareza)
+* [Tony Pitluga](https://github.com/pitluga)
+* [Ben Mills](https://github.com/benmills)
+
View
@@ -2,5 +2,5 @@ task :default => :spec
desc "run the specs"
task :spec do
- sh "vows"
+ sh "./node_modules/.bin/vows " + Dir.glob("spec/**/*_spec.js").join(" ")
end
View
@@ -1,24 +1,31 @@
+require('coffee-script');
+
var sys = require("sys"),
Config = require("./braintree/config").Config,
Environment = require("./braintree/environment").Environment,
Gateway = require("./braintree/gateway").Gateway,
- TransactionGateway = require("./braintree/transaction_gateway").TransactionGateway;
- AuthenticationError = require("./braintree/exceptions/authentication_error").AuthenticationError,
- errorTypes = require("./braintree/exceptions/error_types");
-
-if (process.version !== 'v0.2.0') {
- sys.puts('WARNING: node.js version ' + process.version + ' has not been tested with the braintree library');
-}
+ AddressGateway = require("./braintree/address_gateway").AddressGateway,
+ CreditCardGateway = require("./braintree/credit_card_gateway").CreditCardGateway,
+ CustomerGateway = require("./braintree/customer_gateway").CustomerGateway,
+ SubscriptionGateway = require("./braintree/subscription_gateway").SubscriptionGateway,
+ TransactionGateway = require("./braintree/transaction_gateway").TransactionGateway,
+ TransparentRedirectGateway = require("./braintree/transparent_redirect_gateway").TransparentRedirectGateway,
+ errorTypes = require("./braintree/error_types");
var connect = function(config) {
var gateway = Gateway(Config(config));
return {
- transaction: TransactionGateway(gateway)
+ _gateway: gateway,
+ address: AddressGateway(gateway),
+ creditCard: CreditCardGateway(gateway),
+ customer: CustomerGateway(gateway),
+ subscription: SubscriptionGateway(gateway),
+ transaction: TransactionGateway(gateway),
+ transparentRedirect: TransparentRedirectGateway(gateway)
};
};
exports.connect = connect;
-exports.version = '0.1.0';
-exports.AuthenticationError = AuthenticationError;
+exports.version = '0.2.0';
exports.Environment = Environment;
exports.errorTypes = errorTypes;
@@ -0,0 +1,43 @@
+ErrorResponse = require('./error_response').ErrorResponse
+
+AddressGateway = (gateway) ->
+ my = { gateway: gateway }
+
+ create = (attributes, callback) ->
+ customerId = attributes.customerId
+ delete(attributes.customerId)
+ my.gateway.http.post("/customers/#{customerId}/addresses", {address: attributes}, responseHandler(callback))
+
+ destroy = (customerId, id, callback) ->
+ my.gateway.http.delete("/customers/#{customerId}/addresses/#{id}", callback)
+
+ find = (customerId, id, callback) ->
+ callback = callback
+ my.gateway.http.get("/customers/#{customerId}/addresses/#{id}" , (err, response) ->
+ return callback(err, null) if err
+ callback(null, response.address)
+ )
+
+
+ update = (customerId, id, attributes, callback) ->
+ my.gateway.http.put("/customers/#{customerId}/addresses/#{id}", {address: attributes}, responseHandler(callback))
+
+ responseHandler = (callback) ->
+ return (err, response) ->
+ return callback(err, response) if err
+
+ if (response.address)
+ response.success = true
+ callback(null, response)
+ else if (response.apiErrorResponse)
+ callback(null, ErrorResponse(response.apiErrorResponse))
+
+ {
+ create: create,
+ delete: destroy,
+ find: find,
+ update: update
+ }
+
+exports.AddressGateway = AddressGateway
+
@@ -0,0 +1,11 @@
+Config = (rawConfig) ->
+ {
+ apiVersion: '2',
+ environment: rawConfig.environment,
+ merchantId: rawConfig.merchantId,
+ publicKey: rawConfig.publicKey,
+ privateKey: rawConfig.privateKey,
+ baseMerchantPath: '/merchants/' + rawConfig.merchantId
+ }
+
+exports.Config = Config
View
@@ -1,11 +0,0 @@
-var Config = function (rawConfig) {
- return {
- environment: rawConfig.environment,
- merchant_id: rawConfig.merchantId,
- public_key: rawConfig.publicKey,
- private_key: rawConfig.privateKey,
- baseMerchantPath: '/merchants/' + rawConfig.merchantId
- };
-};
-
-exports.Config = Config;
@@ -0,0 +1,9 @@
+CreditCard = (attributes) ->
+ that = {}
+ for key, value of attributes
+ that[key] = value
+ that.maskedNumber = that.bin + '******' + that.last4
+ that.expirationDate = that.expirationMonth + '/' + that.expirationYear
+ that
+
+exports.CreditCard = CreditCard
@@ -1,13 +0,0 @@
-var _ = require('underscore')._;
-
-var CreditCard = function (attributes) {
- var that = {};
- _.each(attributes, function (val, key) {
- that[key] = val;
- });
- that.maskedNumber = that.bin + '******' + that.last4;
-
- return that;
-};
-
-exports.CreditCard = CreditCard;
@@ -0,0 +1,47 @@
+CreditCard = require('./credit_card').CreditCard
+ErrorResponse = require('./error_response').ErrorResponse
+
+CreditCardGateway = (gateway) ->
+ my = { gateway: gateway }
+
+ create = (attributes, callback) ->
+ my.gateway.http.post('/payment_methods', {creditCard: attributes}, responseHandler(callback))
+
+ destroy = (token, callback) ->
+ my.gateway.http.delete('/payment_methods/' + token, callback)
+
+ find = (token, callback) ->
+ callback = callback
+ my.gateway.http.get('/payment_methods/' + token, (err, response) ->
+ return callback(err, null) if err
+ callback(null, CreditCard(response.creditCard))
+ )
+
+
+ update = (token, attributes, callback) ->
+ my.gateway.http.put(
+ '/payment_methods/' + token,
+ {creditCard: attributes},
+ responseHandler(callback)
+ )
+
+ responseHandler = (callback) ->
+ return (err, response) ->
+ return callback(err, response) if err
+
+ if (response.creditCard)
+ response.success = true
+ response.creditCard = CreditCard(response.creditCard)
+ callback(null, response)
+ else if (response.apiErrorResponse)
+ callback(null, ErrorResponse(response.apiErrorResponse))
+
+ {
+ create: create,
+ delete: destroy,
+ find: find,
+ responseHandler: responseHandler,
+ update: update
+ }
+
+exports.CreditCardGateway = CreditCardGateway
@@ -0,0 +1,10 @@
+CreditCard = require('./credit_card').CreditCard
+
+Customer = (attributes) ->
+ that = {}
+ for key, value of attributes
+ that[key] = value
+ that.creditCards = (CreditCard(cardAttributes) for cardAttributes in attributes.creditCards)
+ that
+
+exports.Customer = Customer
@@ -0,0 +1,47 @@
+Customer = require('./customer').Customer
+ErrorResponse = require('./error_response').ErrorResponse
+
+CustomerGateway = (gateway) ->
+ my = { gateway: gateway }
+
+ create = (attributes, callback) ->
+ my.gateway.http.post('/customers', {customer: attributes}, responseHandler(callback))
+
+ destroy = (customer_id, callback) ->
+ my.gateway.http.delete('/customers/' + customer_id, callback)
+
+ find = (customer_id, callback) ->
+ callback = callback
+ my.gateway.http.get('/customers/' + customer_id, (err, response) ->
+ return callback(err, null) if err
+ callback(null, Customer(response.customer))
+ )
+
+ update = (customer_id, attributes, callback) ->
+ my.gateway.http.put(
+ '/customers/' + customer_id,
+ { customer: attributes },
+ responseHandler(callback)
+ )
+
+ responseHandler = (callback) ->
+ (err, response) ->
+ return callback(err, response) if err
+
+ if (response.customer)
+ response.success = true
+ response.customer = Customer(response.customer)
+ callback(null, response)
+ else if (response.apiErrorResponse)
+ callback(null, ErrorResponse(response.apiErrorResponse))
+
+ {
+ create: create,
+ delete: destroy,
+ find: find,
+ responseHandler: responseHandler,
+ update: update
+ }
+
+exports.CustomerGateway = CustomerGateway
+
Oops, something went wrong.

0 comments on commit b0aa020

Please sign in to comment.