Skip to content

Commit

Permalink
Merge pull request #23 from websiteboxcom/master
Browse files Browse the repository at this point in the history
Create functionalities capture payment and upgrade product
  • Loading branch information
apocas committed Mar 19, 2016
2 parents 1e3e99b + 80d64a4 commit 8134dc2
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion modules/billing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
31 changes: 31 additions & 0 deletions modules/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
35 changes: 35 additions & 0 deletions test/billing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});
});


});
26 changes: 26 additions & 0 deletions test/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

});

0 comments on commit 8134dc2

Please sign in to comment.