braintree
Version:
A library for integrating with Braintree.
63 lines (48 loc) • 2.15 kB
JavaScript
//@ sourceMappingURL=address_gateway.map
// Generated by CoffeeScript 1.6.1
var Address, AddressGateway, Gateway, exceptions,
__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;
Address = require('./address').Address;
exceptions = require('./exceptions');
AddressGateway = (function(_super) {
__extends(AddressGateway, _super);
function AddressGateway(gateway) {
this.gateway = gateway;
}
AddressGateway.prototype.create = function(attributes, callback) {
var customerId;
customerId = attributes.customerId;
delete attributes.customerId;
return this.gateway.http.post("/customers/" + customerId + "/addresses", {
address: attributes
}, this.responseHandler(callback));
};
AddressGateway.prototype["delete"] = function(customerId, id, callback) {
return this.gateway.http["delete"]("/customers/" + customerId + "/addresses/" + id, callback);
};
AddressGateway.prototype.find = function(customerId, id, callback) {
if (customerId.trim() === '' || id.trim() === '') {
return callback(exceptions.NotFoundError("Not Found"), null);
} else {
return this.gateway.http.get("/customers/" + customerId + "/addresses/" + id, function(err, response) {
if (err) {
return callback(err, null);
} else {
return callback(null, response.address);
}
});
}
};
AddressGateway.prototype.update = function(customerId, id, attributes, callback) {
return this.gateway.http.put("/customers/" + customerId + "/addresses/" + id, {
address: attributes
}, this.responseHandler(callback));
};
AddressGateway.prototype.responseHandler = function(callback) {
return this.createResponseHandler("address", Address, callback);
};
return AddressGateway;
})(Gateway);
exports.AddressGateway = AddressGateway;