From 3626bf0448eddefb20e5a256e5b1cceee3f47acf Mon Sep 17 00:00:00 2001 From: Ran Hu Date: Tue, 26 Jan 2016 12:32:03 -0500 Subject: [PATCH 1/6] add API:Capture Payment --- modules/billing.js | 29 ++++++++++++++++++++++++++++- test/billing.js | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/modules/billing.js b/modules/billing.js index 1f1bda8..2ec39f6 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.invoiceid] String|Number + * @param [opts.cvv] String + * @param callback + */ +Billing.prototype.capturepayment = function (opts, callback) { + var options = { + action:'capturepayment' + }; + + 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/test/billing.js b/test/billing.js index 0e10b9e..cae28c4 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': 'banktransfer', + 'date': '20141230', + 'duedate': '20141230', + 'itemdescription1': 'test item', + 'itemamount1': 1, + 'itemtaxed1': true + }; + + client.billing.createInvoice(2, invoiceo, function(err, invoice) { + expect(err).to.be.null; + + client.billing.capturepayment({invoiceid:invoice.invoiceid}, function(err, billing) { + expect(billing.result).to.equal('success'); + + expect(err).to.be.null; + + 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(); + }); + }); + }); + }); + }); + }); From 7468908a4600010350fb8a56ab158cfeba18937e Mon Sep 17 00:00:00 2001 From: Ran Hu Date: Fri, 29 Jan 2016 10:26:09 -0500 Subject: [PATCH 2/6] add API:Capture Payment and upgrade product --- modules/billing.js | 8 +++--- modules/products.js | 31 ++++++++++++++++++++++++ test/billing.js | 59 ++++++++++++++++++++------------------------- test/products.js | 26 ++++++++++++++++++++ 4 files changed, 87 insertions(+), 37 deletions(-) diff --git a/modules/billing.js b/modules/billing.js index 2ec39f6..12e11d2 100644 --- a/modules/billing.js +++ b/modules/billing.js @@ -293,13 +293,13 @@ Billing.prototype.updateInvoice = function (invoiceid, opts, callback) { * Capture payment - http://docs.whmcs.com/API:Capture_Payment * @param invoiceid String|Number * @param [opts] Object - * @param [opts.invoiceid] String|Number * @param [opts.cvv] String * @param callback */ -Billing.prototype.capturepayment = function (opts, callback) { +Billing.prototype.capturepayment = function (invoiceid, opts, callback) { var options = { - action:'capturepayment' + action:'capturepayment', + invoiceid:invoiceid }; if(typeof opts === 'function'){ @@ -312,7 +312,7 @@ Billing.prototype.capturepayment = function (opts, callback) { client: this, body: options }; - +console.log(createOptions.body); utils.modem(createOptions, callback); }; diff --git a/modules/products.js b/modules/products.js index 10800ef..e4de36a 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 cae28c4..db65f07 100644 --- a/test/billing.js +++ b/test/billing.js @@ -75,40 +75,33 @@ describe('billing', function() { }); }); - it('should create an invoice, capture payment and cancel it', function(done) { - this.timeout(15000); - + it('should create an invoice, capture payment and cancel it', function(done) { + this.timeout(15000); - var invoiceo = { - 'paymentmethod': 'banktransfer', - 'date': '20141230', - 'duedate': '20141230', - 'itemdescription1': 'test item', - 'itemamount1': 1, - 'itemtaxed1': true - }; - - client.billing.createInvoice(2, invoiceo, function(err, invoice) { - expect(err).to.be.null; - - client.billing.capturepayment({invoiceid:invoice.invoiceid}, function(err, billing) { - expect(billing.result).to.equal('success'); + var invoiceo = { + 'paymentmethod': 'moneris', + 'date': '20141230', + 'duedate': '20181230', + 'itemdescription1': 'test item', + 'itemamount1': 1, + 'itemtaxed1': true + }; - expect(err).to.be.null; - - 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(); - }); - }); - }); - }); - }); + 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..1ee3463 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(); + }); + }); + + + }); + }); From b506b644e29b4ed4a793c77ee4bdfd75a2a25180 Mon Sep 17 00:00:00 2001 From: Ran Hu Date: Fri, 29 Jan 2016 10:38:23 -0500 Subject: [PATCH 3/6] fix formatting in capture payment test and upgrade product test --- test/billing.js | 61 +++++++++++++++++++++++++++--------------------- test/products.js | 10 ++++---- 2 files changed, 39 insertions(+), 32 deletions(-) diff --git a/test/billing.js b/test/billing.js index db65f07..032cf1b 100644 --- a/test/billing.js +++ b/test/billing.js @@ -75,33 +75,40 @@ describe('billing', function() { }); }); - it('should create an invoice, capture payment and cancel it', function(done) { - this.timeout(15000); + 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; - var invoiceo = { - 'paymentmethod': 'moneris', - 'date': '20141230', - 'duedate': '20181230', - 'itemdescription1': 'test item', - 'itemamount1': 1, - 'itemtaxed1': true - }; + expect(billing.result).to.equal('success'); - 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(); - }); - }); - }); - }); - }); - + 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 1ee3463..7711120 100644 --- a/test/products.js +++ b/test/products.js @@ -38,17 +38,17 @@ describe('products', function() { 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(product_info.result).to.equal('success'); - expect(err).to.be.null; + expect(err).to.be.null; - done(); + done(); }); }); - - }); }); From a69840e77f9f012ca2b854038f7865385ed224f0 Mon Sep 17 00:00:00 2001 From: Ran Hu Date: Fri, 29 Jan 2016 10:44:03 -0500 Subject: [PATCH 4/6] fix billing capture payment action --- modules/billing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/billing.js b/modules/billing.js index 12e11d2..154a402 100644 --- a/modules/billing.js +++ b/modules/billing.js @@ -312,7 +312,7 @@ Billing.prototype.capturepayment = function (invoiceid, opts, callback) { client: this, body: options }; -console.log(createOptions.body); + utils.modem(createOptions, callback); }; From 245a53e753df73223b1dab5c326c9ca16ec4bb89 Mon Sep 17 00:00:00 2001 From: Ran Hu Date: Fri, 29 Jan 2016 11:44:30 -0500 Subject: [PATCH 5/6] capitalize function name --- modules/billing.js | 2 +- modules/products.js | 2 +- test/billing.js | 2 +- test/products.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/billing.js b/modules/billing.js index 154a402..947834d 100644 --- a/modules/billing.js +++ b/modules/billing.js @@ -296,7 +296,7 @@ Billing.prototype.updateInvoice = function (invoiceid, opts, callback) { * @param [opts.cvv] String * @param callback */ -Billing.prototype.capturepayment = function (invoiceid, opts, callback) { +Billing.prototype.capturePayment = function (invoiceid, opts, callback) { var options = { action:'capturepayment', invoiceid:invoiceid diff --git a/modules/products.js b/modules/products.js index e4de36a..fd2f23b 100644 --- a/modules/products.js +++ b/modules/products.js @@ -124,7 +124,7 @@ Products.prototype.getOrders = function(method, id, offset, limit, callback) { * @param [product.ordernotes ] String optional * @param callback */ -Products.prototype.upgradeproduct = function (product, callback) { +Products.prototype.upgradeProduct = function (product, callback) { var options = { action: 'upgradeproduct' }; diff --git a/test/billing.js b/test/billing.js index 032cf1b..0516b3f 100644 --- a/test/billing.js +++ b/test/billing.js @@ -90,7 +90,7 @@ describe('billing', function() { client.billing.createInvoice(2, invoiceo, function(err, invoice) { expect(err).to.be.null; - client.billing.capturepayment(invoice.invoiceid,{cvv:'123'}, function(err, billing) { + client.billing.capturePayment(invoice.invoiceid,{cvv:'123'}, function(err, billing) { expect(err).to.be.null; expect(billing.result).to.equal('success'); diff --git a/test/products.js b/test/products.js index 7711120..5ff2804 100644 --- a/test/products.js +++ b/test/products.js @@ -41,7 +41,7 @@ describe('products', function() { opts.newproductid = customer.products.product[0].pid; - client.products.upgradeproduct(opts, function(err, product_info) { + client.products.upgradeProduct(opts, function(err, product_info) { expect(product_info.result).to.equal('success'); expect(err).to.be.null; From 80d64a4dd26f1cd31158715c5b74e497b7583a0f Mon Sep 17 00:00:00 2001 From: Ran Hu Date: Wed, 16 Mar 2016 17:29:04 -0400 Subject: [PATCH 6/6] add capturePayment and upgradeProduct to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) 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