UNPKG

braintree

Version:

A library for integrating with Braintree.

77 lines (58 loc) 2.6 kB
//@ sourceMappingURL=customer_gateway.map // Generated by CoffeeScript 1.6.1 var Customer, CustomerGateway, CustomerSearch, Gateway, exceptions, util, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Gateway = require('./gateway').Gateway; Customer = require('./customer').Customer; CustomerSearch = require('./customer_search').CustomerSearch; util = require('util'); exceptions = require('./exceptions'); CustomerGateway = (function(_super) { __extends(CustomerGateway, _super); function CustomerGateway(gateway) { this.gateway = gateway; } CustomerGateway.prototype.create = function(attributes, callback) { return this.gateway.http.post('/customers', { customer: attributes }, this.responseHandler(callback)); }; CustomerGateway.prototype["delete"] = function(customerId, callback) { return this.gateway.http["delete"]("/customers/" + customerId, callback); }; CustomerGateway.prototype.find = function(customerId, callback) { if (customerId.trim() === '') { return callback(exceptions.NotFoundError("Not Found"), null); } else { return this.gateway.http.get("/customers/" + customerId, function(err, response) { if (err) { return callback(err, null); } else { return callback(null, new Customer(response.customer)); } }); } }; CustomerGateway.prototype.update = function(customerId, attributes, callback) { return this.gateway.http.put("/customers/" + customerId, { customer: attributes }, this.responseHandler(callback)); }; CustomerGateway.prototype.search = function(fn, callback) { var search; search = new CustomerSearch(); fn(search); return this.createSearchResponse("/customers/advanced_search_ids", search, this.pagingFunctionGenerator(search), callback); }; CustomerGateway.prototype.responseHandler = function(callback) { return this.createResponseHandler("customer", Customer, callback); }; CustomerGateway.prototype.pagingFunctionGenerator = function(search) { return CustomerGateway.__super__.pagingFunctionGenerator.call(this, search, 'customers', Customer, function(response) { return response.customers.customer; }); }; return CustomerGateway; })(Gateway); exports.CustomerGateway = CustomerGateway;