braintree
Version:
A library for integrating with Braintree.
96 lines (77 loc) • 3.31 kB
JavaScript
//@ sourceMappingURL=credit_card_gateway.map
// Generated by CoffeeScript 1.6.1
var CreditCard, CreditCardGateway, 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;
CreditCard = require('./credit_card').CreditCard;
exceptions = require('./exceptions');
CreditCardGateway = (function(_super) {
__extends(CreditCardGateway, _super);
function CreditCardGateway(gateway) {
this.gateway = gateway;
}
CreditCardGateway.prototype.create = function(attributes, callback) {
return this.gateway.http.post('/payment_methods', {
creditCard: attributes
}, this.responseHandler(callback));
};
CreditCardGateway.prototype["delete"] = function(token, callback) {
return this.gateway.http["delete"]("/payment_methods/" + token, callback);
};
CreditCardGateway.prototype.find = function(token, callback) {
if (token.trim() === '') {
return callback(exceptions.NotFoundError("Not Found"), null);
} else {
return this.gateway.http.get("/payment_methods/" + token, function(err, response) {
if (err) {
return callback(err, null);
} else {
return callback(null, new CreditCard(response.creditCard));
}
});
}
};
CreditCardGateway.prototype.fromNonce = function(nonce, callback) {
if (nonce.trim() === '') {
return callback(exceptions.NotFoundError("Not Found"), null);
} else {
return this.gateway.http.get("/payment_methods/from_nonce/" + nonce, function(err, response) {
if (err) {
err.message = "Payment method with nonce " + nonce + " locked, consumed or not found";
return callback(err, null);
} else {
return callback(null, new CreditCard(response.creditCard));
}
});
}
};
CreditCardGateway.prototype.update = function(token, attributes, callback) {
return this.gateway.http.put("/payment_methods/" + token, {
creditCard: attributes
}, this.responseHandler(callback));
};
CreditCardGateway.prototype.responseHandler = function(callback) {
return this.createResponseHandler("creditCard", CreditCard, callback);
};
CreditCardGateway.prototype.expired = function(callback) {
return this.gateway.http.post("/payment_methods/all/expired_ids", {}, this.searchResponseHandler(this, callback));
};
CreditCardGateway.prototype.expiringBetween = function(after, before, callback) {
var url;
url = "/payment_methods/all/expiring_ids?start=" + (this.dateFormat(after)) + "&end=" + (this.dateFormat(before));
return this.gateway.http.post(url, {}, this.searchResponseHandler(this, callback));
};
CreditCardGateway.prototype.dateFormat = function(date) {
var month;
month = date.getMonth() + 1;
if (month < 10) {
month = "0" + month;
} else {
month = "" + month;
}
return month + date.getFullYear();
};
return CreditCardGateway;
})(Gateway);
exports.CreditCardGateway = CreditCardGateway;