diff --git a/README.md b/README.md index b29ac48..82f21d3 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ whmcs_client.customers.getCustomerEmails(clientid, function(err, emails) { - cancelOrder: function (orderid, callback) - deleteOrder: function (orderid, callback) - createInvoice: function (clientid, invoice, callback) +- capturePayment: function (invoiceid, options, callback) ### Customers @@ -95,6 +96,7 @@ whmcs_client.customers.getCustomerEmails(clientid, function(err, emails) { - getProducts: function (gid, callback) - getProductsByType: function (type, id, callback) - getOrders: function (method, id, offset, limit, callback) +- upgradeProduct: function (product, callback) ### Support diff --git a/modules/billing.js b/modules/billing.js index 1f1bda8..947834d 100644 --- a/modules/billing.js +++ b/modules/billing.js @@ -289,4 +289,31 @@ Billing.prototype.updateInvoice = function (invoiceid, opts, callback) { utils.modem(createOptions, callback); }; -module.exports = Billing; +/** + * Capture payment - http://docs.whmcs.com/API:Capture_Payment + * @param invoiceid String|Number + * @param [opts] Object + * @param [opts.cvv] String + * @param callback + */ +Billing.prototype.capturePayment = function (invoiceid, opts, callback) { + var options = { + action:'capturepayment', + invoiceid:invoiceid + }; + + if(typeof opts === 'function'){ + callback = opts; + } else { + options = extend(options,opts); + } + + var createOptions = { + client: this, + body: options + }; + + utils.modem(createOptions, callback); +}; + +module.exports = Billing; \ No newline at end of file diff --git a/modules/products.js b/modules/products.js index 10800ef..fd2f23b 100644 --- a/modules/products.js +++ b/modules/products.js @@ -109,4 +109,35 @@ Products.prototype.getOrders = function(method, id, offset, limit, callback) { utils.modem(createOptions, callback); }; +/** + * Calculate the cost for an upgrade or downgrade of a product/service, and create an order for it. + * @param attributes Object + * @param [product.clientid] String + * @param [product.serviceid] String + * @param [product.type] String either "product" or "configoptions" + * @param [product.newproductid ] String + * @param [product.newproductbillingcycle ] String Must be unique if creating a sub-account + * @param [product.configoptions[x]] Array + * @param [product.paymentmethod ] String + * @param [product.promocode ] String optional + * @param [product.calconly ] String optional + * @param [product.ordernotes ] String optional + * @param callback + */ +Products.prototype.upgradeProduct = function (product, callback) { + var options = { + action: 'upgradeproduct' + }; + + for(var i in product){ + options[i] = product[i]; + } + + var createOptions = { + client: this, + body: options + }; + utils.modem(createOptions, callback); +}; + module.exports = Products; diff --git a/test/billing.js b/test/billing.js index 0e10b9e..0516b3f 100644 --- a/test/billing.js +++ b/test/billing.js @@ -75,5 +75,40 @@ describe('billing', function() { }); }); + it('should create an invoice, capture payment and cancel it', function(done) { + this.timeout(15000); + + var invoiceo = { + 'paymentmethod': 'moneris', + 'date': '20141230', + 'duedate': '20181230', + 'itemdescription1': 'test item', + 'itemamount1': 1, + 'itemtaxed1': true + }; + + client.billing.createInvoice(2, invoiceo, function(err, invoice) { + expect(err).to.be.null; + + client.billing.capturePayment(invoice.invoiceid,{cvv:'123'}, function(err, billing) { + expect(err).to.be.null; + + expect(billing.result).to.equal('success'); + + client.billing.updateInvoice(invoice.invoiceid, {'status': 'Cancelled'}, function(err, data) { + expect(err).to.be.null; + + client.billing.getInvoice(invoice.invoiceid, function(err, invoice) { + expect(err).to.be.null; + + expect(invoice.status).to.equal('Cancelled'); + + done(); + }); + }); + }); + }); + }); + }); diff --git a/test/products.js b/test/products.js index 2b5f55c..5ff2804 100644 --- a/test/products.js +++ b/test/products.js @@ -25,4 +25,30 @@ describe('products', function() { }); }); + it('should upgrade products', function(done) { + this.timeout(15000); + var opts = { + clientid : '1', + serviceid : '1', + type : 'product', + newproductid : null, + newproductbillingcycle : 'monthly', + paymentmethod : 'moneris' + }; + + client.products.getProduct(1, function(err, customer) { + expect(err).to.be.null; + + opts.newproductid = customer.products.product[0].pid; + + client.products.upgradeProduct(opts, function(err, product_info) { + expect(product_info.result).to.equal('success'); + + expect(err).to.be.null; + + done(); + }); + }); + }); + });