UNPKG

braintree

Version:

A library for integrating with Braintree.

120 lines (94 loc) 4.75 kB
//@ sourceMappingURL=transaction_gateway.map // Generated by CoffeeScript 1.6.1 var ErrorResponse, Gateway, Transaction, TransactionGateway, TransactionSearch, 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; }, __slice = [].slice; Gateway = require('./gateway').Gateway; Transaction = require('./transaction').Transaction; TransactionSearch = require('./transaction_search').TransactionSearch; ErrorResponse = require('./error_response').ErrorResponse; exceptions = require('./exceptions'); TransactionGateway = (function(_super) { __extends(TransactionGateway, _super); function TransactionGateway(gateway) { this.gateway = gateway; } TransactionGateway.prototype.cancelRelease = function(transactionId, callback) { return this.gateway.http.put("/transactions/" + transactionId + "/cancel_release", {}, this.responseHandler(callback)); }; TransactionGateway.prototype.cloneTransaction = function(transactionId, attributes, callback) { return this.gateway.http.post("/transactions/" + transactionId + "/clone", { transactionClone: attributes }, this.responseHandler(callback)); }; TransactionGateway.prototype.create = function(attributes, callback) { return this.gateway.http.post('/transactions', { transaction: attributes }, this.responseHandler(callback)); }; TransactionGateway.prototype.credit = function(attributes, callback) { attributes.type = 'credit'; return this.create(attributes, callback); }; TransactionGateway.prototype.find = function(transactionId, callback) { if (transactionId.trim() === '') { return callback(exceptions.NotFoundError("Not Found"), null); } else { return this.gateway.http.get("/transactions/" + transactionId, function(err, response) { if (err) { return callback(err, null); } else { return callback(null, new Transaction(response.transaction)); } }); } }; TransactionGateway.prototype.holdInEscrow = function(transactionId, callback) { return this.gateway.http.put("/transactions/" + transactionId + "/hold_in_escrow", {}, this.responseHandler(callback)); }; TransactionGateway.prototype.refund = function() { var amount, callback, transactionId, _i; transactionId = arguments[0], amount = 3 <= arguments.length ? __slice.call(arguments, 1, _i = arguments.length - 1) : (_i = 1, []), callback = arguments[_i++]; return this.gateway.http.post("/transactions/" + transactionId + "/refund", { transaction: { amount: amount[0] } }, this.responseHandler(callback)); }; TransactionGateway.prototype.responseHandler = function(callback) { return this.createResponseHandler("transaction", Transaction, callback); }; TransactionGateway.prototype.sale = function(attributes, callback) { attributes.type = 'sale'; return this.create(attributes, callback); }; TransactionGateway.prototype.search = function(fn, callback) { var search; search = new TransactionSearch(); fn(search); return this.createSearchResponse("/transactions/advanced_search_ids", search, this.pagingFunctionGenerator(search), callback); }; TransactionGateway.prototype.releaseFromEscrow = function(transactionId, callback) { return this.gateway.http.put("/transactions/" + transactionId + "/release_from_escrow", {}, this.responseHandler(callback)); }; TransactionGateway.prototype.submitForSettlement = function() { var amount, callback, transactionId, _i; transactionId = arguments[0], amount = 3 <= arguments.length ? __slice.call(arguments, 1, _i = arguments.length - 1) : (_i = 1, []), callback = arguments[_i++]; return this.gateway.http.put("/transactions/" + transactionId + "/submit_for_settlement", { transaction: { amount: amount[0] } }, this.responseHandler(callback)); }; TransactionGateway.prototype["void"] = function(transactionId, callback) { return this.gateway.http.put("/transactions/" + transactionId + "/void", null, this.responseHandler(callback)); }; TransactionGateway.prototype.pagingFunctionGenerator = function(search) { return TransactionGateway.__super__.pagingFunctionGenerator.call(this, search, 'transactions', Transaction, function(response) { return response.creditCardTransactions.transaction; }); }; return TransactionGateway; })(Gateway); exports.TransactionGateway = TransactionGateway;