Skip to content

Commit

Permalink
Merge pull request #25 from joaograca/master
Browse files Browse the repository at this point in the history
WHMCS API 3.0 changes
  • Loading branch information
apocas committed Jul 14, 2017
2 parents 8134dc2 + 207f7ff commit 0e06c0e
Showing 1 changed file with 84 additions and 16 deletions.
100 changes: 84 additions & 16 deletions modules/licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ var Licenses = function(config) {
/**
* Add License -
* The Add License function can be used to generate a new WHMCS License Key.
* @param type - License type (branding/nobranding)
* @param product - product type (starter , plus , professional or business)
* @param callback
*/
Licenses.prototype.addLicense = function (type, callback) {
Licenses.prototype.addLicense = function(product, callback) {
var options = {
action: 'addlicense',
type: type || 'branding',
product: product || 'starter',
responsetype: 'xml'
};

Expand All @@ -26,14 +26,82 @@ Licenses.prototype.addLicense = function (type, callback) {
utils.modem(createOptions, callback, true);
};

/**
* Upgrade License -
* Upgrade or downgrade a given license to a new product.
* @param key - The license key to be upgraded/downgraded
* @param product - product type (starter , plus , professional or business)
* @param callback
*/
Licenses.prototype.upgradeLicense = function(key, product, callback) {
var options = {
key: key,
action: 'upgrade',
product: product,
responsetype: 'xml'
};

var createOptions = {
client: this,
body: options
};

utils.modem(createOptions, callback, true);
};

/**
* Downgrade License -
* Alias of Upgrade License.
* @param key - The license key to be upgraded/downgraded
* @param product - product type (starter , plus , professional or business)
* @param callback
*/
Licenses.prototype.downgradeLicense = function(key, product, callback) {
Licenses.prototype.upgradeLicense(key, product, callback);
};

/**
* Upgrade License and Reissue -
* Upgrade or downgrade a given license to a new product and reissue it ready for installation to a new location.
* @param key - The license key to be upgraded/downgraded
* @param product - product type (starter , plus , professional or business)
* @param callback
*/
Licenses.prototype.upgradeReissueLicense = function(key, product, callback) {
var options = {
key: key,
action: 'upgradeandreissue',
product: product,
responsetype: 'xml'
};

var createOptions = {
client: this,
body: options
};

utils.modem(createOptions, callback, true);
};

/**
* Downgrade License and Reissue -
* Alias of Upgrade License.
* @param key - The license key to be upgraded/downgraded
* @param product - product type (starter , plus , professional or business)
* @param callback
*/
Licenses.prototype.downgradeReissueLicense = function(key, product, callback) {
Licenses.prototype.upgradeReissueLicense(key, product, callback);
};

/**
* Cancel License -
* This will cancel an active WHMCS License Key and prevent it from being billed
again. It will terminate it immediately and not allow it to be reactivated.
* @param key - License Key to be cancelled
* @param callback
*/
Licenses.prototype.cancelLicense = function (key, callback) {
Licenses.prototype.cancelLicense = function(key, callback) {
var options = {
action: 'cancel',
key: key,
Expand All @@ -56,7 +124,7 @@ The no branding status will be true/false. And the license status either Active,
Reissued, or Suspended. Expired keys are excluded.
* @param callback
*/
Licenses.prototype.listLicenses = function (callback) {
Licenses.prototype.listLicenses = function(callback) {
var options = {
action: 'listlicenses',
responsetype: 'xml'
Expand All @@ -78,7 +146,7 @@ the associated installation.
* @param key - License Key to be reissued.
* @param callback
*/
Licenses.prototype.reissueLicense = function (key, callback) {
Licenses.prototype.reissueLicense = function(key, callback) {
var options = {
action: 'reissue',
key: key,
Expand All @@ -104,17 +172,17 @@ key.
* @param [opts.directory] Comma separated list of allowed directories
* @param callback
*/
Licenses.prototype.modifyLicense = function (key, opts, callback) {
Licenses.prototype.modifyLicense = function(key, opts, callback) {
var options = {
action: 'modify',
key: key,
responsetype: 'xml'
};

if(typeof opts === 'function'){
if (typeof opts === 'function') {
callback = opts;
} else {
options = extend(options,opts);
options = extend(options, opts);
}

var createOptions = {
Expand All @@ -130,16 +198,16 @@ Licenses.prototype.modifyLicense = function (key, opts, callback) {
* The Get Pricing can be used to retrieve pricing information for your account.
* @param callback
*/
Licenses.prototype.getPricingLicense = function (callback) {
Licenses.prototype.getPricingLicense = function(callback) {
var options = {
action: 'getpricing',
responsetype: 'xml'
};

if(typeof opts === 'function'){
if (typeof opts === 'function') {
callback = opts;
} else {
options = extend(options,opts);
options = extend(options, opts);
}

var createOptions = {
Expand All @@ -162,16 +230,16 @@ At least one criteria must be submitted.
* @param [opts.ipaddr] (Optional) Obtain results of a specific IP address
* @param callback
*/
Licenses.prototype.searchLicense = function (opts, callback) {
Licenses.prototype.searchLicense = function(opts, callback) {
var options = {
action: 'searchlicenses',
responsetype: 'xml'
};

if(typeof opts === 'function'){
if (typeof opts === 'function') {
callback = opts;
} else {
options = extend(options,opts);
options = extend(options, opts);
}

var createOptions = {
Expand All @@ -189,7 +257,7 @@ Licenses.prototype.searchLicense = function (opts, callback) {
* @param key License Key
* @param callback
*/
Licenses.prototype.brandingLicense = function (action, key, callback) {
Licenses.prototype.brandingLicense = function(action, key, callback) {
// action The function to perform [brandingenable/brandingdisable]
if (action && action === true) {
action = 'brandingenable';
Expand Down

0 comments on commit 0e06c0e

Please sign in to comment.