-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0aa020
commit fa8d8fb
Showing
40 changed files
with
546 additions
and
476 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
sys = require "sys" | |||
{Config} = require("./braintree/config") | |||
{Environment} = require("./braintree/environment") | |||
{BraintreeGateway} = require("./braintree/braintree_gateway") | |||
errorTypes = require("./braintree/error_types") | |||
|
|||
connect = (config) -> | |||
new BraintreeGateway(new Config(config)) | |||
|
|||
exports.connect = connect | |||
exports.version = '0.3.0' | |||
exports.Environment = Environment | |||
exports.errorTypes = errorTypes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,31 +1,7 @@ | |||
require('coffee-script'); | require('coffee-script'); | ||
braintree = require('./braintree.coffee') | |||
|
|
||
var sys = require("sys"), | exports.connect = braintree.connect; | ||
Config = require("./braintree/config").Config, | exports.version = braintree.version; | ||
Environment = require("./braintree/environment").Environment, | exports.Environment = braintree.Environment; | ||
Gateway = require("./braintree/gateway").Gateway, | exports.errorTypes = braintree.errorTypes; | ||
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 { | |||
_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.2.0'; | |||
exports.Environment = Environment; | |||
exports.errorTypes = errorTypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
{AttributeSetter} = require('./attribute_setter') | |||
|
|||
class Address extends AttributeSetter | |||
|
|||
exports.Address = Address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,43 +1,28 @@ | |||
ErrorResponse = require('./error_response').ErrorResponse | {Gateway} = require('./gateway') | ||
{Address} = require('./address') | |||
|
|
||
AddressGateway = (gateway) -> | class AddressGateway extends Gateway | ||
my = { gateway: gateway } | constructor: (@gateway) -> | ||
|
|
||
create = (attributes, callback) -> | create: (attributes, callback) -> | ||
customerId = attributes.customerId | customerId = attributes.customerId | ||
delete(attributes.customerId) | delete(attributes.customerId) | ||
my.gateway.http.post("/customers/#{customerId}/addresses", {address: attributes}, responseHandler(callback)) | @gateway.http.post("/customers/#{customerId}/addresses", {address: attributes}, @responseHandler(callback)) | ||
|
|
||
destroy = (customerId, id, callback) -> | delete: (customerId, id, callback) -> | ||
my.gateway.http.delete("/customers/#{customerId}/addresses/#{id}", callback) | @gateway.http.delete("/customers/#{customerId}/addresses/#{id}", callback) | ||
|
|
||
find = (customerId, id, callback) -> | find: (customerId, id, callback) -> | ||
callback = callback | @gateway.http.get "/customers/#{customerId}/addresses/#{id}", (err, response) -> | ||
my.gateway.http.get("/customers/#{customerId}/addresses/#{id}" , (err, response) -> | if err | ||
return callback(err, null) if err | callback(err, null) | ||
callback(null, response.address) | else | ||
) | callback(null, response.address) | ||
|
|
||
update: (customerId, id, attributes, callback) -> | |||
@gateway.http.put("/customers/#{customerId}/addresses/#{id}", {address: attributes}, @responseHandler(callback)) | |||
|
|
||
update = (customerId, id, attributes, callback) -> | responseHandler: (callback) -> | ||
my.gateway.http.put("/customers/#{customerId}/addresses/#{id}", {address: attributes}, responseHandler(callback)) | @createResponseHandler("address", Address, 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 | exports.AddressGateway = AddressGateway | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
class AttributeSetter | |||
constructor: (attributes) -> | |||
for key, value of attributes | |||
@[key] = value | |||
|
|||
exports.AttributeSetter = AttributeSetter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
{Http} = require('./http') | |||
{AddressGateway} = require("./address_gateway") | |||
{CreditCardGateway} = require("./credit_card_gateway") | |||
{CustomerGateway} = require("./customer_gateway") | |||
{SettlementBatchSummaryGateway} = require("./settlement_batch_summary_gateway") | |||
{SubscriptionGateway} = require("./subscription_gateway") | |||
{TransactionGateway} = require("./transaction_gateway") | |||
{TransparentRedirectGateway} = require("./transparent_redirect_gateway") | |||
|
|||
class BraintreeGateway | |||
constructor: (@config) -> | |||
@http = new Http(@config) | |||
@address = new AddressGateway(this) | |||
@creditCard = new CreditCardGateway(this) | |||
@customer = new CustomerGateway(this) | |||
@settlementBatchSummary = new SettlementBatchSummaryGateway(this) | |||
@subscription = new SubscriptionGateway(this) | |||
@transaction = new TransactionGateway(this) | |||
@transparentRedirect = new TransparentRedirectGateway(this) | |||
|
|||
exports.BraintreeGateway = BraintreeGateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,11 +1,10 @@ | |||
Config = (rawConfig) -> | class Config | ||
{ | constructor: (rawConfig) -> | ||
apiVersion: '2', | @apiVersion = '2' | ||
environment: rawConfig.environment, | @environment = rawConfig.environment | ||
merchantId: rawConfig.merchantId, | @merchantId = rawConfig.merchantId | ||
publicKey: rawConfig.publicKey, | @publicKey = rawConfig.publicKey | ||
privateKey: rawConfig.privateKey, | @privateKey = rawConfig.privateKey | ||
baseMerchantPath: '/merchants/' + rawConfig.merchantId | @baseMerchantPath = "/merchants/#{rawConfig.merchantId}" | ||
} | |||
|
|
||
exports.Config = Config | exports.Config = Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,9 +1,9 @@ | |||
CreditCard = (attributes) -> | {AttributeSetter} = require('./attribute_setter') | ||
that = {} |
|
||
for key, value of attributes | class CreditCard extends AttributeSetter | ||
that[key] = value | constructor: (attributes) -> | ||
that.maskedNumber = that.bin + '******' + that.last4 | super attributes | ||
that.expirationDate = that.expirationMonth + '/' + that.expirationYear | @maskedNumber = "#{@bin}******#{@last4}" | ||
that | @expirationDate = "#{@expirationMonth}/#{@expirationYear}" | ||
|
|
||
exports.CreditCard = CreditCard | exports.CreditCard = CreditCard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,47 +1,26 @@ | |||
CreditCard = require('./credit_card').CreditCard | {Gateway} = require('./gateway') | ||
ErrorResponse = require('./error_response').ErrorResponse | {CreditCard} = require('./credit_card') | ||
|
|
||
CreditCardGateway = (gateway) -> | class CreditCardGateway extends Gateway | ||
my = { gateway: gateway } | constructor: (@gateway) -> | ||
|
|
||
create = (attributes, callback) -> | create: (attributes, callback) -> | ||
my.gateway.http.post('/payment_methods', {creditCard: attributes}, responseHandler(callback)) | @gateway.http.post('/payment_methods', {creditCard: attributes}, @responseHandler(callback)) | ||
|
|
||
destroy = (token, callback) -> | delete: (token, callback) -> | ||
my.gateway.http.delete('/payment_methods/' + token, callback) | @gateway.http.delete("/payment_methods/#{token}", callback) | ||
|
|
||
find = (token, callback) -> | find: (token, callback) -> | ||
callback = callback | @gateway.http.get "/payment_methods/#{token}", (err, response) -> | ||
my.gateway.http.get('/payment_methods/' + token, (err, response) -> | if err | ||
return callback(err, null) if err | callback(err, null) | ||
callback(null, CreditCard(response.creditCard)) | else | ||
) | callback(null, new CreditCard(response.creditCard)) | ||
|
|
||
update: (token, attributes, callback) -> | |||
@gateway.http.put("/payment_methods/#{token}", {creditCard: attributes}, @responseHandler(callback)) | |||
|
|
||
update = (token, attributes, callback) -> | responseHandler: (callback) -> | ||
my.gateway.http.put( | @createResponseHandler("creditCard", CreditCard, callback) | ||
'/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 | exports.CreditCardGateway = CreditCardGateway |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,10 +1,9 @@ | |||
CreditCard = require('./credit_card').CreditCard | {AttributeSetter} = require('./attribute_setter') | ||
{CreditCard} = require('./credit_card') | |||
|
|
||
Customer = (attributes) -> | class Customer extends AttributeSetter | ||
that = {} | constructor: (attributes) -> | ||
for key, value of attributes | super attributes | ||
that[key] = value | @creditCards = (new CreditCard(cardAttributes) for cardAttributes in attributes.creditCards) | ||
that.creditCards = (CreditCard(cardAttributes) for cardAttributes in attributes.creditCards) | |||
that | |||
|
|
||
exports.Customer = Customer | exports.Customer = Customer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,47 +1,26 @@ | |||
Customer = require('./customer').Customer | {Gateway} = require('./gateway') | ||
ErrorResponse = require('./error_response').ErrorResponse | {Customer} = require('./customer') | ||
|
|
||
CustomerGateway = (gateway) -> | class CustomerGateway extends Gateway | ||
my = { gateway: gateway } | constructor: (@gateway) -> | ||
|
|
||
create = (attributes, callback) -> | create: (attributes, callback) -> | ||
my.gateway.http.post('/customers', {customer: attributes}, responseHandler(callback)) | @gateway.http.post('/customers', {customer: attributes}, @responseHandler(callback)) | ||
|
|
||
destroy = (customer_id, callback) -> | delete: (customerId, callback) -> | ||
my.gateway.http.delete('/customers/' + customer_id, callback) | @gateway.http.delete("/customers/#{customerId}", callback) | ||
|
|
||
find = (customer_id, callback) -> | find: (customerId, callback) -> | ||
callback = callback | @gateway.http.get "/customers/#{customerId}", (err, response) -> | ||
my.gateway.http.get('/customers/' + customer_id, (err, response) -> | if err | ||
return callback(err, null) if err | callback(err, null) | ||
callback(null, Customer(response.customer)) | else | ||
) | callback(null, new Customer(response.customer)) | ||
|
|
||
update = (customer_id, attributes, callback) -> | update: (customerId, attributes, callback) -> | ||
my.gateway.http.put( | @gateway.http.put("/customers/#{customerId}", {customer: attributes}, @responseHandler(callback)) | ||
'/customers/' + customer_id, | |||
{ customer: attributes }, | |||
responseHandler(callback) | |||
) | |||
|
|
||
responseHandler = (callback) -> | responseHandler: (callback) -> | ||
(err, response) -> | @createResponseHandler("customer", Customer, callback) | ||
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 | exports.CustomerGateway = CustomerGateway | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,20 +1,18 @@ | |||
sys = require('sys') | sys = require('sys') | ||
crypto = require('crypto') | crypto = require('crypto') | ||
|
|
||
Digest = -> | class Digest | ||
sha1 = (data) -> | @hexdigest: (privateKey, string) -> | ||
hash = crypto.createHash('sha1') | new Digest().hmacSha1(privateKey, string) | ||
hash.update(data) | |||
hash.digest() | |||
|
|
||
hmacSha1 = (key, data) -> | hmacSha1: (key, data) -> | ||
hmac = crypto.createHmac('sha1', sha1(key)) | hmac = crypto.createHmac('sha1', @sha1(key)) | ||
hmac.update(data) | hmac.update(data) | ||
hmac.digest('hex') | hmac.digest('hex') | ||
|
|
||
{ hmacSha1: hmacSha1 } | sha1: (data) -> | ||
|
hash = crypto.createHash('sha1') | ||
Digest.hexdigest = (privateKey, string) -> | hash.update(data) | ||
Digest().hmacSha1(privateKey, string) | hash.digest() | ||
|
|
||
exports.Digest = Digest | exports.Digest = Digest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,15 +1,9 @@ | |||
Environment = (server, port, ssl) -> | class Environment | ||
{ | DEVELOPMENT_PORT = process.env['GATEWAY_PORT'] || '3000' | ||
server: server, | @Development = new Environment('localhost', DEVELOPMENT_PORT, false) | ||
port: port, | @Sandbox = new Environment('sandbox.braintreegateway.com', '443', true) | ||
ssl: ssl | @Production = new Environment('www.braintreegateway.com', '443', true) | ||
} | |||
|
|
||
|
constructor: (@server, @port, @ssl) -> | ||
developmentPort = process.env['GATEWAY_PORT'] || '3000' | |||
|
|||
Environment.Development = Environment('localhost', developmentPort, false) | |||
Environment.Sandbox = Environment('sandbox.braintreegateway.com', '443', true) | |||
Environment.Production = Environment('www.braintreegateway.com', '443', true) | |||
|
|
||
exports.Environment = Environment | exports.Environment = Environment |
Oops, something went wrong.