├── .gitignore ├── Makefile ├── README.md ├── lib ├── utils.js ├── whmcserror.js └── whmcshttpclient.js ├── modules ├── addons.js ├── affiliates.js ├── authentication.js ├── billing.js ├── client.js ├── domains.js ├── index.js ├── module.js ├── orders.js ├── products.js ├── projectmanagement.js ├── servers.js ├── service.js ├── support.js ├── system.js ├── tickets.js └── users.js ├── package-lock.json ├── package.json ├── test ├── addons.js ├── affiliates.js ├── authentication.js ├── billing.js ├── client.js ├── conf.js ├── domains.js ├── internal.js ├── module.js ├── orders.js ├── products.js ├── projectmanagement.js ├── servers.js ├── service.js ├── support.js ├── system.js ├── tickets.js └── users.js └── whmcs.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | test.js 3 | 4 | node_modules 5 | npm-debug.log 6 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | test: 2 | @./node_modules/.bin/mocha \ 3 | --reporter list 4 | 5 | .PHONY: test -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WHMCS Node Module 2 | ========= 3 | 4 | WHMCS' API Node client. 5 | 6 | ## Pre-requisites 7 | 8 | Install [Node.js](https://nodejs.org/en/) version 12.0.0 or higher. 9 | 10 | ## Installation 11 | 12 | ``` 13 | npm install whmcs 14 | ``` 15 | 16 | ## Usage 17 | 18 | First you need to instantiate it. 19 | 20 | You can instantiate with api credentials: 21 | 22 | ```javascript 23 | const config = { 24 | apiIdentifier: '', 25 | apiSecret: '', 26 | accesskey: '', //optional. use it to bypass IP restrictions 27 | serverUrl: 'http://127.0.0.1', 28 | userAgent: '' 29 | }; 30 | 31 | const wclient = new WHMCS(config); 32 | ``` 33 | 34 | Or you can instantiate with administrator username and password: 35 | 36 | ```javascript 37 | const config = { 38 | username: process.env.WHMCS_USER || '', 39 | password: process.env.WHMCS_PASSWORD || '', 40 | accesskey: '', //optional. use it to bypass IP restrictions 41 | serverUrl: 'http://127.0.0.1', 42 | userAgent: '' 43 | }; 44 | 45 | const whmcs = new WHMCS(config); 46 | ``` 47 | 48 | With the created WHMCS client, you should get the category/module you want (see [available modules](#Implemented-functions)) and call the method you need. 49 | 50 | For example, you can fetch 10 users like this: 51 | 52 | ```javascript 53 | const parameters = { 54 | limitstart: 0, 55 | limitnum: 10 56 | }; 57 | 58 | whmcs.users.getUsers(parameters) 59 | .then(details => { 60 | ... 61 | }) 62 | .catch(err => { 63 | ... 64 | }); 65 | ``` 66 | 67 | If you want/need to, you can use callbacks instead: 68 | 69 | ```javascript 70 | const parameters = { 71 | limitstart: 0, 72 | limitnum: 10 73 | }; 74 | 75 | whmcs.users.getUsers(parameters, function (err, details) { 76 | ... 77 | }); 78 | ``` 79 | 80 | ## Module architecture 81 | 82 | This node-js module follows [WHMCS' API Index](https://developers.whmcs.com/api/api-index/) structure, which have functions organized by categories. Every category is represented here by a module Object, and each module has public methods representing WHMCS' functions. 83 |
84 | When WHMCS' function requires parameters, they must be grouped in a JSON Object and then can be set as the first argument of the method. If no parameters are required, this argument must not be set. The "callback" argument is optional, and when not provided the method returns a Promise. This pattern is shared all across the modules public methods. 85 |
86 | 87 | ## Implemented functions 88 | 89 | The [WHMCS' API Index](https://developers.whmcs.com/api/api-index/) can be updated anytime, so you must check below which functions are implemented (expand to show the function list). 90 | 91 |
92 | Addons 93 | 94 | - UpdateClientAddon: updateClientAddon(parameters, [callback]) 95 |
96 | 97 |
98 | Affiliates 99 | 100 | - AffiliateActivate: affiliateActivate(parameters, [callback]) 101 | - GetAffiliates: getAffiliates(parameters, [callback]) 102 |
103 | 104 |
105 | Authentication 106 | 107 | - CreateOAuthCredential: createOAuthCredential(parameters, [callback]) 108 | - CreateSsoToken: createSsoToken(parameters, [callback]) 109 | - DeleteOAuthCredential: deleteOAuthCredential(parameters, [callback]) 110 | - ListOAuthCredentials: listOAuthCredentials(parameters, [callback]) 111 | - UpdateOAuthCredential: updateOAuthCredential(parameters, [callback]) 112 | - ValidateLogin: validateLogin(parameters, [callback]) 113 |
114 | 115 |
116 | Billing 117 | 118 | - AcceptQuote: acceptQuote(parameters, [callback]) 119 | - AddBillableItem: addBillableItem(parameters, [callback]) 120 | - AddCredit: addCredit(parameters, [callback]) 121 | - AddInvoicePayment: addInvoicePayment(parameters, [callback]) 122 | - AddPayMethod: addPayMethod(parameters, [callback]) 123 | - AddTransaction: addTransaction(parameters, [callback]) 124 | - ApplyCredit: applyCredit(parameters, [callback]) 125 | - CapturePayment: capturePayment(parameters, [callback]) 126 | - CreateInvoice: createInvoice(parameters, [callback]) 127 | - CreateQuote: createQuote(parameters, [callback]) 128 | - DeletePayMethod: deletePayMethod(parameters, [callback]) 129 | - DeleteQuote: deleteQuote(parameters, [callback]) 130 | - GenInvoices: genInvoices(parameters, [callback]) 131 | - GetCredits: getCredits(parameters, [callback]) 132 | - GetInvoice: getInvoice(parameters, [callback]) 133 | - GetInvoices: getInvoices(parameters, [callback]) 134 | - GetPayMethods: getPayMethods(parameters, [callback]) 135 | - GetQuotes: getQuotes(parameters, [callback]) 136 | - GetTransactions: getTransactions(parameters, [callback]) 137 | - SendQuote: sendQuote(parameters, [callback]) 138 | - UpdateInvoice: updateInvoice(parameters, [callback]) 139 | - UpdatePayMethod: updatePayMethod(parameters, [callback]) 140 | - UpdateQuote: updateQuote(parameters, [callback]) 141 | - UpdateTransaction: updateTransaction(parameters, [callback]) 142 |
143 | 144 |
145 | Client 146 | 147 | - AddClient: addClient(parameters, [callback]) 148 | - AddContact: addContact(parameters, [callback]) 149 | - CloseClient: closeClient(parameters, [callback]) 150 | - DeleteClient: deleteClient(parameters, [callback]) 151 | - DeleteContact: deleteContact(parameters, [callback]) 152 | - GetCancelledPackages: getCancelledPackages(parameters, [callback]) 153 | - GetClientGroups: getClientGroups([callback]) 154 | - GetClientPassword: getClientPassword(parameters, [callback]) 155 | - GetClients: getClients(parameters, [callback]) 156 | - GetClientsAddons: getClientsAddons(parameters, [callback]) 157 | - GetClientsDetails: getClientsDetails(parameters, [callback]) 158 | - GetClientsDomains: getClientsDomains(parameters, [callback]) 159 | - GetClientsProducts: getClientsProducts(parameters, [callback]) 160 | - GetContacts: getContacts(parameters, [callback]) 161 | - GetEmails: getEmails(parameters, [callback]) 162 | - UpdateClient: updateClient(parameters, [callback]) 163 | - UpdateContact: updateContact(parameters, [callback]) 164 |
165 | 166 |
167 | Domains 168 | 169 | - CreateOrUpdateTLD: createOrUpdateTLD(parameters, [callback]) 170 | - DomainGetLockingStatus: domainGetLockingStatus(parameters, [callback]) 171 | - DomainGetNameservers: domainGetNameservers(parameters, [callback]) 172 | - DomainGetWhoisInfo: domainGetWhoisInfo(parameters, [callback]) 173 | - DomainRegister: domainRegister(parameters, [callback]) 174 | - DomainRelease: domainRelease(parameters, [callback]) 175 | - DomainRenew: domainRenew(parameters, [callback]) 176 | - DomainRequestEPP: domainRequestEPP(parameters, [callback]) 177 | - DomainToggleIdProtect: domainToggleIdProtect(parameters, [callback]) 178 | - DomainTransfer: domainTransfer(parameters, [callback]) 179 | - DomainUpdateLockingStatus: domainUpdateLockingStatus(parameters, [callback]) 180 | - DomainUpdateNameservers: domainUpdateNameservers(parameters, [callback]) 181 | - DomainUpdateWhoisInfo: domainUpdateWhoisInfo(parameters, [callback]) 182 | - DomainWhois: domainWhois(parameters, [callback]) 183 | - GetTLDPricing: getTLDPricing(parameters, [callback]) 184 | - UpdateClientDomain: updateClientDomain(parameters, [callback]) 185 |
186 | 187 |
188 | Module 189 | 190 | - ActivateModule: activateModule(parameters, [callback]) 191 | - DeactivateModule: deactivateModule(parameters, [callback]) 192 | - GetModuleConfigurationParameters: getModuleConfigurationParameters(parameters, [callback]) 193 | - GetModuleQueue: getModuleQueue(parameters, [callback]) 194 | - UpdateModuleConfiguration: updateModuleConfiguration(parameters, [callback]) 195 |
196 | 197 |
198 | Module 199 | 200 | - AcceptOrder: acceptOrder(parameters, [callback]) 201 | - AddOrder: addOrder(parameters, [callback]) 202 | - CancelOrder: cancelOrder(parameters, [callback]) 203 | - DeleteOrder: deleteOrder(parameters, [callback]) 204 | - FraudOrder: fraudOrder(parameters, [callback]) 205 | - GetOrders: getOrders(parameters, [callback]) 206 | - GetOrderStatuses: getOrderStatuses([callback]) 207 | - GetProducts: getProducts(parameters, [callback]) 208 | - GetPromotions: getPromotions(parameters, [callback]) 209 | - OrderFraudCheck: orderFraudCheck(parameters, [callback]) 210 | - PendingOrder: pendingOrder(parameters, [callback]) 211 |
212 | 213 |
214 | Products 215 | 216 | - AddProduct: addProduct(parameters, [callback]) 217 |
218 | 219 |
220 | Project Management 221 | 222 | - AddProjectMessage: addProjectMessage(parameters, [callback]) 223 | - AddProjectTask: addProjectTask(parameters, [callback]) 224 | - CreateProject: createProject(parameters, [callback]) 225 | - DeleteProjectTask: deleteProjectTask(parameters, [callback]) 226 | - EndTaskTimer: endTaskTimer(parameters, [callback]) 227 | - GetProject: getProject(parameters, [callback]) 228 | - GetProjects: getProjects(parameters, [callback]) 229 | - StartTaskTimer: startTaskTimer(parameters, [callback]) 230 | - UpdateProject: updateProject(parameters, [callback]) 231 | - UpdateProjectTask: updateProjectTask(parameters, [callback]) 232 |
233 | 234 |
235 | Servers 236 | 237 | - GetHealthStatus: getHealthStatus(parameters, [callback]) 238 | - GetServers: getServers(parameters, [callback]) 239 |
240 | 241 | 242 |
243 | Service 244 | 245 | - ModuleChangePackage: moduleChangePackage(parameters, [callback]) 246 | - ModuleChangePw: moduleChangePw(parameters, [callback]) 247 | - ModuleCreate: moduleCreate(parameters, [callback]) 248 | - ModuleCustom: moduleCustom(parameters, [callback]) 249 | - ModuleSuspend: moduleSuspend(parameters, [callback]) 250 | - ModuleTerminate: moduleTerminate(parameters, [callback]) 251 | - ModuleUnsuspend: moduleUnsuspend(parameters, [callback]) 252 | - UpdateClientProduct: updateClientProduct(parameters, [callback]) 253 | - UpgradeProduct: upgradeProduct(parameters, [callback]) 254 |
255 | 256 |
257 | Support 258 | 259 | - AddAnnouncement: addAnnouncement(parameters, [callback]) 260 | - AddCancelRequest: addCancelRequest(parameters, [callback]) 261 | - AddClientNote: addClientNote(parameters, [callback]) 262 | - AddTicketNote: addTicketNote(parameters, [callback]) 263 | - AddTicketReply: addTicketReply(parameters, [callback]) 264 | - blockTicketSender: blockTicketSender(parameters, [callback]) 265 | - DeleteAnnouncement: deleteAnnouncement(parameters, [callback]) 266 | - DeleteTicket: deleteTicket(parameters, [callback]) 267 | - DeleteTicketNote: deleteTicketNote(parameters, [callback]) 268 | - DeleteTicketReply: deleteTicketReply(parameters, [callback]) 269 | - GetAnnouncements: getAnnouncements(parameters, [callback]) 270 | - MergeTicket: mergeTicket(parameters, [callback]) 271 | - OpenTicket: openTicket(parameters, [callback]) 272 | - UpdateTicket: updateTicket(parameters, [callback]) 273 | - UpdateTicketReply: updateTicketReply(parameters, [callback]) 274 |
275 | 276 | 277 |
278 | System 279 | 280 | - AddBannedIp: addBannedIp(parameters, [callback]) 281 | - DecryptPassword: decryptPassword(parameters, [callback]) 282 | - EncryptPassword: encryptPassword(parameters, [callback]) 283 | - GetActivityLog: getActivityLog(parameters, [callback]) 284 | - GetAdminDetails: getAdminDetails([callback]) 285 | - GetAdminUsers: getAdminUsers(parameters, [callback]) 286 | - GetAutomationLog: getAutomationLog(parameters, [callback]) 287 | - GetConfigurationValue: getConfigurationValue(parameters, [callback]) 288 | - GetCurrencies: getCurrencies([callback]) 289 | - GetEmailTemplates: getEmailTemplates(parameters, [callback]) 290 | - GetPaymentMethods: getPaymentMethods([callback]) 291 | - GetStaffOnline: getStaffOnline([callback]) 292 | - GetStats: getStats(parameters, [callback]) 293 | - GetToDoItems: getToDoItems(parameters, [callback]) 294 | - GetToDoItemStatuses: getToDoItemStatuses([callback]) 295 | - LogActivity: logActivity(parameters, [callback]) 296 | - SendAdminEmail: sendAdminEmail(parameters, [callback]) 297 | - SendEmail: sendEmail(parameters, [callback]) 298 | - SetConfigurationValue: setConfigurationValue(parameters, [callback]) 299 | - TriggerNotificationEvent: triggerNotificationEvent(parameters, [callback]) 300 | - UpdateAdminNotes: updateAdminNotes(parameters, [callback]) 301 | - UpdateAnnouncement: updateAnnouncement(parameters, [callback]) 302 | - UpdateToDoItem: updateToDoItem(parameters, [callback]) 303 | - WhmcsDetails: whmcsDetails([callback]) 304 |
305 | 306 |
307 | Tickets 308 | 309 | - GetSupportDepartments: getSupportDepartments(parameters, [callback]) 310 | - GetSupportStatuses: getSupportStatuses(parameters, [callback]) 311 | - GetTicket: getTicket(parameters, [callback]) 312 | - GetTicketAttachment: getTicketAttachment(parameters, [callback]) 313 | - GetTicketCounts: getTicketCounts(parameters, [callback]) 314 | - GetTicketNotes: getTicketNotes(parameters, [callback]) 315 | - GetTicketPredefinedCats: getTicketPredefinedCats([callback]) 316 | - GetTicketPredefinedReplies: getTicketPredefinedReplies(parameters, [callback]) 317 | - GetTickets: getTickets(parameters, [callback]) 318 |
319 | 320 |
321 | Users 322 | 323 | - AddUser: addUser(parameters, [callback]) 324 | - CreateClientInvite: createClientInvite(parameters, [callback]) 325 | - DeleteUserClient: deleteUserClient(parameters, [callback]) 326 | - GetPermissionsList: getPermissionsList([callback]) 327 | - GetUserPermissions: getUserPermissions(parameters, [callback]) 328 | - GetUsers: getUsers(parameters, [callback]) 329 | - ResetPassword: resetPassword(parameters, [callback]) 330 | - UpdateUser: updateUser(parameters, [callback]) 331 | - UpdateUserPermissions: updateUserPermissions(parameters, [callback]) 332 |
333 | 334 | 335 | ## Custom API functions 336 | 337 | It is possible to call custom functions using the method callApi: 338 | 339 | ```javascript 340 | const parameters = { 341 | paramx: 'x', 342 | paramy: 'y' 343 | }; 344 | 345 | whmcs.callApi('CustomFunctionName', parameters) 346 | .then(details => { 347 | ... 348 | }) 349 | .catch(err => { 350 | ... 351 | }); 352 | ``` 353 | 354 | ## Tests 355 | 356 | Tests are implemented using `mocha` and `chai`. Run them with `npm test`. 357 | 358 | 359 | ## License 360 | 361 | Pedro Dias - [@pedromdias](https://twitter.com/pedromdias) 362 | 363 | Licensed under the Apache license, version 2.0 (the "license"); You may not use this file except in compliance with the license. You may obtain a copy of the license at: 364 | 365 | http://www.apache.org/licenses/LICENSE-2.0.html 366 | 367 | Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. See the license for the specific language governing permissions and limitations under the license. 368 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | const hasOwnProperty = Object.prototype.hasOwnProperty; 2 | 3 | module.exports = { 4 | /** 5 | * Extend properties of one object with one or more Objects 6 | * Copied from Underscore - http://underscorejs.org/ 7 | * @param obj Object 8 | * @returns Object 9 | */ 10 | extend: function (obj) { 11 | if (typeof obj !== 'object') return obj; 12 | let source, prop; 13 | for (let i = 1, length = arguments.length; i < length; i++) { 14 | source = arguments[i]; 15 | for (prop in source) { 16 | if (hasOwnProperty.call(source, prop)) { 17 | obj[prop] = source[prop]; 18 | } 19 | } 20 | } 21 | return obj; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /lib/whmcserror.js: -------------------------------------------------------------------------------- 1 | class WhmcsError extends Error { 2 | #httpStatus = null; 3 | #headers = null; 4 | #message = null; 5 | 6 | constructor(message, httpStatus, headers) { 7 | super(message); 8 | this.name = this.constructor.name; 9 | this.message = message; 10 | this.#httpStatus = httpStatus; 11 | this.#headers = headers; 12 | } 13 | 14 | getMessage() { 15 | return this.#message; 16 | } 17 | 18 | getHttpStatus() { 19 | return this.#httpStatus; 20 | } 21 | 22 | getHeaders() { 23 | return this.#headers; 24 | } 25 | } 26 | 27 | module.exports = WhmcsError; -------------------------------------------------------------------------------- /lib/whmcshttpclient.js: -------------------------------------------------------------------------------- 1 | const utils = require('./utils'), 2 | WhmcsError = require('./whmcserror'), 3 | axios = require('axios'), 4 | xml2js = require('xml2js'), 5 | HttpsProxyAgent = require('https-proxy-agent'), 6 | querystring = require('querystring'), 7 | crypto = require('crypto'); 8 | 9 | class WhmcsHttpClient { 10 | #apiSecret = null; 11 | #apiIdentifier = null; 12 | #username = null; 13 | #password = null; 14 | #accessKey = null; 15 | #serverUrl = null; 16 | #Promise = global.Promise; 17 | #responseType = 'json'; 18 | #userAgent = null; 19 | #proxyUrl = null; 20 | #axiosConf = null; 21 | #timeout = 0; 22 | 23 | constructor(configs = {}) { 24 | this.#username = (configs.username != null) ? configs.username : this.#username; 25 | this.#password = (configs.password != null) ? crypto.createHash('md5').update(configs.password).digest('hex') : this.#password; 26 | this.#serverUrl = (configs.serverUrl != null) ? configs.serverUrl : this.#serverUrl; 27 | this.#timeout = (configs.timeout != null) ? configs.timeout : this.#timeout; 28 | this.#apiIdentifier = (configs.apiIdentifier != null) ? configs.apiIdentifier : this.#apiIdentifier; 29 | this.#apiSecret = (configs.apiSecret != null) ? configs.apiSecret : this.#apiSecret; 30 | this.#accessKey = (configs.accessKey != null) ? configs.accessKey : this.#accessKey; 31 | this.#Promise = (configs.Promise != null) ? configs.Promise : this.#Promise; 32 | this.#responseType = (configs.responseType != null) ? configs.responseType : this.#responseType; 33 | this.#userAgent = (configs.userAgent != null) ? configs.userAgent : this.#userAgent; 34 | this.#proxyUrl = (configs.proxyUrl != null) ? configs.proxyUrl : this.#proxyUrl; 35 | 36 | if (this.#Promise != null && typeof this.#Promise.resolve !== 'function') { 37 | throw new Error('Invalid promise library.'); 38 | } 39 | 40 | this.#axiosConf = { 41 | baseURL: this.#serverUrl, 42 | timeout: this.#timeout, 43 | headers: { 44 | 'Content-Type': 'application/x-www-form-urlencoded' 45 | } 46 | }; 47 | 48 | if (this.#userAgent != null) { 49 | this.#axiosConf.headers['User-Agent'] = this.#userAgent; 50 | } 51 | 52 | if (this.#proxyUrl != null) { 53 | this.#axiosConf.httpsAgent = new HttpsProxyAgent(this.#proxyUrl); 54 | } 55 | } 56 | 57 | /** 58 | * Executes a WHMCS' API action with given parameters. 59 | * WHMCS' official action list available here: https://developers.whmcs.com/api/api-index/ 60 | * @param {String} action Command name 61 | * @param {Object} parameters Request parameters (JSON Object) 62 | * @param {*} callback Optional callback. If not set the method returns a Promise 63 | */ 64 | callApi(action, parameters, callback) { 65 | let bodyParams = { 66 | action: action, 67 | username: this.#username, 68 | password: this.#password, 69 | identifier: this.#apiIdentifier, 70 | secret: this.#apiSecret, 71 | accesskey: this.#accessKey, 72 | responsetype: this.#responseType 73 | }; 74 | 75 | if (typeof parameters === 'function' && callback == null) { 76 | callback = parameters; 77 | } else { 78 | bodyParams = utils.extend(bodyParams, parameters); 79 | } 80 | 81 | if (typeof callback === 'function') { 82 | this.#postWithCallback(bodyParams, callback); 83 | } else { 84 | return new this.#Promise((resolve, reject) => { 85 | this.#post(bodyParams).then(res => { 86 | resolve(res); 87 | }).catch(e => { 88 | reject(e); 89 | }); 90 | }); 91 | } 92 | } 93 | 94 | #getAxiosInstance() { 95 | return axios.create(this.#axiosConf); 96 | } 97 | 98 | #postWithCallback(bodyParams, callback) { 99 | this.#post(bodyParams) 100 | .then(res => { 101 | callback(null, res); 102 | }, e => { 103 | callback(e); 104 | }); 105 | } 106 | 107 | async #post(bodyParams) { 108 | const qs = querystring.stringify(bodyParams); 109 | const axios = this.#getAxiosInstance(); 110 | let axiosResp = await axios.post('/includes/api.php', qs); 111 | let parsedData = axiosResp.data; 112 | 113 | if (axiosResp.headers['content-type'].indexOf('application/xml') > -1) { 114 | parsedData = await new Promise((resolve, reject) => { 115 | xml2js.parseString(axiosResp.data, { 116 | 'explicitArray': false 117 | }, function (err, parsedXml) { 118 | if (err) { 119 | return reject(new Error('Error parsing xml')); 120 | } else if (!parsedXml) { 121 | return reject(new Error('Empty HTTP response')); 122 | } else if (!parsedXml.whmcsapi || parsedXml.whmcsapi.constructor != ({}).constructor) { 123 | return reject(new Error('Unexpected XML response')); 124 | } else { 125 | return resolve(parsedXml.whmcsapi); 126 | } 127 | }); 128 | }); 129 | } 130 | 131 | if (parsedData.result && parsedData.result == 'error' || parsedData.status && parsedData.status == 'error') { 132 | const whmcsError = new WhmcsError(parsedData.message, axiosResp.status, axiosResp.headers); 133 | return Promise.reject(whmcsError); 134 | } else { 135 | return Promise.resolve(parsedData); 136 | } 137 | } 138 | } 139 | 140 | module.exports = WhmcsHttpClient; -------------------------------------------------------------------------------- /modules/addons.js: -------------------------------------------------------------------------------- 1 | class Addons { 2 | /** 3 | * Creates a new Addons object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Updates a Client Addon. 12 | * https://developers.whmcs.com/api-reference/updateclientaddon/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | updateClientAddon(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('UpdateClientAddon', parameters, callback); 18 | }; 19 | } 20 | 21 | module.exports = Addons; 22 | -------------------------------------------------------------------------------- /modules/affiliates.js: -------------------------------------------------------------------------------- 1 | class Affiliates { 2 | /** 3 | * Creates a new Affiliates object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Activate affiliate referrals for a client. 12 | * https://developers.whmcs.com/api-reference/affiliateactivate/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | affiliateActivate(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AffiliateActivate', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Obtain an array of affiliates 22 | * https://developers.whmcs.com/api-reference/getaffiliates/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | getAffiliates(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('GetAffiliates', parameters, callback); 28 | }; 29 | } 30 | 31 | module.exports = Affiliates; 32 | -------------------------------------------------------------------------------- /modules/authentication.js: -------------------------------------------------------------------------------- 1 | class Authentication { 2 | /** 3 | * Creates a new Authentication object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Create an OAuth Credential 12 | * https://developers.whmcs.com/api-reference/createoauthcredential/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | createOAuthCredential(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('CreateOAuthCredential', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Create a single use, client or user single sign-on access token. 22 | * https://developers.whmcs.com/api-reference/createssotoken/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | createSsoToken(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('CreateSsoToken', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Removes OAuth Credential record. This action cannot be undone. 32 | * https://developers.whmcs.com/api-reference/deleteoauthcredential/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | deleteOAuthCredential(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('DeleteOAuthCredential', parameters, callback); 38 | }; 39 | 40 | /** 41 | * List OAuth Credentials matching passed criteria. 42 | * https://developers.whmcs.com/api-reference/listoauthcredentials/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | listOAuthCredentials(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('ListOAuthCredentials', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Updates a given OAuth API Client Credential. 52 | * https://developers.whmcs.com/api-reference/updateoauthcredential/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | updateOAuthCredential(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('UpdateOAuthCredential', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Validate user login credentials. 62 | * https://developers.whmcs.com/api-reference/validatelogin/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | validateLogin(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('ValidateLogin', parameters, callback); 68 | }; 69 | 70 | } 71 | 72 | module.exports = Authentication; 73 | -------------------------------------------------------------------------------- /modules/billing.js: -------------------------------------------------------------------------------- 1 | class Billing { 2 | /** 3 | * Creates a new Billing object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Accepts a quote. 12 | * https://developers.whmcs.com/api-reference/acceptquote/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | acceptQuote(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AcceptQuote', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Adds a Billable Item. 22 | * https://developers.whmcs.com/api-reference/addbillableitem/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | addBillableItem(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('AddBillableItem', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Adds credit to a given client. 32 | * https://developers.whmcs.com/api-reference/addcredit/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | addCredit(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('AddCredit', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Adds payment to a given invoice. 42 | * https://developers.whmcs.com/api-reference/addinvoicepayment/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | addInvoicePayment(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('AddInvoicePayment', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Add a Pay Method to a given client. 52 | * https://developers.whmcs.com/api-reference/addpaymethod/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | addPayMethod(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('AddPayMethod', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Add a transaction to the system. 62 | * https://developers.whmcs.com/api-reference/addtransaction/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | addTransaction(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('AddTransaction', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Applies the Client’s Credit to an invoice. 72 | * https://developers.whmcs.com/api-reference/applycredit/ 73 | * @param {Object} parameters Request parameters 74 | * @param {Function} callback Optional callback. If not set the method returns a Promise 75 | */ 76 | applyCredit(parameters, callback) { 77 | return this.whmcsHttpClient.callApi('ApplyCredit', parameters, callback); 78 | }; 79 | 80 | /** 81 | * Attempt to capture a payment on an unpaid CC Invoice. 82 | * https://developers.whmcs.com/api-reference/capturepayment/ 83 | * @param {Object} parameters Request parameters 84 | * @param {Function} callback Optional callback. If not set the method returns a Promise 85 | */ 86 | capturePayment(parameters, callback) { 87 | return this.whmcsHttpClient.callApi('CapturePayment', parameters, callback); 88 | }; 89 | 90 | /** 91 | * Create an invoice using the provided parameters. 92 | * https://developers.whmcs.com/api-reference/createinvoice/ 93 | * @param {Object} parameters Request parameters 94 | * @param {Function} callback Optional callback. If not set the method returns a Promise 95 | */ 96 | createInvoice(parameters, callback) { 97 | return this.whmcsHttpClient.callApi('CreateInvoice', parameters, callback); 98 | }; 99 | 100 | /** 101 | * Creates a new quote. 102 | * https://developers.whmcs.com/api-reference/createquote/ 103 | * @param {Object} parameters Request parameters 104 | * @param {Function} callback Optional callback. If not set the method returns a Promise 105 | */ 106 | createQuote(parameters, callback) { 107 | return this.whmcsHttpClient.callApi('CreateQuote', parameters, callback); 108 | }; 109 | 110 | /** 111 | * Delete a Pay Method. 112 | * https://developers.whmcs.com/api-reference/deletepaymethod/ 113 | * @param {Object} parameters Request parameters 114 | * @param {Function} callback Optional callback. If not set the method returns a Promise 115 | */ 116 | deletePayMethod(parameters, callback) { 117 | return this.whmcsHttpClient.callApi('DeletePayMethod', parameters, callback); 118 | }; 119 | 120 | /** 121 | * Deletes a quote. 122 | * https://developers.whmcs.com/api-reference/deletequote/ 123 | * @param {Object} parameters Request parameters 124 | * @param {Function} callback Optional callback. If not set the method returns a Promise 125 | */ 126 | deleteQuote(parameters, callback) { 127 | return this.whmcsHttpClient.callApi('DeleteQuote', parameters, callback); 128 | }; 129 | 130 | /** 131 | * Generate any invoices that are due to be generated. 132 | * https://developers.whmcs.com/api-reference/geninvoices/ 133 | * @param {Object} parameters Request parameters 134 | * @param {Function} callback Optional callback. If not set the method returns a Promise 135 | */ 136 | genInvoices(parameters, callback) { 137 | return this.whmcsHttpClient.callApi('GenInvoices', parameters, callback); 138 | }; 139 | 140 | /** 141 | * Obtain the Credit Log for a Client Account. 142 | * https://developers.whmcs.com/api-reference/getcredits/ 143 | * @param {Object} parameters Request parameters 144 | * @param {Function} callback Optional callback. If not set the method returns a Promise 145 | */ 146 | getCredits(parameters, callback) { 147 | return this.whmcsHttpClient.callApi('GetCredits', parameters, callback); 148 | }; 149 | 150 | /** 151 | * Retrieve a specific invoice. 152 | * https://developers.whmcs.com/api-reference/getinvoice/ 153 | * @param {Object} parameters Request parameters 154 | * @param {Function} callback Optional callback. If not set the method returns a Promise 155 | */ 156 | getInvoice(parameters, callback) { 157 | return this.whmcsHttpClient.callApi('GetInvoice', parameters, callback); 158 | }; 159 | 160 | /** 161 | * Retrieve a list of invoices. 162 | * https://developers.whmcs.com/api-reference/getinvoices/ 163 | * @param {Object} parameters Request parameters 164 | * @param {Function} callback Optional callback. If not set the method returns a Promise 165 | */ 166 | getInvoices(parameters, callback) { 167 | return this.whmcsHttpClient.callApi('GetInvoices', parameters, callback); 168 | }; 169 | 170 | /** 171 | * Obtain the Pay Methods associated with a provided client id. 172 | * https://developers.whmcs.com/api-reference/getpaymethods/ 173 | * @param {Object} parameters Request parameters 174 | * @param {Function} callback Optional callback. If not set the method returns a Promise 175 | */ 176 | getPayMethods(parameters, callback) { 177 | return this.whmcsHttpClient.callApi('GetPayMethods', parameters, callback); 178 | }; 179 | 180 | /** 181 | * Obtain quotes matching the passed criteria. 182 | * https://developers.whmcs.com/api-reference/getquotes/ 183 | * @param {Object} parameters Request parameters 184 | * @param {Function} callback Optional callback. If not set the method returns a Promise 185 | */ 186 | getQuotes(parameters, callback) { 187 | return this.whmcsHttpClient.callApi('GetQuotes', parameters, callback); 188 | }; 189 | 190 | /** 191 | * Obtain transactions matching the passed criteria. 192 | * https://developers.whmcs.com/api-reference/gettransactions/ 193 | * @param {Object} parameters Request parameters 194 | * @param {Function} callback Optional callback. If not set the method returns a Promise 195 | */ 196 | getTransactions(parameters, callback) { 197 | return this.whmcsHttpClient.callApi('GetTransactions', parameters, callback); 198 | }; 199 | 200 | /** 201 | * Send a quote to the associated client. 202 | * https://developers.whmcs.com/api-reference/sendquote/ 203 | * @param {Object} parameters Request parameters 204 | * @param {Function} callback Optional callback. If not set the method returns a Promise 205 | */ 206 | sendQuote(parameters, callback) { 207 | return this.whmcsHttpClient.callApi('SendQuote', parameters, callback); 208 | }; 209 | 210 | /** 211 | * Update an invoice using the provided parameters. 212 | * https://developers.whmcs.com/api-reference/updateinvoice/ 213 | * @param {Object} parameters Request parameters 214 | * @param {Function} callback Optional callback. If not set the method returns a Promise 215 | */ 216 | updateInvoice(parameters, callback) { 217 | return this.whmcsHttpClient.callApi('UpdateInvoice', parameters, callback); 218 | }; 219 | 220 | /** 221 | * Update a Credit Card Pay Method. 222 | * https://developers.whmcs.com/api-reference/updatepaymethod/ 223 | * @param {Object} parameters Request parameters 224 | * @param {Function} callback Optional callback. If not set the method returns a Promise 225 | */ 226 | updatePayMethod(parameters, callback) { 227 | return this.whmcsHttpClient.callApi('UpdatePayMethod', parameters, callback); 228 | }; 229 | 230 | /** 231 | * Updates an existing quote. 232 | * https://developers.whmcs.com/api-reference/updatequote/ 233 | * @param {Object} parameters Request parameters 234 | * @param {Function} callback Optional callback. If not set the method returns a Promise 235 | */ 236 | 237 | updateQuote(parameters, callback) { 238 | return this.whmcsHttpClient.callApi('UpdateQuote', parameters, callback); 239 | }; 240 | 241 | /** 242 | * Updates a transaction in the system. 243 | * https://developers.whmcs.com/api-reference/updatetransaction/ 244 | * @param {Object} parameters Request parameters 245 | * @param {Function} callback Optional callback. If not set the method returns a Promise 246 | */ 247 | updateTransaction(parameters, callback) { 248 | return this.whmcsHttpClient.callApi('UpdateTransaction', parameters, callback); 249 | }; 250 | } 251 | 252 | module.exports = Billing; -------------------------------------------------------------------------------- /modules/client.js: -------------------------------------------------------------------------------- 1 | class Client { 2 | /** 3 | * Creates a new Client object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Adds a client. 12 | * https://developers.whmcs.com/api-reference/addclient/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | addClient(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AddClient', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Adds a contact to a client account. 22 | * https://developers.whmcs.com/api-reference/addcontact/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | addContact(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('AddContact', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Close a Client. 32 | * https://developers.whmcs.com/api-reference/closeclient/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | closeClient(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('CloseClient', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Deletes a client. 42 | * https://developers.whmcs.com/api-reference/deleteclient/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | deleteClient(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('DeleteClient', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Deletes a contact. 52 | * https://developers.whmcs.com/api-reference/deletecontact/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | deleteContact(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('DeleteContact', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Obtain an array of cancellation requests. 62 | * https://developers.whmcs.com/api-reference/getcancelledpackages/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | getCancelledPackages(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('GetCancelledPackages', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Obtain an array of client groups. 72 | * https://developers.whmcs.com/api-reference/getclientgroups/ 73 | * @param {Function} callback Optional callback. If not set the method returns a Promise 74 | */ 75 | getClientGroups(callback) { 76 | return this.whmcsHttpClient.callApi('GetClientGroups', callback); 77 | }; 78 | 79 | /** 80 | * Obtain the encrypted client password. 81 | * https://developers.whmcs.com/api-reference/getclientpassword/ 82 | * @param {Object} parameters Request parameters 83 | * @param {Function} callback Optional callback. If not set the method returns a Promise 84 | */ 85 | getClientPassword(parameters, callback) { 86 | return this.whmcsHttpClient.callApi('GetClientPassword', parameters, callback); 87 | }; 88 | 89 | /** 90 | * Obtain the Clients that match passed criteria. 91 | * https://developers.whmcs.com/api-reference/getclients/ 92 | * @param {Object} parameters Request parameters 93 | * @param {Function} callback Optional callback. If not set the method returns a Promise 94 | */ 95 | getClients(parameters, callback) { 96 | return this.whmcsHttpClient.callApi('GetClients', parameters, callback); 97 | }; 98 | 99 | /** 100 | * Obtain the Clients Product Addons that match passed criteria. 101 | * https://developers.whmcs.com/api-reference/getclientsaddons/ 102 | * @param {Object} parameters Request parameters 103 | * @param {Function} callback Optional callback. If not set the method returns a Promise 104 | */ 105 | getClientsAddons(parameters, callback) { 106 | return this.whmcsHttpClient.callApi('GetClientsAddons', parameters, callback); 107 | }; 108 | 109 | /** 110 | * Obtain the Clients Details for a specific client. 111 | * https://developers.whmcs.com/api-reference/getclientsdetails/ 112 | * @param {Object} parameters Request parameters 113 | * @param {Function} callback Optional callback. If not set the method returns a Promise 114 | */ 115 | getClientsDetails(parameters, callback) { 116 | return this.whmcsHttpClient.callApi('GetClientsDetails', parameters, callback); 117 | }; 118 | 119 | /** 120 | * Obtain a list of Client Purchased Domains matching the provided criteria. 121 | * https://developers.whmcs.com/api-reference/getclientsdomains/ 122 | * @param {Object} parameters Request parameters 123 | * @param {Function} callback Optional callback. If not set the method returns a Promise 124 | */ 125 | getClientsDomains(parameters, callback) { 126 | return this.whmcsHttpClient.callApi('GetClientsDomains', parameters, callback); 127 | }; 128 | 129 | /** 130 | * Obtain a list of Client Purchased Products matching the provided criteria. 131 | * https://developers.whmcs.com/api-reference/getclientsproducts/ 132 | * @param {Object} parameters Request parameters 133 | * @param {Function} callback Optional callback. If not set the method returns a Promise 134 | */ 135 | getClientsProducts(parameters, callback) { 136 | return this.whmcsHttpClient.callApi('GetClientsProducts', parameters, callback); 137 | }; 138 | 139 | /** 140 | * Obtain the Client Contacts that match passed criteria. 141 | * https://developers.whmcs.com/api-reference/getcontacts/ 142 | * @param {Object} parameters Request parameters 143 | * @param {Function} callback Optional callback. If not set the method returns a Promise 144 | */ 145 | getContacts(parameters, callback) { 146 | return this.whmcsHttpClient.callApi('GetContacts', parameters, callback); 147 | }; 148 | 149 | /** 150 | * Obtain a list of emails sent to a specific Client ID. 151 | * https://developers.whmcs.com/api-reference/getemails/ 152 | * @param {Object} parameters Request parameters 153 | * @param {Function} callback Optional callback. If not set the method returns a Promise 154 | */ 155 | getEmails(parameters, callback) { 156 | return this.whmcsHttpClient.callApi('GetEmails', parameters, callback); 157 | }; 158 | 159 | /** 160 | * Updates a client with the passed parameters. 161 | * https://developers.whmcs.com/api-reference/updateclient/ 162 | * @param {Object} parameters Request parameters 163 | * @param {Function} callback Optional callback. If not set the method returns a Promise 164 | */ 165 | updateClient(parameters, callback) { 166 | return this.whmcsHttpClient.callApi('UpdateClient', parameters, callback); 167 | }; 168 | 169 | /** 170 | * Updates a contact with the passed parameters. 171 | * https://developers.whmcs.com/api-reference/updatecontact/ 172 | * @param {Object} parameters Request parameters 173 | * @param {Function} callback Optional callback. If not set the method returns a Promise 174 | */ 175 | updateContact(parameters, callback) { 176 | return this.whmcsHttpClient.callApi('UpdateContact', parameters, callback); 177 | }; 178 | } 179 | 180 | module.exports = Client; -------------------------------------------------------------------------------- /modules/domains.js: -------------------------------------------------------------------------------- 1 | class Domains { 2 | /** 3 | * Creates a new Domains object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Create or Update a TLD Extension. 12 | * https://developers.whmcs.com/api-reference/createorupdatetld/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | createOrUpdateTLD(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('CreateOrUpdateTLD', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Obtains the current lock status of the domain. 22 | * https://developers.whmcs.com/api-reference/domaingetlockingstatus/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | domainGetLockingStatus(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('DomainGetLockingStatus', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Obtains the current nameservers for the domain. 32 | * https://developers.whmcs.com/api-reference/domaingetnameservers/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | domainGetNameservers(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('DomainGetNameservers', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Obtains the current whois information for the domain. 42 | * https://developers.whmcs.com/api-reference/domaingetwhoisinfo/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | domainGetWhoisInfo(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('DomainGetWhoisInfo', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Sends the Register command to the registrar for the domain. 52 | * https://developers.whmcs.com/api-reference/domainregister/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | domainRegister(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('DomainRegister', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Sends the Release command to the registrar for the domain to a new tag. 62 | * https://developers.whmcs.com/api-reference/domainrelease/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | domainRelease(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('DomainRelease', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Sends the Renew command to the registrar for the domain. 72 | * https://developers.whmcs.com/api-reference/domainrenew/ 73 | * @param {Object} parameters Request parameters 74 | * @param {Function} callback Optional callback. If not set the method returns a Promise 75 | */ 76 | domainRenew(parameters, callback) { 77 | return this.whmcsHttpClient.callApi('DomainRenew', parameters, callback); 78 | }; 79 | 80 | /** 81 | * Sends the Request EPP command to the registrar for the domain. 82 | * https://developers.whmcs.com/api-reference/domainrequestepp/ 83 | * @param {Object} parameters Request parameters 84 | * @param {Function} callback Optional callback. If not set the method returns a Promise 85 | */ 86 | domainRequestEPP(parameters, callback) { 87 | return this.whmcsHttpClient.callApi('DomainRequestEPP', parameters, callback); 88 | }; 89 | 90 | /** 91 | * Sends the Toggle ID Protect command to the registrar for the domain. 92 | * https://developers.whmcs.com/api-reference/domaintoggleidprotect/ 93 | * @param {Object} parameters Request parameters 94 | * @param {Function} callback Optional callback. If not set the method returns a Promise 95 | */ 96 | domainToggleIdProtect(parameters, callback) { 97 | return this.whmcsHttpClient.callApi('DomainToggleIdProtect', parameters, callback); 98 | }; 99 | 100 | /** 101 | * Sends the Transfer command to the registrar for the domain. 102 | * https://developers.whmcs.com/api-reference/domaintransfer/ 103 | * @param {Object} parameters Request parameters 104 | * @param {Function} callback Optional callback. If not set the method returns a Promise 105 | */ 106 | domainTransfer(parameters, callback) { 107 | return this.whmcsHttpClient.callApi('DomainTransfer', parameters, callback); 108 | }; 109 | 110 | /** 111 | * Sends the Update Lock command to the registrar for the domain. 112 | * https://developers.whmcs.com/api-reference/domainupdatelockingstatus/ 113 | * @param {Object} parameters Request parameters 114 | * @param {Function} callback Optional callback. If not set the method returns a Promise 115 | */ 116 | domainUpdateLockingStatus(parameters, callback) { 117 | return this.whmcsHttpClient.callApi('DomainUpdateLockingStatus', parameters, callback); 118 | }; 119 | 120 | /** 121 | * Sends the Save Nameservers command to the registrar for the domain. 122 | * https://developers.whmcs.com/api-reference/domainupdatenameservers/ 123 | * @param {Object} parameters Request parameters 124 | * @param {Function} callback Optional callback. If not set the method returns a Promise 125 | */ 126 | domainUpdateNameservers(parameters, callback) { 127 | return this.whmcsHttpClient.callApi('DomainUpdateNameservers', parameters, callback); 128 | }; 129 | 130 | /** 131 | * Sends the Save Whois command to the registrar for the domain. 132 | * https://developers.whmcs.com/api-reference/domainupdatewhoisinfo/ 133 | * @param {Object} parameters Request parameters 134 | * @param {Function} callback Optional callback. If not set the method returns a Promise 135 | */ 136 | domainUpdateWhoisInfo(parameters, callback) { 137 | return this.whmcsHttpClient.callApi('DomainUpdateWhoisInfo', parameters, callback); 138 | }; 139 | 140 | /** 141 | * Retrieve domain whois information. 142 | * https://developers.whmcs.com/api-reference/domainwhois/ 143 | * @param {Object} parameters Request parameters 144 | * @param {Function} callback Optional callback. If not set the method returns a Promise 145 | */ 146 | domainWhois(parameters, callback) { 147 | return this.whmcsHttpClient.callApi('DomainWhois', parameters, callback); 148 | }; 149 | 150 | /** 151 | * Retrieve TLD pricing. 152 | * https://developers.whmcs.com/api-reference/gettldpricing/ 153 | * @param {Object} parameters Request parameters 154 | * @param {Function} callback Optional callback. If not set the method returns a Promise 155 | */ 156 | getTLDPricing(parameters, callback) { 157 | return this.whmcsHttpClient.callApi('GetTLDPricing', parameters, callback); 158 | }; 159 | 160 | /** 161 | * Updates a Client Domain. 162 | * https://developers.whmcs.com/api-reference/updateclientdomain/ 163 | * @param {Object} parameters Request parameters 164 | * @param {Function} callback Optional callback. If not set the method returns a Promise 165 | */ 166 | updateClientDomain(parameters, callback) { 167 | return this.whmcsHttpClient.callApi('UpdateClientDomain', parameters, callback); 168 | }; 169 | } 170 | 171 | module.exports = Domains; 172 | -------------------------------------------------------------------------------- /modules/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | Orders: require('./orders.js'), 3 | Billing: require('./billing.js'), 4 | Module: require('./module.js'), 5 | Support: require('./support.js'), 6 | System: require('./system.js'), 7 | Client: require('./client.js'), 8 | Products: require('./products.js'), 9 | ProjectManagement: require('./projectmanagement.js'), 10 | Users: require('./users.js'), 11 | Affiliates: require('./affiliates.js'), 12 | Authentication: require('./authentication.js'), 13 | Domains: require('./domains.js'), 14 | Servers: require('./servers.js'), 15 | Tickets: require('./tickets.js'), 16 | Service: require('./service.js'), 17 | Addons: require('./addons.js') 18 | } 19 | -------------------------------------------------------------------------------- /modules/module.js: -------------------------------------------------------------------------------- 1 | class Module { 2 | /** 3 | * Creates a new Module object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Activates a given module. 12 | * https://developers.whmcs.com/api-reference/activatemodule/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | activateModule(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('ActivateModule', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Deactivates a given module. 22 | * https://developers.whmcs.com/api-reference/deactivatemodule/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | deactivateModule(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('DeactivateModule', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Obtains the Module Configuration Parameters. 32 | * https://developers.whmcs.com/api-reference/getmoduleconfigurationparameters/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | getModuleConfigurationParameters(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('GetModuleConfigurationParameters', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Obtains the Module Queue for Incomplete Failed Actions. 42 | * https://developers.whmcs.com/api-reference/getmodulequeue/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | getModuleQueue(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('GetModuleQueue', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Updates a given module. 52 | * https://developers.whmcs.com/api-reference/updatemoduleconfiguration/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | updateModuleConfiguration(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('UpdateModuleConfiguration', parameters, callback); 58 | }; 59 | } 60 | 61 | module.exports = Module; -------------------------------------------------------------------------------- /modules/orders.js: -------------------------------------------------------------------------------- 1 | class Orders { 2 | /** 3 | * Creates a new Orders object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Accepts a pending order. 12 | * https://developers.whmcs.com/api-reference/acceptorder/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | acceptOrder(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AcceptOrder', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Adds an order to a client. 22 | * https://developers.whmcs.com/api-reference/addorder/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | addOrder(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('AddOrder', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Cancel a Pending Order. 32 | * https://developers.whmcs.com/api-reference/cancelorder/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | cancelOrder(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('CancelOrder', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Deletes a cancelled or fraud order. 42 | * https://developers.whmcs.com/api-reference/deleteorder/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | deleteOrder(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('DeleteOrder', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Marks an order as fraudulent. 52 | * https://developers.whmcs.com/api-reference/fraudorder/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | fraudOrder(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('FraudOrder', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Obtain orders matching the passed criteria. 62 | * https://developers.whmcs.com/api-reference/getorders/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | getOrders(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('GetOrders', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Retrieve Order Status and number in those statuses. 72 | * https://developers.whmcs.com/api-reference/getorderstatuses/ 73 | * @param {Function} callback Optional callback. If not set the method returns a Promise 74 | */ 75 | getOrderStatuses(callback) { 76 | return this.whmcsHttpClient.callApi('GetOrderStatuses', callback); 77 | }; 78 | 79 | /** 80 | * Retrieve configured products matching provided criteria. 81 | * https://developers.whmcs.com/api-reference/getproducts/ 82 | * @param {Object} parameters Request parameters 83 | * @param {Function} callback Optional callback. If not set the method returns a Promise 84 | */ 85 | getProducts(parameters, callback) { 86 | return this.whmcsHttpClient.callApi('GetProducts', parameters, callback); 87 | }; 88 | 89 | /** 90 | * Obtain promotions matching the passed criteria. 91 | * https://developers.whmcs.com/api-reference/getpromotions/ 92 | * @param {Object} parameters Request parameters 93 | * @param {Function} callback Optional callback. If not set the method returns a Promise 94 | */ 95 | getPromotions(parameters, callback) { 96 | return this.whmcsHttpClient.callApi('GetPromotions', parameters, callback); 97 | }; 98 | 99 | /** 100 | * Run a fraud check on a passed Order ID using the active fraud module. 101 | * https://developers.whmcs.com/api-reference/orderfraudcheck/ 102 | * @param {Object} parameters Request parameters 103 | * @param {Function} callback Optional callback. If not set the method returns a Promise 104 | */ 105 | orderFraudCheck(parameters, callback) { 106 | return this.whmcsHttpClient.callApi('OrderFraudCheck', parameters, callback); 107 | }; 108 | 109 | /** 110 | * Sets an order, and all associated order items to Pending status. 111 | * https://developers.whmcs.com/api-reference/pendingorder/ 112 | * @param {Object} parameters Request parameters 113 | * @param {Function} callback Optional callback. If not set the method returns a Promise 114 | */ 115 | pendingOrder(parameters, callback) { 116 | return this.whmcsHttpClient.callApi('PendingOrder', parameters, callback); 117 | }; 118 | } 119 | 120 | module.exports = Orders; -------------------------------------------------------------------------------- /modules/products.js: -------------------------------------------------------------------------------- 1 | class Products { 2 | /** 3 | * Creates a new Products object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Adds a product to the system to be available for purchase. 12 | * https://developers.whmcs.com/api-reference/addproduct/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | addProduct(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AddProduct', parameters, callback); 18 | }; 19 | } 20 | module.exports = Products; 21 | -------------------------------------------------------------------------------- /modules/projectmanagement.js: -------------------------------------------------------------------------------- 1 | class ProjectManagement { 2 | /** 3 | * Creates a new ProjectManagement object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Adds a Message to a project. 12 | * https://developers.whmcs.com/api-reference/addprojectmessage/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | addProjectMessage(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AddProjectMessage', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Adds a Task to a project. 22 | * https://developers.whmcs.com/api-reference/addprojecttask/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | addProjectTask(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('AddProjectTask', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Creates a new project. 32 | * https://developers.whmcs.com/api-reference/createproject/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | createProject(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('CreateProject', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Deletes a task associated with a project. 42 | * https://developers.whmcs.com/api-reference/deleteprojecttask/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | deleteProjectTask(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('DeleteProjectTask', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Ends a started timer for a project. 52 | * https://developers.whmcs.com/api-reference/endtasktimer/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | endTaskTimer(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('EndTaskTimer', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Retrieve a specific Project. 62 | * https://developers.whmcs.com/api-reference/getproject/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | getProject(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('GetProject', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Obtain orders matching the passed criteria. 72 | * https://developers.whmcs.com/api-reference/getprojects/ 73 | * @param {Object} parameters Request parameters 74 | * @param {Function} callback Optional callback. If not set the method returns a Promise 75 | */ 76 | getProjects(parameters, callback) { 77 | return this.whmcsHttpClient.callApi('GetProjects', parameters, callback); 78 | }; 79 | 80 | /** 81 | * Starts a timer for a project. 82 | * https://developers.whmcs.com/api-reference/starttasktimer/ 83 | * @param {Object} parameters Request parameters 84 | * @param {Function} callback Optional callback. If not set the method returns a Promise 85 | */ 86 | startTaskTimer(parameters, callback) { 87 | return this.whmcsHttpClient.callApi('StartTaskTimer', parameters, callback); 88 | }; 89 | 90 | /** 91 | * Updates a project. 92 | * https://developers.whmcs.com/api-reference/updateproject/ 93 | * @param {Object} parameters Request parameters 94 | * @param {Function} callback Optional callback. If not set the method returns a Promise 95 | */ 96 | updateProject(parameters, callback) { 97 | return this.whmcsHttpClient.callApi('UpdateProject', parameters, callback); 98 | }; 99 | 100 | /** 101 | * Adds a Task to a project. 102 | * https://developers.whmcs.com/api-reference/updateprojecttask/ 103 | * @param {Object} parameters Request parameters 104 | * @param {Function} callback Optional callback. If not set the method returns a Promise 105 | */ 106 | updateProjectTask(parameters, callback) { 107 | return this.whmcsHttpClient.callApi('UpdateProjectTask', parameters, callback); 108 | }; 109 | } 110 | 111 | module.exports = ProjectManagement; 112 | -------------------------------------------------------------------------------- /modules/servers.js: -------------------------------------------------------------------------------- 1 | class Servers { 2 | /** 3 | * Creates a new Servers object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Get health status. 12 | * https://developers.whmcs.com/api-reference/gethealthstatus/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | getHealthStatus(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('GetHealthStatus', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Get servers. 22 | * https://developers.whmcs.com/api-reference/getservers/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | getServers(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('GetServers', parameters, callback); 28 | }; 29 | } 30 | 31 | module.exports = Servers; 32 | -------------------------------------------------------------------------------- /modules/service.js: -------------------------------------------------------------------------------- 1 | class Service { 2 | /** 3 | * Creates a new Service object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Runs a change package action for a given service. 12 | * https://developers.whmcs.com/api-reference/modulechangepackage/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | moduleChangePackage(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('ModuleChangePackage', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Runs a change password action for a given service. 22 | * https://developers.whmcs.com/api-reference/modulechangepw/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | moduleChangePw(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('ModuleChangePw', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Runs the module create action for a given service. 32 | * https://developers.whmcs.com/api-reference/modulecreate/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | moduleCreate(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('ModuleCreate', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Runs a custom module action for a given service. 42 | * https://developers.whmcs.com/api-reference/modulecustom/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | moduleCustom(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('ModuleCustom', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Runs the module suspend action for a given service. 52 | * https://developers.whmcs.com/api-reference/modulesuspend/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | moduleSuspend(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('ModuleSuspend', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Runs a terminate action for a given service. 62 | * https://developers.whmcs.com/api-reference/moduleterminate/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | moduleTerminate(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('ModuleTerminate', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Runs an unsuspend action for a given service. 72 | * https://developers.whmcs.com/api-reference/moduleunsuspend/ 73 | * @param {Object} parameters Request parameters 74 | * @param {Function} callback Optional callback. If not set the method returns a Promise 75 | */ 76 | moduleUnsuspend(parameters, callback) { 77 | return this.whmcsHttpClient.callApi('ModuleUnsuspend', parameters, callback); 78 | }; 79 | 80 | /** 81 | * Updates a Client Service. 82 | * https://developers.whmcs.com/api-reference/updateclientproduct/ 83 | * @param {Object} parameters Request parameters 84 | * @param {Function} callback Optional callback. If not set the method returns a Promise 85 | */ 86 | updateClientProduct(parameters, callback) { 87 | return this.whmcsHttpClient.callApi('UpdateClientProduct', parameters, callback); 88 | }; 89 | 90 | /** 91 | * Upgrade, or calculate an upgrade on, a product. 92 | * https://developers.whmcs.com/api-reference/upgradeproduct/ 93 | * @param {Object} parameters Request parameters 94 | * @param {Function} callback Optional callback. If not set the method returns a Promise 95 | */ 96 | upgradeProduct(parameters, callback) { 97 | return this.whmcsHttpClient.callApi('UpgradeProduct', parameters, callback); 98 | }; 99 | } 100 | 101 | module.exports = Service; 102 | -------------------------------------------------------------------------------- /modules/support.js: -------------------------------------------------------------------------------- 1 | class Support { 2 | /** 3 | * Creates a new Support object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Adds an announcement. 12 | * https://developers.whmcs.com/api-reference/addannouncement/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | addAnnouncement(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AddAnnouncement', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Adds a Cancellation Request. 22 | * https://developers.whmcs.com/api-reference/addcancelrequest/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | addCancelRequest(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('AddCancelRequest', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Adds a Client Note. 32 | * https://developers.whmcs.com/api-reference/addclientnote/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | addClientNote(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('AddClientNote', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Add a note to a ticket by Ticket ID or Ticket Number. 42 | * https://developers.whmcs.com/api-reference/addticketnote/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | addTicketNote(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('AddTicketNote', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Add a reply to a ticket by Ticket ID. 52 | * https://developers.whmcs.com/api-reference/addticketreply/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | addTicketReply(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('AddTicketReply', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Blocks a ticket sender. 62 | * https://developers.whmcs.com/api-reference/blockticketsender/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | blockTicketSender(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('BlockTicketSender', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Delete an announcement. 72 | * https://developers.whmcs.com/api-reference/deleteannouncement/ 73 | * @param {Object} parameters Request parameters 74 | * @param {Function} callback Optional callback. If not set the method returns a Promise 75 | */ 76 | deleteAnnouncement(parameters, callback) { 77 | return this.whmcsHttpClient.callApi('DeleteAnnouncement', parameters, callback); 78 | }; 79 | 80 | /** 81 | * Deletes a ticket. 82 | * https://developers.whmcs.com/api-reference/deleteticket/ 83 | * @param {Object} parameters Request parameters 84 | * @param {Function} callback Optional callback. If not set the method returns a Promise 85 | */ 86 | deleteTicket(parameters, callback) { 87 | return this.whmcsHttpClient.callApi('DeleteTicket', parameters, callback); 88 | }; 89 | 90 | /** 91 | * Deletes a ticket note. 92 | * https://developers.whmcs.com/api-reference/deleteticketnote/ 93 | * @param {Object} parameters Request parameters 94 | * @param {Function} callback Optional callback. If not set the method returns a Promise 95 | */ 96 | deleteTicketNote(parameters, callback) { 97 | return this.whmcsHttpClient.callApi('DeleteTicketNote', parameters, callback); 98 | }; 99 | 100 | /** 101 | * Deletes a ticket reply. 102 | * https://developers.whmcs.com/api-reference/deleteticketreply/ 103 | * @param {Object} parameters Request parameters 104 | * @param {Function} callback Optional callback. If not set the method returns a Promise 105 | */ 106 | deleteTicketReply(parameters, callback) { 107 | return this.whmcsHttpClient.callApi('DeleteTicketReply', parameters, callback); 108 | }; 109 | 110 | /** 111 | * Obtain an array of announcements. 112 | * https://developers.whmcs.com/api-reference/getannouncements/ 113 | * @param {Object} parameters Request parameters 114 | * @param {Function} callback Optional callback. If not set the method returns a Promise 115 | */ 116 | getAnnouncements(parameters, callback) { 117 | return this.whmcsHttpClient.callApi('GetAnnouncements', parameters, callback); 118 | }; 119 | 120 | /** 121 | * Merge tickets. 122 | * https://developers.whmcs.com/api-reference/mergeticket/ 123 | * @param {Object} parameters Request parameters 124 | * @param {Function} callback Optional callback. If not set the method returns a Promise 125 | */ 126 | mergeTicket(parameters, callback) { 127 | return this.whmcsHttpClient.callApi('MergeTicket', parameters, callback); 128 | }; 129 | 130 | /** 131 | * Open a new ticket. 132 | * https://developers.whmcs.com/api-reference/openticket/ 133 | * @param {Object} parameters Request parameters 134 | * @param {Function} callback Optional callback. If not set the method returns a Promise 135 | */ 136 | openTicket(parameters, callback) { 137 | return this.whmcsHttpClient.callApi('OpenTicket', parameters, callback); 138 | }; 139 | 140 | /** 141 | * Updates an existing ticket. 142 | * https://developers.whmcs.com/api-reference/updateticket/ 143 | * @param {Object} parameters Request parameters 144 | * @param {Function} callback Optional callback. If not set the method returns a Promise 145 | */ 146 | updateTicket(parameters, callback) { 147 | return this.whmcsHttpClient.callApi('UpdateTicket', parameters, callback); 148 | }; 149 | 150 | /** 151 | * Updates a ticket reply message. 152 | * https://developers.whmcs.com/api-reference/updateticketreply/ 153 | * @param {Object} parameters Request parameters 154 | * @param {Function} callback Optional callback. If not set the method returns a Promise 155 | */ 156 | updateTicketReply(parameters, callback) { 157 | return this.whmcsHttpClient.callApi('UpdateTicketReply', parameters, callback); 158 | }; 159 | } 160 | 161 | module.exports = Support; 162 | -------------------------------------------------------------------------------- /modules/system.js: -------------------------------------------------------------------------------- 1 | class System { 2 | /** 3 | * Creates a new System object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Adds an IP to the ban list. 12 | * https://developers.whmcs.com/api-reference/addbannedip/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | addBannedIp(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AddBannedIp', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Decrypt an encrypted string. 22 | * https://developers.whmcs.com/api-reference/decryptpassword/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | decryptPassword(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('DecryptPassword', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Encrypt a string. 32 | * https://developers.whmcs.com/api-reference/encryptpassword/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | encryptPassword(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('EncryptPassword', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Obtain the Activity Log that matches passed criteria. 42 | * https://developers.whmcs.com/api-reference/getactivitylog/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | getActivityLog(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('GetActivityLog', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Obtain the details for the current Admin User. 52 | * https://developers.whmcs.com/api-reference/getadmindetails/ 53 | * @param {Function} callback Optional callback. If not set the method returns a Promise 54 | */ 55 | getAdminDetails(callback) { 56 | return this.whmcsHttpClient.callApi('GetAdminDetails', callback); 57 | }; 58 | 59 | /** 60 | * Retrieve a list of administrator user accounts. 61 | * https://developers.whmcs.com/api-reference/getadminusers/ 62 | * @param {Object} parameters Request parameters 63 | * @param {Function} callback Optional callback. If not set the method returns a Promise 64 | */ 65 | getAdminUsers(parameters, callback) { 66 | return this.whmcsHttpClient.callApi('GetAdminUsers', parameters, callback); 67 | }; 68 | 69 | /** 70 | * Get Automation Task Log. 71 | * https://developers.whmcs.com/api-reference/getautomationlog/ 72 | * @param {Object} parameters Request parameters 73 | * @param {Function} callback Optional callback. If not set the method returns a Promise 74 | */ 75 | getAutomationLog(parameters, callback) { 76 | return this.whmcsHttpClient.callApi('GetAutomationLog', parameters, callback); 77 | }; 78 | 79 | /** 80 | * Retrieve a System Configuration Value. 81 | * https://developers.whmcs.com/api-reference/getconfigurationvalue/ 82 | * @param {Object} parameters Request parameters 83 | * @param {Function} callback Optional callback. If not set the method returns a Promise 84 | */ 85 | getConfigurationValue(parameters, callback) { 86 | return this.whmcsHttpClient.callApi('GetConfigurationValue', parameters, callback); 87 | }; 88 | 89 | /** 90 | * Obtain the Currencies configured in the System. 91 | * https://developers.whmcs.com/api-reference/getcurrencies/ 92 | * @param {Function} callback Optional callback. If not set the method returns a Promise 93 | */ 94 | getCurrencies(callback) { 95 | return this.whmcsHttpClient.callApi('GetCurrencies', callback); 96 | }; 97 | 98 | /** 99 | * Obtain a list of email templates from the system. 100 | * https://developers.whmcs.com/api-reference/getemailtemplates/ 101 | * @param {Object} parameters Request parameters 102 | * @param {Function} callback Optional callback. If not set the method returns a Promise 103 | */ 104 | getEmailTemplates(parameters, callback) { 105 | return this.whmcsHttpClient.callApi('GetEmailTemplates', parameters, callback); 106 | }; 107 | 108 | /** 109 | * Retrieve Activated Payment Methods. 110 | * https://developers.whmcs.com/api-reference/getpaymentmethods/ 111 | * @param {Function} callback Optional callback. If not set the method returns a Promise 112 | */ 113 | getPaymentMethods(callback) { 114 | return this.whmcsHttpClient.callApi('GetPaymentMethods', callback); 115 | }; 116 | 117 | /** 118 | * Retrieve a list of currently logged in admin users. 119 | * https://developers.whmcs.com/api-reference/getstaffonline/ 120 | * @param {Function} callback Optional callback. If not set the method returns a Promise 121 | */ 122 | getStaffOnline(callback) { 123 | return this.whmcsHttpClient.callApi('GetStaffOnline', callback); 124 | }; 125 | 126 | /** 127 | * Get business performance metrics and statistics. 128 | * https://developers.whmcs.com/api-reference/getstats/ 129 | * @param {Object} parameters Request parameters 130 | * @param {Function} callback Optional callback. If not set the method returns a Promise 131 | */ 132 | getStats(parameters, callback) { 133 | return this.whmcsHttpClient.callApi('GetStats', parameters, callback); 134 | }; 135 | 136 | /** 137 | * Get To-Do List Items. 138 | * https://developers.whmcs.com/api-reference/gettodoitems/ 139 | * @param {Object} parameters Request parameters 140 | * @param {Function} callback Optional callback. If not set the method returns a Promise 141 | */ 142 | getToDoItems(parameters, callback) { 143 | return this.whmcsHttpClient.callApi('GetToDoItems', parameters, callback); 144 | }; 145 | 146 | /** 147 | * Obtain To Do item statuses and counts. 148 | * https://developers.whmcs.com/api-reference/gettodoitemstatuses/ 149 | * @param {Function} callback Optional callback. If not set the method returns a Promise 150 | */ 151 | getToDoItemStatuses(callback) { 152 | return this.whmcsHttpClient.callApi('GetToDoItemStatuses', callback); 153 | }; 154 | 155 | /** 156 | * Creates an activity log entry. 157 | * https://developers.whmcs.com/api-reference/logactivity/ 158 | * @param {Object} parameters Request parameters 159 | * @param {Function} callback Optional callback. If not set the method returns a Promise 160 | */ 161 | logActivity(parameters, callback) { 162 | return this.whmcsHttpClient.callApi('LogActivity', parameters, callback); 163 | }; 164 | 165 | /** 166 | * Send an Admin Email Notification. 167 | * https://developers.whmcs.com/api-reference/sendadminemail/ 168 | * @param {Object} parameters Request parameters 169 | * @param {Function} callback Optional callback. If not set the method returns a Promise 170 | */ 171 | sendAdminEmail(parameters, callback) { 172 | return this.whmcsHttpClient.callApi('SendAdminEmail', parameters, callback); 173 | }; 174 | 175 | /** 176 | * Send a client Email Notification. 177 | * https://developers.whmcs.com/api-reference/sendemail/ 178 | * @param {Object} parameters Request parameters 179 | * @param {Function} callback Optional callback. If not set the method returns a Promise 180 | */ 181 | sendEmail(parameters, callback) { 182 | return this.whmcsHttpClient.callApi('SendEmail', parameters, callback); 183 | }; 184 | 185 | /** 186 | * Set a System Configuration Value via the local API only. 187 | * https://developers.whmcs.com/api-reference/setconfigurationvalue/ 188 | * @param {Object} parameters Request parameters 189 | * @param {Function} callback Optional callback. If not set the method returns a Promise 190 | */ 191 | setConfigurationValue(parameters, callback) { 192 | return this.whmcsHttpClient.callApi('SetConfigurationValue', parameters, callback); 193 | }; 194 | 195 | /** 196 | * Trigger a Custom Notification Event. 197 | * https://developers.whmcs.com/api-reference/triggernotificationevent/ 198 | * @param {Object} parameters Request parameters 199 | * @param {Function} callback Optional callback. If not set the method returns a Promise 200 | */ 201 | triggerNotificationEvent(parameters, callback) { 202 | return this.whmcsHttpClient.callApi('TriggerNotificationEvent', parameters, callback); 203 | }; 204 | 205 | /** 206 | * Update the admin notes. 207 | * https://developers.whmcs.com/api-reference/updateadminnotes/ 208 | * @param {Object} parameters Request parameters 209 | * @param {Function} callback Optional callback. If not set the method returns a Promise 210 | */ 211 | updateAdminNotes(parameters, callback) { 212 | return this.whmcsHttpClient.callApi('UpdateAdminNotes', parameters, callback); 213 | }; 214 | 215 | /** 216 | * Update a specific announcement. 217 | * https://developers.whmcs.com/api-reference/updateannouncement/ 218 | * @param {Object} parameters Request parameters 219 | * @param {Function} callback Optional callback. If not set the method returns a Promise 220 | */ 221 | updateAnnouncement(parameters, callback) { 222 | return this.whmcsHttpClient.callApi('UpdateAnnouncement', parameters, callback); 223 | }; 224 | 225 | /** 226 | * Update To-Do Item. 227 | * https://developers.whmcs.com/api-reference/updatetodoitem/ 228 | * @param {Object} parameters Request parameters 229 | * @param {Function} callback Optional callback. If not set the method returns a Promise 230 | */ 231 | updateToDoItem(parameters, callback) { 232 | return this.whmcsHttpClient.callApi('UpdateToDoItem', parameters, callback); 233 | }; 234 | 235 | /** 236 | * Obtain details pertaining to the current WHMCS installation. 237 | * https://developers.whmcs.com/api-reference/whmcsdetails/ 238 | * @param {Function} callback Optional callback. If not set the method returns a Promise 239 | */ 240 | whmcsDetails(callback) { 241 | return this.whmcsHttpClient.callApi('WhmcsDetails', callback); 242 | }; 243 | } 244 | 245 | module.exports = System; -------------------------------------------------------------------------------- /modules/tickets.js: -------------------------------------------------------------------------------- 1 | class Tickets { 2 | /** 3 | * Creates a new Tickets object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Get the support departments and associated ticket counts. 12 | * https://developers.whmcs.com/api-reference/getsupportdepartments/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | getSupportDepartments(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('GetSupportDepartments', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Get the support statuses and number of tickets in each status. 22 | * https://developers.whmcs.com/api-reference/getsupportstatuses/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | getSupportStatuses(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('GetSupportStatuses', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Obtain a specific ticket 32 | * https://developers.whmcs.com/api-reference/getticket/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | getTicket(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('GetTicket', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Retrieve a single attachment. 42 | * https://developers.whmcs.com/api-reference/getticketattachment/ 43 | * @param {Object} parameters Request parameters 44 | * @param {Function} callback Optional callback. If not set the method returns a Promise 45 | */ 46 | getTicketAttachment(parameters, callback) { 47 | return this.whmcsHttpClient.callApi('GetTicketAttachment', parameters, callback); 48 | }; 49 | 50 | /** 51 | * Get ticket counts. 52 | * https://developers.whmcs.com/api-reference/getticketcounts/ 53 | * @param {Object} parameters Request parameters 54 | * @param {Function} callback Optional callback. If not set the method returns a Promise 55 | */ 56 | getTicketCounts(parameters, callback) { 57 | return this.whmcsHttpClient.callApi('GetTicketCounts', parameters, callback); 58 | }; 59 | 60 | /** 61 | * Obtain a specific ticket notes. 62 | * https://developers.whmcs.com/api-reference/getticketnotes/ 63 | * @param {Object} parameters Request parameters 64 | * @param {Function} callback Optional callback. If not set the method returns a Promise 65 | */ 66 | getTicketNotes(parameters, callback) { 67 | return this.whmcsHttpClient.callApi('GetTicketNotes', parameters, callback); 68 | }; 69 | 70 | /** 71 | * Obtain the Predefined Ticket Reply Categories. 72 | * https://developers.whmcs.com/api-reference/getticketpredefinedcats/ 73 | * @param {Function} callback Optional callback. If not set the method returns a Promise 74 | */ 75 | getTicketPredefinedCats(callback) { 76 | return this.whmcsHttpClient.callApi('GetTicketPredefinedCats', callback); 77 | }; 78 | 79 | /** 80 | * Obtain the Predefined Ticket Replies. 81 | * https://developers.whmcs.com/api-reference/getticketpredefinedreplies/ 82 | * @param {Object} parameters Request parameters 83 | * @param {Function} callback Optional callback. If not set the method returns a Promise 84 | */ 85 | getTicketPredefinedReplies(parameters, callback) { 86 | return this.whmcsHttpClient.callApi('GetTicketPredefinedReplies', parameters, callback); 87 | }; 88 | 89 | /** 90 | * Obtain tickets matching the passed criteria. 91 | * https://developers.whmcs.com/api-reference/gettickets/ 92 | * @param {Object} parameters Request parameters 93 | * @param {Function} callback Optional callback. If not set the method returns a Promise 94 | */ 95 | getTickets(parameters, callback) { 96 | return this.whmcsHttpClient.callApi('GetTickets', parameters, callback); 97 | }; 98 | } 99 | 100 | module.exports = Tickets; 101 | -------------------------------------------------------------------------------- /modules/users.js: -------------------------------------------------------------------------------- 1 | class Users { 2 | /** 3 | * Creates a new Users object 4 | * @param {WhmcsHttpClient} whmcsHttpClient 5 | */ 6 | constructor(whmcsHttpClient) { 7 | this.whmcsHttpClient = whmcsHttpClient; 8 | } 9 | 10 | /** 11 | * Add a user. 12 | * https://developers.whmcs.com/api-reference/adduser/ 13 | * @param {Object} parameters Request parameters 14 | * @param {Function} callback Optional callback. If not set the method returns a Promise 15 | */ 16 | addUser(parameters, callback) { 17 | return this.whmcsHttpClient.callApi('AddUser', parameters, callback); 18 | }; 19 | 20 | /** 21 | * Send an invite to manage a client. 22 | * https://developers.whmcs.com/api-reference/createclientinvite/ 23 | * @param {Object} parameters Request parameters 24 | * @param {Function} callback Optional callback. If not set the method returns a Promise 25 | */ 26 | createClientInvite(parameters, callback) { 27 | return this.whmcsHttpClient.callApi('CreateClientInvite', parameters, callback); 28 | }; 29 | 30 | /** 31 | * Delete relationship between user and client. 32 | * https://developers.whmcs.com/api-reference/deleteuserclient/ 33 | * @param {Object} parameters Request parameters 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise 35 | */ 36 | deleteUserClient(parameters, callback) { 37 | return this.whmcsHttpClient.callApi('DeleteUserClient', parameters, callback); 38 | }; 39 | 40 | /** 41 | * Retrieve a list of permissions that can be used when creating a user. 42 | * https://developers.whmcs.com/api-reference/getpermissionslist/ 43 | * @param {Function} callback Optional callback. If not set the method returns a Promise 44 | */ 45 | getPermissionsList(callback) { 46 | return this.whmcsHttpClient.callApi('GetPermissionsList', callback); 47 | }; 48 | 49 | /** 50 | * Provide the permissions of a user for a client. 51 | * https://developers.whmcs.com/api-reference/getuserpermissions/ 52 | * @param {Object} parameters Request parameters 53 | * @param {Function} callback Optional callback. If not set the method returns a Promise 54 | */ 55 | getUserPermissions(parameters, callback) { 56 | return this.whmcsHttpClient.callApi('GetUserPermissions', parameters, callback); 57 | }; 58 | 59 | /** 60 | * Obtain the Users that match passed criteria. 61 | * https://developers.whmcs.com/api-reference/getusers/ 62 | * @param {Object} parameters Request parameters 63 | * @param {Function} callback Optional callback. If not set the method returns a Promise 64 | */ 65 | getUsers(parameters, callback) { 66 | return this.whmcsHttpClient.callApi('GetUsers', parameters, callback); 67 | }; 68 | 69 | /** 70 | * Starts the password reset process for a user. 71 | * https://developers.whmcs.com/api-reference/resetpassword/ 72 | * @param {Object} parameters Request parameters 73 | * @param {Function} callback Optional callback. If not set the method returns a Promise 74 | */ 75 | resetPassword(parameters, callback) { 76 | return this.whmcsHttpClient.callApi('ResetPassword', parameters, callback); 77 | }; 78 | 79 | /** 80 | * Update a user. 81 | * https://developers.whmcs.com/api-reference/updateuser/ 82 | * @param {Object} parameters Request parameters 83 | * @param {Function} callback Optional callback. If not set the method returns a Promise 84 | */ 85 | updateUser(parameters, callback) { 86 | return this.whmcsHttpClient.callApi('UpdateUser', parameters, callback); 87 | }; 88 | 89 | /** 90 | * Update the permissions of a user for a client. 91 | * https://developers.whmcs.com/api-reference/updateuserpermissions/ 92 | * @param {Object} parameters Request parameters 93 | * @param {Function} callback Optional callback. If not set the method returns a Promise 94 | */ 95 | updateUserPermissions(parameters, callback) { 96 | return this.whmcsHttpClient.callApi('UpdateUserPermissions', parameters, callback); 97 | }; 98 | } 99 | 100 | module.exports = Users; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "whmcs", 3 | "description": "WHMCS API client.", 4 | "version": "1.2.2", 5 | "author": "Pedro Dias ", 6 | "maintainers": [ 7 | "apocas " 8 | ], 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/apocas/node-whmcs.git" 12 | }, 13 | "keywords": [ 14 | "whmcs", 15 | "hosting" 16 | ], 17 | "dependencies": { 18 | "axios": "^0.21.4", 19 | "bluebird": "^3.7.2", 20 | "https-proxy-agent": "^5.0.0", 21 | "xml2js": "0.4.x" 22 | }, 23 | "devDependencies": { 24 | "chai": "~4.2.0", 25 | "mocha": "^7.1.0" 26 | }, 27 | "scripts": { 28 | "test": "mocha --timeout 10000" 29 | }, 30 | "main": "./whmcs", 31 | "engines": { 32 | "node": ">= 12.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/addons.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Addons"', function () { 6 | 7 | it('should update client addon', async function () { 8 | let opts = { 9 | id: 1 10 | }; 11 | 12 | try { 13 | let res = await conf.whmcs.addons.updateClientAddon(opts); 14 | expect(res).to.have.a.property('result').to.equal('success'); 15 | } catch (e) { 16 | if (e instanceof WhmcsError) { 17 | const possibleErr = ['Addon ID Not Found', 'Nothing to Update']; 18 | expect(possibleErr.indexOf(e.message) > -1).to.be.true; 19 | } else { 20 | throw e; 21 | } 22 | } 23 | }); 24 | 25 | }); -------------------------------------------------------------------------------- /test/affiliates.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Affiliates"', function () { 6 | 7 | it('should get referrals', async function () { 8 | const opts = { 9 | limitstart: 0, 10 | limitnum: 25 11 | }; 12 | const res = await conf.whmcs.affiliates.getAffiliates(opts); 13 | expect(res).to.have.a.property('result').to.equal('success'); 14 | expect(res).to.have.a.property('numreturned').to.not.be.null; 15 | if (parseInt(res.numreturned) > 0) { 16 | expect(res).to.have.a.property('affiliates').to.be.an('object').to.have.a.property('affiliate').to.be.an('array').to.have.length.greaterThan(0); 17 | } 18 | }); 19 | 20 | it('should activate and get referrals by client id', async function () { 21 | const activateOpts = { 22 | userid: conf.demoClientId 23 | }; 24 | const activateRes = await conf.whmcs.affiliates.affiliateActivate(activateOpts); 25 | expect(activateRes).to.have.a.property('result').to.equal('success'); 26 | 27 | const getOpts = { 28 | userid: conf.demoClientId 29 | }; 30 | const getRes = await conf.whmcs.affiliates.getAffiliates(getOpts); 31 | expect(getRes).to.have.a.property('result').to.equal('success'); 32 | expect(getRes).to.have.a.property('affiliates').to.be.an('object'); 33 | expect(getRes.affiliates).to.have.a.property('affiliate').to.be.an('array'); 34 | const a = getRes.affiliates.affiliate.map(function (affiliate) { 35 | return affiliate.clientid; 36 | }); 37 | expect(a).includes(conf.demoClientId.toString()); 38 | }); 39 | 40 | }); -------------------------------------------------------------------------------- /test/authentication.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Authentication"', function () { 6 | 7 | it('should validate user login credential', async function () { 8 | const opts = { 9 | email: conf.demoUserDetails.email, 10 | password2: conf.demoUserDetails.password2 11 | }; 12 | const res = await conf.whmcs.authentication.validateLogin(opts);; 13 | expect(res).to.have.a.property('result').to.equal('success'); 14 | }); 15 | 16 | it('should create, update, get and delete an OAuth credential', async function () { 17 | this.timeout(30000); 18 | 19 | const createOpts = { 20 | email: conf.demoUserDetails.email, 21 | grantType: 'authorization_code', 22 | scope: 'clientarea:sso', 23 | name: 'oauthtest' 24 | }; 25 | 26 | const createRes = await conf.whmcs.authentication.createOAuthCredential(createOpts);; 27 | expect(createRes).to.have.a.property('result').to.equal('success'); 28 | expect(createRes).to.have.a.property('credentialId').to.not.be.null; 29 | const credentialId = createRes.credentialId; 30 | 31 | const updateOpts = { 32 | credentialId: credentialId, 33 | scope: 'clientarea:billing_info' 34 | }; 35 | const updateRes = await conf.whmcs.authentication.updateOAuthCredential(updateOpts);; 36 | expect(updateRes).to.have.a.property('result').to.equal('success'); 37 | 38 | const listRes = await conf.whmcs.authentication.listOAuthCredentials();; 39 | expect(listRes).to.have.a.property('result').to.equal('success'); 40 | expect(listRes).to.have.a.property('clients').to.be.an('array'); 41 | const c = listRes.clients.map(function (client) { 42 | return client.credentialId; 43 | }); 44 | expect(c).includes(credentialId); 45 | 46 | const deleteOpts = { 47 | credentialId: credentialId 48 | }; 49 | const deleteRes = await conf.whmcs.authentication.deleteOAuthCredential(deleteOpts);; 50 | expect(deleteRes).to.have.a.property('result').to.equal('success'); 51 | }); 52 | 53 | it('should create a SSO token', async function () { 54 | const opts = { 55 | client_id: conf.demoClientId 56 | }; 57 | const res = await conf.whmcs.authentication.createSsoToken(opts);; 58 | expect(res).to.have.a.property('result').to.equal('success'); 59 | }); 60 | }); -------------------------------------------------------------------------------- /test/billing.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Billing"', function () { 6 | 7 | describe('Quote', function () { 8 | let demoQuoteId; 9 | 10 | before(async function () { 11 | const opts = { 12 | subject: 'test quote', 13 | stage: 'Draft', 14 | validuntil: '01-01-2099', 15 | userid: conf.demoClientId 16 | }; 17 | 18 | const items = { 19 | 'lineitems[0]': { 20 | desc: 'quote description', 21 | qty: 1, 22 | up: 10, 23 | taxable: false 24 | } 25 | }; 26 | 27 | opts['lineitems'] = Buffer.from(conf.serialize(items), 'ascii').toString('base64'); 28 | 29 | const res = await conf.whmcs.billing.createQuote(opts); 30 | expect(res).to.have.a.property('result').to.equal('success'); 31 | expect(res).to.have.a.property('quoteid').to.not.be.null; 32 | demoQuoteId = res.quoteid; 33 | }); 34 | 35 | it('should get quotes', async function () { 36 | const opts = { 37 | limitstart: 0, 38 | limitnum: 1 39 | }; 40 | 41 | const res = await conf.whmcs.billing.getQuotes(opts); 42 | expect(res).to.have.a.property('result').to.equal('success'); 43 | expect(res).to.have.a.property('quotes').to.be.an('object'); 44 | expect(res.quotes).to.have.a.property('quote').to.be.an('array'); 45 | }); 46 | 47 | it('should create a quote', async function () { 48 | const opts = { 49 | subject: 'test quote', 50 | stage: 'Draft', 51 | validuntil: '01-01-2099', 52 | userid: conf.demoClientId 53 | }; 54 | 55 | const items = { 56 | 'lineitems[0]': { 57 | desc: 'quote description', 58 | qty: 1, 59 | up: 10, 60 | taxable: false 61 | } 62 | }; 63 | 64 | opts['lineitems'] = Buffer.from(conf.serialize(items), 'ascii').toString('base64'); 65 | 66 | const res = await conf.whmcs.billing.createQuote(opts); 67 | expect(res).to.have.a.property('result').to.equal('success'); 68 | expect(res).to.have.a.property('quoteid').to.not.be.null; 69 | }); 70 | 71 | it('should get a quote by id', async function () { 72 | const opts = { 73 | quoteid: demoQuoteId 74 | }; 75 | 76 | const res = await conf.whmcs.billing.getQuotes(opts); 77 | expect(res).to.have.a.property('result').to.equal('success'); 78 | expect(res).to.have.a.property('quotes').to.be.an('object'); 79 | expect(res.quotes).to.have.a.property('quote').to.be.an('array').to.have.lengthOf(1); 80 | }); 81 | 82 | it('should update a quote', async function () { 83 | const opts = { 84 | quoteid: demoQuoteId, 85 | subject: 'this is an updated quote' 86 | }; 87 | 88 | const res = await conf.whmcs.billing.updateQuote(opts); 89 | expect(res).to.have.a.property('result').to.equal('success'); 90 | }); 91 | 92 | it('should accept a quote', async function () { 93 | this.timeout(30000); 94 | const opts = { 95 | quoteid: demoQuoteId, 96 | }; 97 | 98 | const res = await conf.whmcs.billing.acceptQuote(opts); 99 | expect(res).to.have.a.property('result').to.equal('success'); 100 | expect(res).to.have.a.property('invoiceid').to.not.be.null; 101 | }); 102 | 103 | it('should send a quote', async function () { 104 | const opts = { 105 | quoteid: demoQuoteId, 106 | }; 107 | 108 | const res = await conf.whmcs.billing.sendQuote(opts); 109 | expect(res).to.have.a.property('result').to.equal('success'); 110 | }); 111 | 112 | it('should delete a quote', async function () { 113 | const opts = { 114 | quoteid: demoQuoteId, 115 | }; 116 | 117 | const res = await conf.whmcs.billing.deleteQuote(opts); 118 | expect(res).to.have.a.property('result').to.equal('success'); 119 | }); 120 | }); 121 | 122 | it('should add a billable item', async function () { 123 | const opts = { 124 | clientid: conf.demoClientId, 125 | description: 'this is a billable item', 126 | amount: '10.00', 127 | unit: 'quantity' 128 | }; 129 | 130 | const res = await conf.whmcs.billing.addBillableItem(opts); 131 | expect(res).to.have.a.property('result').to.equal('success'); 132 | expect(res).to.have.a.property('billableid').to.not.be.null; 133 | }); 134 | 135 | it('should create an invoice', async function () { 136 | this.timeout(30000); 137 | const opts = { 138 | userid: conf.demoClientId, 139 | itemdescription0: 'this is a test invoice', 140 | itemamount0: 1, 141 | autoapplycredit: false 142 | }; 143 | 144 | const res = await conf.whmcs.billing.createInvoice(opts); 145 | expect(res).to.have.a.property('result').to.equal('success'); 146 | expect(res).to.have.a.property('invoiceid').to.not.be.null; 147 | }); 148 | 149 | it('should get invoices', async function () { 150 | const opts = { 151 | limitstart: 0, 152 | limitnum: 1 153 | }; 154 | 155 | const res = await conf.whmcs.billing.getInvoices(opts); 156 | expect(res).to.have.a.property('result').to.equal('success'); 157 | expect(res).to.have.a.property('invoices').to.be.an('object'); 158 | expect(res.invoices).to.have.a.property('invoice').to.be.an('array'); 159 | }); 160 | 161 | describe('Invoice', function () { 162 | let demoInvoiceId; 163 | 164 | before(async function () { 165 | const opts = { 166 | userid: conf.demoClientId, 167 | itemdescription0: 'this is a test invoice', 168 | itemamount0: 1, 169 | autoapplycredit: false 170 | }; 171 | 172 | const res = await conf.whmcs.billing.createInvoice(opts); 173 | expect(res).to.have.a.property('result').to.equal('success'); 174 | expect(res).to.have.a.property('invoiceid').to.be.a('number'); 175 | demoInvoiceId = res.invoiceid; 176 | }); 177 | 178 | it('should update an invoice', async function () { 179 | const opts = { 180 | invoiceid: demoInvoiceId, 181 | 'itemdescription[0]': 'this is an updated invoice', 182 | 'itemamount[0]': 1, 183 | 'itemtaxed[0]': false 184 | }; 185 | 186 | const res = await conf.whmcs.billing.updateInvoice(opts); 187 | expect(res).to.have.a.property('result').to.equal('success'); 188 | expect(res).to.have.a.property('invoiceid').to.equal(demoInvoiceId); 189 | }); 190 | 191 | it('should get an invoice', async function () { 192 | const opts = { 193 | invoiceid: demoInvoiceId 194 | }; 195 | 196 | const res = await conf.whmcs.billing.getInvoice(opts); 197 | expect(res).to.have.a.property('result').to.equal('success'); 198 | expect(res).to.have.a.property('items').to.be.an('object'); 199 | expect(res.items).to.have.a.property('item').to.be.an('array').to.have.lengthOf(1); 200 | }); 201 | 202 | it('should add a payment to an invoice', async function () { 203 | const opts = { 204 | invoiceid: demoInvoiceId, 205 | transid: 1234, 206 | amount: 0.01, 207 | gateway: 'paypal' 208 | }; 209 | 210 | const res = await conf.whmcs.billing.addInvoicePayment(opts); 211 | expect(res).to.have.a.property('result').to.equal('success'); 212 | }); 213 | 214 | it('should apply credit to an invoice', async function () { 215 | const opts = { 216 | invoiceid: demoInvoiceId, 217 | amount: 0.01, 218 | noemail: true 219 | }; 220 | let res; 221 | 222 | try { 223 | res = await conf.whmcs.billing.applyCredit(opts); 224 | expect(res).to.have.a.property('result').to.equal('success'); 225 | expect(res).to.have.a.property('invoicepaid').to.not.be.null; 226 | } catch (e) { 227 | if (e instanceof WhmcsError) { 228 | const possibleErr = ['Amount exceeds customer credit balance']; 229 | expect(possibleErr.indexOf(e.message) > -1).to.be.true; 230 | } else { 231 | throw e; 232 | } 233 | } 234 | }); 235 | 236 | it('should capture payment on an unpaid invoice', async function () { 237 | const opts = { 238 | invoiceid: demoInvoiceId 239 | }; 240 | let res; 241 | 242 | try { 243 | res = await conf.whmcs.billing.capturePayment(opts); 244 | expect(res).to.have.a.property('result').to.equal('success'); 245 | } catch (e) { 246 | if (e instanceof WhmcsError) { 247 | const possibleErr = ['Payment Attempt Failed']; 248 | expect(possibleErr.indexOf(e.message) > -1).to.be.true; 249 | } else { 250 | throw e; 251 | } 252 | } 253 | }); 254 | }); 255 | 256 | describe('Pay Method', function () { 257 | let demoPaymentMethodId; 258 | 259 | before(async function () { 260 | const opts = { 261 | clientid: conf.demoClientId, 262 | type: 'BankAccount', 263 | bank_code: '123456789', 264 | bank_code: '1234', 265 | bank_account: '999999999' 266 | }; 267 | 268 | const res = await conf.whmcs.billing.addPayMethod(opts); 269 | expect(res).to.have.a.property('result').to.equal('success'); 270 | expect(res).to.have.a.property('paymethodid').to.not.be.null; 271 | demoPaymentMethodId = res.paymethodid; 272 | }); 273 | 274 | it('should add a pay method to given client', async function () { 275 | const opts = { 276 | clientid: conf.demoClientId, 277 | type: 'BankAccount', 278 | bank_code: '123456789', 279 | bank_code: '1234', 280 | bank_account: '999999999' 281 | }; 282 | 283 | const res = await conf.whmcs.billing.addPayMethod(opts); 284 | expect(res).to.have.a.property('result').to.equal('success'); 285 | expect(res).to.have.a.property('paymethodid').to.not.be.null; 286 | }); 287 | 288 | it('should get pay methods associated with client id', async function () { 289 | const opts = { 290 | clientid: conf.demoClientId, 291 | paymethodid: demoPaymentMethodId 292 | }; 293 | 294 | const res = await conf.whmcs.billing.getPayMethods(opts); 295 | expect(res).to.have.a.property('result').to.equal('success'); 296 | expect(res).to.have.a.property('paymethods').to.be.an('array').to.have.lengthOf(1); 297 | 298 | }); 299 | 300 | it('should update a pay method', async function () { 301 | const opts = { 302 | clientid: conf.demoClientId, 303 | paymethodid: demoPaymentMethodId 304 | }; 305 | 306 | const res = await conf.whmcs.billing.updatePayMethod(opts); 307 | expect(res).to.have.a.property('result').to.equal('success'); 308 | expect(res).to.have.a.property('paymethodid').to.not.be.null; 309 | 310 | }); 311 | 312 | it('should delete a pay method', async function () { 313 | const opts = { 314 | clientid: conf.demoClientId, 315 | paymethodid: demoPaymentMethodId 316 | }; 317 | 318 | const res = await conf.whmcs.billing.deletePayMethod(opts); 319 | expect(res).to.have.a.property('result').to.equal('success'); 320 | expect(res).to.have.a.property('paymethodid').to.not.be.null; 321 | }); 322 | }); 323 | 324 | it('should generate invoices that are due to be generated', async function () { 325 | this.timeout(30000); 326 | const opts = { 327 | clientid: conf.demoClientId 328 | }; 329 | const res = await conf.whmcs.billing.genInvoices(opts); 330 | expect(res).to.have.a.property('result').to.equal('success'); 331 | expect(res).to.have.a.property('numcreated').to.not.be.null; 332 | }); 333 | 334 | describe('Credit', function () { 335 | it('should add credit', async function () { 336 | const opts = { 337 | clientid: conf.demoClientId, 338 | description: 'this is a credit test', 339 | amount: 1 340 | }; 341 | 342 | const res = await conf.whmcs.billing.addCredit(opts); 343 | expect(res).to.have.a.property('result').to.equal('success'); 344 | expect(res).to.have.a.property('newbalance').to.not.be.null; 345 | }); 346 | 347 | it('should get credits', async function () { 348 | const opts = { 349 | clientid: conf.demoClientId 350 | }; 351 | 352 | const res = await conf.whmcs.billing.getCredits(opts); 353 | expect(res).to.have.a.property('result').to.equal('success'); 354 | expect(res).to.have.a.property('credits').to.be.an('object'); 355 | expect(res.credits).to.have.a.property('credit').to.be.an('array'); 356 | }); 357 | }); 358 | 359 | describe('Transaction', function () { 360 | it('should add, get and update a transaction', async function () { 361 | const addOpts = { 362 | paymentmethod: conf.demoPaymentMethod, 363 | userid: conf.demoClientId 364 | }; 365 | 366 | const addRes = await conf.whmcs.billing.addTransaction(addOpts); 367 | expect(addRes).to.have.a.property('result').to.equal('success'); 368 | 369 | const getOpts = { 370 | clientid: conf.demoClientId 371 | }; 372 | 373 | const getRes = await conf.whmcs.billing.getTransactions(getOpts); 374 | expect(getRes).to.have.a.property('result').to.equal('success'); 375 | expect(getRes).to.have.a.property('transactions').to.be.an('object'); 376 | expect(getRes.transactions).to.have.a.property('transaction').to.be.an('array').to.have.length.greaterThan(0); 377 | expect(getRes.transactions.transaction[0]).to.have.a.property('id').to.not.be.null; 378 | 379 | const updateOpts = { 380 | transactionid: getRes.transactions.transaction[0].id, 381 | description: 'this transaction has been updated' 382 | }; 383 | 384 | const updateRes = await conf.whmcs.billing.updateTransaction(updateOpts); 385 | expect(updateRes).to.have.a.property('result').to.equal('success'); 386 | expect(updateRes).to.have.a.property('transactionid').to.equal(getRes.transactions.transaction[0].id); 387 | }); 388 | }); 389 | 390 | }); -------------------------------------------------------------------------------- /test/client.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Client"', function () { 6 | 7 | it('should create a client, create a contact, close the client and then delete both of them', async function () { 8 | this.timeout(30000); 9 | const clientOpts = { 10 | firstname: 'Major', 11 | lastname: 'Tom', 12 | email: 'majortom@john.doe', 13 | address1: 'Mars', 14 | city: 'Phobos', 15 | state: 'Crater', 16 | postcode: '9999-999', 17 | country: 'US', 18 | phonenumber: '10987654321', 19 | password2: 'liftoff' 20 | }; 21 | 22 | const clientRes = await conf.whmcs.client.addClient(clientOpts); 23 | expect(clientRes).to.have.a.property('result').to.equal('success'); 24 | expect(clientRes).to.have.a.property('owner_id').to.not.be.null; 25 | expect(clientRes).to.have.a.property('clientid').to.not.be.null; 26 | 27 | const clientId = clientRes.clientid; 28 | 29 | const contactOpts = { 30 | clientid: clientId, 31 | firstname: 'Ground', 32 | lastname: 'Control', 33 | email: 'groundcontrol@john.doe', 34 | address1: 'Earth', 35 | city: 'Phobos', 36 | state: 'Crater', 37 | postcode: '9999-999', 38 | country: 'US', 39 | phonenumber: '911911911' 40 | } 41 | const contactRes = await conf.whmcs.client.addContact(contactOpts); 42 | expect(contactRes).to.have.a.property('result').to.equal('success'); 43 | expect(contactRes).to.have.a.property('contactid').to.not.be.null; 44 | 45 | const contactId = contactRes.contactid; 46 | 47 | const delContactOpts = { 48 | contactid: contactId 49 | } 50 | const delContactRes = await conf.whmcs.client.deleteContact(delContactOpts); 51 | expect(delContactRes).to.have.a.property('result').to.equal('success'); 52 | 53 | const closeOpts = { 54 | clientid: clientId 55 | } 56 | const closeRes = await conf.whmcs.client.closeClient(closeOpts); 57 | expect(closeRes).to.have.a.property('result').to.equal('success'); 58 | 59 | const delClientOpts = { 60 | clientid: clientId, 61 | deleteusers: true, 62 | deletetransactions: true 63 | } 64 | const delClientRes = await conf.whmcs.client.deleteClient(delClientOpts); 65 | expect(delClientRes).to.have.a.property('result').to.equal('success'); 66 | }); 67 | 68 | it('should get cancellation requests', async function () { 69 | const opts = { 70 | limitstart: 0, 71 | limitnum: 25 72 | }; 73 | const res = await conf.whmcs.client.getCancelledPackages(opts); 74 | expect(res).to.have.a.property('result').to.equal('success'); 75 | expect(res).to.have.a.property('numreturned').to.not.be.null; 76 | if (parseInt(res.numreturned) > 0) { 77 | expect(res).to.have.a.property('packages').to.be.an('object'); 78 | expect(res.packages).to.have.a.property('package').to.be.an('array').to.have.length.greaterThan(0); 79 | } 80 | }); 81 | 82 | it('should get client groups', async function () { 83 | const res = await conf.whmcs.client.getClientGroups(); 84 | expect(res).to.have.a.property('result').to.equal('success'); 85 | expect(res).to.have.a.property('totalresults').to.not.be.null; 86 | if (parseInt(res.totalresults) > 0) { 87 | expect(res).to.have.a.property('groups').to.be.an.an('object'); 88 | expect(res.groups).to.have.a.property('group'); 89 | expect(res.groups.group).to.be.an('array').to.have.length.greaterThan(0); 90 | } 91 | }); 92 | 93 | it('should get the encrypted password, by user id', async function () { 94 | const opts = { 95 | userid: conf.demoClientId 96 | }; 97 | const res = await conf.whmcs.client.getClientPassword(opts); 98 | expect(res).to.have.a.property('result').to.equal('success'); 99 | expect(res).to.have.a.property('password').to.be.a('string'); 100 | }); 101 | 102 | it('should get the encrypted password, by user email address', async function () { 103 | const opts = { 104 | email: conf.demoUserDetails.email 105 | }; 106 | const res = await conf.whmcs.client.getClientPassword(opts); 107 | expect(res).to.have.a.property('result').to.equal('success'); 108 | }); 109 | 110 | it('should get clients by email', async function () { 111 | const opts = { 112 | search: conf.demoUserDetails.email 113 | }; 114 | const res = await conf.whmcs.client.getClients(opts); 115 | expect(res).to.have.a.property('result').to.equal('success'); 116 | expect(res).to.have.a.property('numreturned').to.equal(1); 117 | expect(res).to.have.a.property('clients').to.be.an.an('object'); 118 | expect(res.clients).to.have.a.property('client'); 119 | expect(res.clients.client).to.be.an('array').to.have.lengthOf(1); 120 | }); 121 | 122 | it('should get client addons', async function () { 123 | const opts = { 124 | clientid: conf.demoClientId 125 | }; 126 | const res = await conf.whmcs.client.getClientsAddons(opts); 127 | expect(res).to.have.a.property('result').to.equal('success'); 128 | expect(res).to.have.a.property('totalresults').to.not.be.null; 129 | if (parseInt(res.totalresults) > 0) { 130 | expect(res.gteBody()).to.have.a.property('addons').to.be.an('object'); 131 | expect(res.addons).to.have.a.property('addon').to.be.an('array').to.have.length.greaterThan(0); 132 | } 133 | }); 134 | 135 | it('should get client details by id', async function () { 136 | const opts = { 137 | clientid: conf.demoClientId 138 | }; 139 | const res = await conf.whmcs.client.getClientsDetails(opts); 140 | expect(res).to.have.a.property('result').to.equal('success'); 141 | expect(res).to.have.a.property('client').to.be.an.an('object'); 142 | }); 143 | 144 | it('should get client domains by client id', async function () { 145 | const opts = { 146 | clientid: conf.demoClientId 147 | }; 148 | const res = await conf.whmcs.client.getClientsDomains(opts); 149 | expect(res).to.have.a.property('result').to.equal('success'); 150 | expect(res).to.have.a.property('totalresults').to.not.be.null; 151 | if (parseInt(res.totalresults) > 0) { 152 | expect(res).to.have.a.property('domains').to.be.an.an('object'); 153 | expect(res.domains).to.have.a.property('domain'); 154 | expect(res.domains.domain).to.be.an('array').to.have.length.greaterThan(0); 155 | } 156 | }); 157 | 158 | it('should get clients products by client id', async function () { 159 | const opts = { 160 | clientid: conf.demoClientId 161 | }; 162 | const res = await conf.whmcs.client.getClientsProducts(opts); 163 | expect(res).to.have.a.property('result').to.equal('success'); 164 | expect(res).to.have.a.property('totalresults').to.not.be.null; 165 | if (parseInt(res.totalresults) > 0) { 166 | expect(res).to.have.a.property('products').to.be.an.an('object'); 167 | expect(res.products).to.have.a.property('product'); 168 | expect(res.products.product).to.be.an('array').to.have.length.greaterThan(0); 169 | } 170 | }); 171 | 172 | it('should get clients contacts by client id', async function () { 173 | const opts = { 174 | userid: conf.demoClientId 175 | }; 176 | const res = await conf.whmcs.client.getContacts(opts); 177 | expect(res).to.have.a.property('result').to.equal('success'); 178 | expect(res).to.have.a.property('numreturned').to.not.be.null; 179 | if (parseInt(res.numreturned) > 0) { 180 | expect(res).to.have.a.property('contacts').to.be.an.an('object'); 181 | expect(res.contacts).to.have.a.property('contact'); 182 | expect(res.contacts.contact).to.be.an('array').to.have.length.greaterThan(0); 183 | } 184 | }); 185 | 186 | it('should get clients emails', async function () { 187 | const opts = { 188 | clientid: conf.demoClientId 189 | }; 190 | const res = await conf.whmcs.client.getEmails(opts); 191 | expect(res).to.have.a.property('result').to.equal('success'); 192 | expect(res).to.have.a.property('numreturned').to.not.be.null; 193 | if (parseInt(res.numreturned) > 0) { 194 | expect(res).to.have.a.property('emails').to.be.an.an('object'); 195 | expect(res.emails).to.have.a.property('email'); 196 | expect(res.emails.email).to.be.an('array').to.have.length.greaterThan(0); 197 | } 198 | }); 199 | 200 | it('should update client by clientid', async function () { 201 | const updateOpts = { 202 | clientid: conf.demoClientId, 203 | lastname: 'updated1' 204 | }; 205 | const updateRes = await conf.whmcs.client.updateClient(updateOpts); 206 | expect(updateRes).to.have.a.property('result').to.equal('success'); 207 | expect(updateRes).to.have.a.property('clientid').to.equal(conf.demoClientId.toString()); 208 | }); 209 | 210 | it('should update contact by contact id', async function () { 211 | const updateOpts = { 212 | contactid: conf.demoContactId, 213 | lastname: 'newlastname' 214 | }; 215 | const updateRes = await conf.whmcs.client.updateContact(updateOpts); 216 | expect(updateRes).to.have.a.property('result').to.equal('success'); 217 | expect(updateRes).to.have.a.property('contactid').to.equal(conf.demoContactId.toString()); 218 | }); 219 | 220 | }); -------------------------------------------------------------------------------- /test/conf.js: -------------------------------------------------------------------------------- 1 | const WHMCS = require('../whmcs'), 2 | expect = require('chai').expect, 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | const config = { 6 | apiIdentifier: process.env.WHMCS_API_IDENTIFIER || 'apiIdentifier', 7 | apiSecret: process.env.WHMCS_API_SECRET || 'apiSecret', 8 | serverUrl: process.env.WHMCS_URL || 'http://192.168.1.1', 9 | userAgent: process.env.WHMCS_USERAGENT || 'node-whmcs', 10 | accessKey: process.env.WHMCS_AK 11 | }; 12 | 13 | const whmcs = new WHMCS(config); 14 | 15 | const userDetails = { 16 | firstname: 'John', 17 | lastname: 'Doe', 18 | email: 'johndoe@john.doe', 19 | address1: 'Mars', 20 | city: 'Phobos', 21 | state: 'Crater', 22 | postcode: '9999-999', 23 | country: 'US', 24 | phonenumber: '123456789', 25 | password2: '123qwe' 26 | }; 27 | 28 | const contactDetails = { 29 | firstname: 'Ground', 30 | lastname: 'Control', 31 | email: 'groundcontrol@john.doe', 32 | address1: 'Earth', 33 | city: 'Phobos', 34 | state: 'Crater', 35 | postcode: '9999-999', 36 | country: 'US', 37 | phonenumber: '911911911' 38 | } 39 | 40 | async function addClient() { 41 | const clientRes = await whmcs.client.addClient(userDetails); 42 | expect(clientRes).to.have.a.property('result').to.equal('success'); 43 | expect(clientRes).to.have.a.property('owner_id').to.not.be.null; 44 | expect(clientRes).to.have.a.property('clientid').to.not.be.null; 45 | 46 | module.exports.demoUserId = clientRes.owner_id; 47 | module.exports.demoClientId = clientRes.clientid; 48 | 49 | contactDetails.clientid = clientRes.clientid; 50 | return clientRes; 51 | } 52 | 53 | async function addContact() { 54 | let contactRes; 55 | 56 | contactRes = await whmcs.client.addContact(contactDetails) 57 | expect(contactRes).to.have.a.property('result').to.equal('success'); 58 | expect(contactRes).to.have.a.property('contactid').to.not.be.null; 59 | 60 | module.exports.demoContactId = contactRes.contactid; 61 | return contactRes; 62 | } 63 | 64 | async function addProduct() { 65 | const productOpts = { 66 | name: 'Test product', 67 | gid: process.env.WHMCS_TEST_GID || '1', 68 | type: 'hostingaccount' 69 | }; 70 | 71 | let productRes; 72 | 73 | try { 74 | productRes = await whmcs.products.addProduct(productOpts); 75 | expect(productRes).to.have.a.property('result').to.equal('success'); 76 | expect(productRes).to.have.a.property('pid').to.not.be.null; 77 | } catch (e) { 78 | if (e.message.indexOf('You must supply a valid Product Group ID') > -1) { 79 | throw new Error('There is no Product Group #' + productOpts.gid + '. You must create a Product Group in WHMCS and set the environment variable "WHMCS_TEST_GID" in order to proceed with the tests.'); 80 | } else { 81 | throw e; 82 | } 83 | } 84 | 85 | module.exports.demoProductId = productRes.pid; 86 | return productRes; 87 | } 88 | 89 | async function getPaymentMethod() { 90 | let methodsRes; 91 | 92 | methodsRes = await whmcs.system.getPaymentMethods(); 93 | expect(methodsRes).to.have.a.property('result').to.equal('success'); 94 | expect(methodsRes).to.have.a.property('totalresults').to.not.be.null; 95 | if (methodsRes.totalresults == 0) { 96 | throw new Error('Payment methods not found. You must create a new payment method first in order to proceed with the tests.'); 97 | } 98 | expect(methodsRes).to.have.a.property('paymentmethods').to.be.an('object').to.have.a.property('paymentmethod').to.be.an('array').to.have.length.greaterThan(0); 99 | expect(methodsRes.paymentmethods.paymentmethod[0]).to.have.a.property('module').to.be.a('string'); 100 | module.exports.demoPaymentMethod = methodsRes.paymentmethods.paymentmethod[0].module; 101 | return methodsRes; 102 | } 103 | 104 | async function createOrder() { 105 | const orderOpts = { 106 | clientid: module.exports.demoClientId, 107 | paymentmethod: module.exports.demoPaymentMethod, 108 | 'pid[0]': module.exports.demoProductId, 109 | 'domain[0]': 'hostingtest.com', 110 | 'billingcycle[0]': 'monthly', 111 | 'priceoverride[0]': 1 112 | }; 113 | const orderRes = await whmcs.orders.addOrder(orderOpts); 114 | expect(orderRes).to.have.a.property('result').to.equal('success'); 115 | expect(orderRes).to.have.a.property('orderid').to.not.be.null; 116 | module.exports.demoOrderId = orderRes.orderid; 117 | return orderRes; 118 | } 119 | 120 | async function getService() { 121 | const productsOpts = { 122 | domain: 'hostingtest.com', 123 | clientid: module.exports.demoClientId, 124 | limitstart: 0, 125 | limitnum: 1 126 | }; 127 | const productsRes = await whmcs.client.getClientsProducts(productsOpts) 128 | expect(productsRes).to.have.a.property('result').to.equal('success'); 129 | expect(productsRes).to.have.a.property('products').to.be.an('object').to.have.a.property('product').to.be.an('array'); 130 | expect(productsRes.products.product[0]).to.have.a.property('id').to.be.a('string'); 131 | module.exports.demoServiceId = productsRes.products.product[0].id; 132 | return productsRes; 133 | } 134 | 135 | async function getSupportDepartment() { 136 | const deptRes = await whmcs.tickets.getSupportDepartments(); 137 | expect(deptRes).to.have.a.property('result').to.equal('success'); 138 | expect(deptRes).to.have.a.property('totalresults').to.not.be.null; 139 | if (deptRes.totalresults == 0) { 140 | throw new Error('Support departments not found. You must create a support department and set the environment variable "WHMCS_TEST_DEPTID" in order to proceed with the tests.'); 141 | } 142 | expect(deptRes).to.have.a.property('departments').to.be.an('object'); 143 | expect(deptRes.departments).to.have.a.property('department').to.be.an('array'); 144 | expect(deptRes.departments.department[0]).to.have.a.property('id').to.be.a('string') 145 | module.exports.demoDeptId = deptRes.departments.department[0].id; 146 | return deptRes; 147 | } 148 | 149 | async function checkProjectManagementIsActive() { 150 | const opts = { 151 | title: 'test project', 152 | adminid: 1 153 | }; 154 | 155 | let res; 156 | try { 157 | res = await whmcs.projectManagement.createProject(opts); 158 | } catch (e) { 159 | if (e instanceof WhmcsError && e.message == 'Project Management is not active.') { 160 | throw new Error('Project Management is not active. You must activate the Project Management Addon in order to proceed with the tests.'); 161 | } else { 162 | throw e; 163 | } 164 | } 165 | expect(res).to.have.a.property('result').to.equal('success'); 166 | } 167 | 168 | async function initialize() { 169 | console.log('Preparing the test environment. Please wait...'); 170 | await addClient(); 171 | await addContact(); 172 | await addProduct(); 173 | await getPaymentMethod(); 174 | await createOrder(); 175 | await getService(); 176 | await getSupportDepartment(); 177 | await checkProjectManagementIsActive(); 178 | console.log('Test environment initialization complete.'); 179 | } 180 | 181 | async function removeClient() { 182 | const opts = { 183 | clientid: module.exports.demoClientId, 184 | deleteusers: true, 185 | deletetransactions: true 186 | }; 187 | const delRes = await whmcs.client.deleteClient(opts); 188 | expect(delRes).to.have.a.property('result').to.equal('success'); 189 | return delRes; 190 | } 191 | 192 | async function rollback() { 193 | console.log('Removing the temporary data. Please wait...'); 194 | await removeClient(); 195 | console.log('Temporary data removed.'); 196 | } 197 | 198 | before(async function () { 199 | const _this = this; 200 | this.timeout(60000); 201 | await initialize(); 202 | }); 203 | 204 | after(async function () { 205 | this.timeout(60000); 206 | await rollback(); 207 | }); 208 | 209 | function serialize(mixed_value) { 210 | // http://kevin.vanzonneveld.net 211 | // + original by: Arpad Ray (mailto:arpad@php.net) 212 | // + improved by: Dino 213 | // + bugfixed by: Andrej Pavlovic 214 | // + bugfixed by: Garagoth 215 | // + input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html) 216 | // + bugfixed by: Russell Walker (http://www.nbill.co.uk/) 217 | // + bugfixed by: Jamie Beck (http://www.terabit.ca/) 218 | // + input by: Martin (http://www.erlenwiese.de/) 219 | // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/) 220 | // + improved by: Le Torbi (http://www.letorbi.de/) 221 | // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net/) 222 | // + bugfixed by: Ben (http://benblume.co.uk/) 223 | // % note: We feel the main purpose of this function should be to ease the transport of data between php & js 224 | // % note: Aiming for PHP-compatibility, we have to translate objects to arrays 225 | // * example 1: serialize(['Kevin', 'van', 'Zonneveld']); 226 | // * returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}' 227 | // * example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}); 228 | // * returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}' 229 | let val, key, okey, 230 | ktype = '', 231 | vals = '', 232 | count = 0, 233 | _utf8Size = function (str) { 234 | let size = 0, 235 | i = 0, 236 | l = str.length, 237 | code = ''; 238 | for (i = 0; i < l; i++) { 239 | code = str.charCodeAt(i); 240 | if (code < 0x0080) { 241 | size += 1; 242 | } else if (code < 0x0800) { 243 | size += 2; 244 | } else { 245 | size += 3; 246 | } 247 | } 248 | return size; 249 | }, 250 | _getType = function (inp) { 251 | let match, key, cons, types, type = typeof inp; 252 | 253 | if (type === 'object' && !inp) { 254 | return 'null'; 255 | } 256 | if (type === 'object') { 257 | if (!inp.constructor) { 258 | return 'object'; 259 | } 260 | cons = inp.constructor.toString(); 261 | match = cons.match(/(\w+)\(/); 262 | if (match) { 263 | cons = match[1].toLowerCase(); 264 | } 265 | types = ['boolean', 'number', 'string', 'array']; 266 | for (key in types) { 267 | if (cons == types[key]) { 268 | type = types[key]; 269 | break; 270 | } 271 | } 272 | } 273 | return type; 274 | }, 275 | type = _getType(mixed_value); 276 | 277 | switch (type) { 278 | case 'function': 279 | val = ''; 280 | break; 281 | case 'boolean': 282 | val = 'b:' + (mixed_value ? '1' : '0'); 283 | break; 284 | case 'number': 285 | val = (Math.round(mixed_value) == mixed_value ? 'i' : 'd') + ':' + mixed_value; 286 | break; 287 | case 'string': 288 | val = 's:' + _utf8Size(mixed_value) + ':"' + mixed_value + '"'; 289 | break; 290 | case 'array': 291 | case 'object': 292 | val = 'a'; 293 | /* 294 | if (type === 'object') { 295 | let objname = mixed_value.constructor.toString().match(/(\w+)\(\)/); 296 | if (objname == undefined) { 297 | return; 298 | } 299 | objname[1] = this.serialize(objname[1]); 300 | val = 'O' + objname[1].substring(1, objname[1].length - 1); 301 | } 302 | */ 303 | 304 | for (key in mixed_value) { 305 | if (mixed_value.hasOwnProperty(key)) { 306 | ktype = _getType(mixed_value[key]); 307 | if (ktype === 'function') { 308 | continue; 309 | } 310 | 311 | okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key); 312 | vals += serialize(okey) + serialize(mixed_value[key]); 313 | count++; 314 | } 315 | } 316 | val += ':' + count + ':{' + vals + '}'; 317 | break; 318 | default: 319 | // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP 320 | val = 'N'; 321 | break; 322 | } 323 | if (type !== 'object' && type !== 'array') { 324 | val += ';'; 325 | } 326 | return val; 327 | }; 328 | 329 | module.exports = { 330 | whmcs: whmcs, 331 | demoUserDetails: userDetails, 332 | demoContactDetails: contactDetails, 333 | serialize: serialize 334 | }; 335 | -------------------------------------------------------------------------------- /test/domains.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | function isRegistrarError(msg) { 6 | const errorMessages = ['Registrar Error Message', 'Registrar Function Not Supported', 'No response from API command']; 7 | 8 | for (let i = 0; i < errorMessages.length; i++) { 9 | if (msg.indexOf(errorMessages[i]) > -1) { 10 | return true; 11 | } 12 | } 13 | 14 | return false; 15 | }; 16 | 17 | describe('Module "Domains"', function () { 18 | 19 | before(async function () { 20 | const opts = { 21 | extension: '.com', 22 | 'register[1]': 10, 23 | 'transfer[1]': 10, 24 | 'renew[1]': 10, 25 | 'currency_code': process.env.WHMCS_TEST_CURRENCY || 'USD' 26 | }; 27 | const res = await conf.whmcs.domains.createOrUpdateTLD(opts); 28 | expect(res).to.have.a.property('result').to.equal('success'); 29 | expect(res).to.have.a.property('extension').to.be.equal(opts.extension); 30 | }); 31 | 32 | it('should create or update tld', async function () { 33 | const opts = { 34 | extension: '.com', 35 | 'register[1]': 15, 36 | 'transfer[1]': 15, 37 | 'renew[1]': 15, 38 | 'currency_code': process.env.WHMCS_TEST_CURRENCY || 'USD' 39 | }; 40 | const res = await conf.whmcs.domains.createOrUpdateTLD(opts); 41 | expect(res).to.have.a.property('result').to.equal('success'); 42 | expect(res).to.have.a.property('extension').to.be.equal(opts.extension); 43 | }); 44 | 45 | it('should get tld pricing', async function () { 46 | this.timeout(30000); 47 | 48 | const opts = { 49 | clientid: conf.demoClientId 50 | }; 51 | const res = await conf.whmcs.domains.getTLDPricing(opts); 52 | expect(res).to.have.a.property('result').to.equal('success'); 53 | expect(res).to.have.a.property('pricing').to.be.an('object'); 54 | }); 55 | 56 | describe('Domain', function () { 57 | let demoDomainId, demoOrderId; 58 | 59 | before(async function () { 60 | this.timeout(30000); 61 | 62 | const orderOpts = { 63 | clientid: conf.demoClientId, 64 | paymentmethod: conf.demoPaymentMethod, 65 | 'domain[0]': 'domaintest.com', 66 | 'domaintype[0]': 'register', 67 | 'regperiod[0]': 1 68 | }; 69 | const orderRes = await conf.whmcs.orders.addOrder(orderOpts); 70 | expect(orderRes).to.have.a.property('result').to.equal('success'); 71 | expect(orderRes).to.have.a.property('orderid').to.not.be.null; 72 | 73 | demoOrderId = orderRes.orderid; 74 | 75 | const domainOpts = { 76 | domain: 'domaintest.com', 77 | limitstart: 0, 78 | limitnum: 1 79 | }; 80 | const domainRes = await conf.whmcs.client.getClientsDomains(domainOpts); 81 | expect(domainRes).to.have.a.property('result').to.equal('success'); 82 | expect(domainRes).to.have.a.property('domains').to.be.an('object').to.have.a.property('domain').to.be.an('array').to.have.length.greaterThan(0); 83 | expect(domainRes.domains.domain[0]).to.have.a.property('id').to.not.be.null; 84 | demoDomainId = domainRes.domains.domain[0].id; 85 | }); 86 | 87 | it('should get locking status', async function () { 88 | const opts = { 89 | domainid: demoDomainId 90 | }; 91 | 92 | const res = await conf.whmcs.domains.domainGetLockingStatus(opts); 93 | expect(res).to.have.a.property('result').to.equal('success'); 94 | expect(res).to.have.a.property('lockstatus').to.be.a('string'); 95 | }); 96 | 97 | it('should get nameservers', async function () { 98 | this.timeout(60000); 99 | const opts = { 100 | domainid: demoDomainId 101 | }; 102 | 103 | try { 104 | const res = await conf.whmcs.domains.domainGetNameservers(opts); 105 | expect(res).to.have.a.property('result').to.equal('success'); 106 | expect(res).to.have.a.property('ns1').to.not.be.null; 107 | } catch (e) { 108 | if (e instanceof WhmcsError) { 109 | expect(isRegistrarError(e.message)).to.be.true; 110 | } else { 111 | throw e; 112 | } 113 | } 114 | }); 115 | 116 | it('should get whois information', async function () { 117 | this.timeout(60000); 118 | const opts = { 119 | domainid: demoDomainId 120 | }; 121 | 122 | try { 123 | const res = await conf.whmcs.domains.domainGetWhoisInfo(opts); 124 | expect(res).to.have.a.property('result').to.equal('success'); 125 | } catch (e) { 126 | if (e instanceof WhmcsError) { 127 | expect(isRegistrarError(e.message)).to.be.true; 128 | } else { 129 | throw e; 130 | } 131 | } 132 | }); 133 | 134 | it('should send a register command to command to registrar module', async function () { 135 | const opts = { 136 | domainid: demoDomainId 137 | }; 138 | 139 | try { 140 | const res = await conf.whmcs.domains.domainRegister(opts); 141 | expect(res).to.have.a.property('result').to.equal('success'); 142 | } catch (e) { 143 | if (e instanceof WhmcsError) { 144 | expect(isRegistrarError(e.message)).to.be.true; 145 | } else { 146 | throw e; 147 | } 148 | } 149 | }); 150 | 151 | it('should send a release command to registrar module', async function () { 152 | const opts = { 153 | domainid: demoDomainId 154 | }; 155 | 156 | try { 157 | const res = await conf.whmcs.domains.domainRelease(opts); 158 | expect(res).to.have.a.property('result').to.equal('success'); 159 | } catch (e) { 160 | if (e instanceof WhmcsError) { 161 | expect(isRegistrarError(e.message)).to.be.true; 162 | } else { 163 | throw e; 164 | } 165 | } 166 | }); 167 | 168 | it('should send a renew command to registrar module', async function () { 169 | const opts = { 170 | domainid: demoDomainId 171 | }; 172 | 173 | try { 174 | const res = await conf.whmcs.domains.domainRenew(opts); 175 | expect(res).to.have.a.property('result').to.equal('success'); 176 | } catch (e) { 177 | if (e instanceof WhmcsError) { 178 | expect(isRegistrarError(e.message)).to.be.true; 179 | } else { 180 | throw e; 181 | } 182 | } 183 | }); 184 | 185 | it('should send an epp command to registrar module', async function () { 186 | const opts = { 187 | domainid: demoDomainId 188 | }; 189 | 190 | try { 191 | const res = await conf.whmcs.domains.domainRequestEPP(opts); 192 | expect(res).to.have.a.property('result').to.equal('success'); 193 | } catch (e) { 194 | if (e instanceof WhmcsError) { 195 | expect(isRegistrarError(e.message)).to.be.true; 196 | } else { 197 | throw e; 198 | } 199 | } 200 | }); 201 | 202 | it('should send the toggle ID protect command to registrar module', async function () { 203 | const opts = { 204 | domainid: demoDomainId 205 | }; 206 | 207 | try { 208 | const res = await conf.whmcs.domains.domainToggleIdProtect(opts); 209 | expect(res).to.have.a.property('result').to.equal('success'); 210 | } catch (e) { 211 | if (e instanceof WhmcsError) { 212 | expect(isRegistrarError(e.message)).to.be.true; 213 | } else { 214 | throw e; 215 | } 216 | } 217 | }); 218 | 219 | it('should send the domain transfer command to registrar module', async function () { 220 | const opts = { 221 | domainid: demoDomainId 222 | }; 223 | 224 | try { 225 | const res = await conf.whmcs.domains.domainTransfer(opts); 226 | expect(res).to.have.a.property('result').to.equal('success'); 227 | } catch (e) { 228 | if (e instanceof WhmcsError) { 229 | expect(isRegistrarError(e.message)).to.be.true; 230 | } else { 231 | throw e; 232 | } 233 | } 234 | }); 235 | 236 | it('should send the update lock command to registrar module', async function () { 237 | const opts = { 238 | domainid: demoDomainId 239 | }; 240 | 241 | try { 242 | const res = await conf.whmcs.domains.domainUpdateLockingStatus(opts); 243 | expect(res).to.have.a.property('result').to.equal('success'); 244 | } catch (e) { 245 | if (e instanceof WhmcsError) { 246 | expect(isRegistrarError(e.message)).to.be.true; 247 | } else { 248 | throw e; 249 | } 250 | } 251 | }); 252 | 253 | it('should send the save nameservers command to registrar module', async function () { 254 | const opts = { 255 | domainid: demoDomainId, 256 | ns1: 'ns1.domaintest.com', 257 | ns2: 'ns2.domaintest.com' 258 | }; 259 | 260 | try { 261 | const res = await conf.whmcs.domains.domainUpdateNameservers(opts); 262 | expect(res).to.have.a.property('result').to.equal('success'); 263 | } catch (e) { 264 | if (e instanceof WhmcsError) { 265 | expect(isRegistrarError(e.message)).to.be.true; 266 | } else { 267 | throw e; 268 | } 269 | } 270 | }); 271 | 272 | it('should send the save whois command to registrar module', async function () { 273 | const opts = { 274 | domainid: demoDomainId 275 | }; 276 | 277 | try { 278 | const res = await conf.whmcs.domains.domainUpdateWhoisInfo(opts); 279 | expect(res).to.have.a.property('result').to.equal('success'); 280 | } catch (e) { 281 | if (e instanceof WhmcsError) { 282 | const possibleErr = ['Domain ID Not Found', 'XML Required', 'Registrar Error Message']; 283 | expect(possibleErr.indexOf(e.message) > -1).to.be.true; 284 | } else { 285 | throw e; 286 | } 287 | } 288 | }); 289 | 290 | it('should retrieve whois information', async function () { 291 | const opts = { 292 | domainid: demoDomainId 293 | }; 294 | 295 | try { 296 | const res = await conf.whmcs.domains.domainWhois(opts); 297 | expect(res).to.have.a.property('result').to.equal('success'); 298 | expect(res).to.have.a.property('status').to.not.be.null; 299 | } catch (e) { 300 | if (e instanceof WhmcsError) { 301 | expect(isRegistrarError(e.message)).to.be.true; 302 | } else { 303 | throw e; 304 | } 305 | } 306 | }); 307 | 308 | it('should update a domain', async function () { 309 | const opts = { 310 | domainid: demoDomainId, 311 | idprotection: false 312 | }; 313 | 314 | try { 315 | const res = await conf.whmcs.domains.updateClientDomain(opts); 316 | expect(res).to.have.a.property('result').to.equal('success'); 317 | expect(res).to.have.a.property('domainid').to.equal(parseInt(demoDomainId)); 318 | } catch (e) { 319 | if (e instanceof WhmcsError) { 320 | expect(isRegistrarError(e.message)).to.be.true; 321 | } else { 322 | throw e; 323 | } 324 | } 325 | }); 326 | 327 | }); 328 | 329 | }); -------------------------------------------------------------------------------- /test/internal.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WHMCS = require('../whmcs'), 4 | Bluebird = require('bluebird'), 5 | WhmcsError = require('../lib/whmcserror'); 6 | 7 | describe('Internal', function () { 8 | it('should call an action by name', async function () { 9 | const opts = { 10 | limitstart: 0, 11 | limitnum: 1 12 | } 13 | const res = await conf.whmcs.callApi('GetActivityLog', opts); 14 | expect(res).to.have.a.property('result').to.equal('success'); 15 | }); 16 | 17 | it('should handle callbacks', function (done) { 18 | const opts = { 19 | limitstart: 0, 20 | limitnum: 1 21 | } 22 | conf.whmcs.callApi('GetActivityLog', opts, function (err, res) { 23 | expect(err).to.be.null; 24 | expect(res).to.have.a.property('result').to.equal('success'); 25 | done(); 26 | }); 27 | }); 28 | 29 | it('should handle native promises', function () { 30 | const opts = { 31 | limitstart: 0, 32 | limitnum: 1 33 | }; 34 | 35 | const promise = conf.whmcs.system.getActivityLog(opts); 36 | expect(promise).to.be.instanceOf(Promise); 37 | 38 | return promise.then(function (res) { 39 | expect(res).to.have.a.property('result').to.equal('success'); 40 | }); 41 | }); 42 | 43 | it('should handle custom promises library', function () { 44 | const config = { 45 | apiIdentifier: process.env.WHMCS_API_IDENTIFIER || 'apiIdentifier', 46 | apiSecret: process.env.WHMCS_API_SECRET || 'apiSecret', 47 | serverUrl: process.env.WHMCS_URL || 'http://192.168.1.1', 48 | userAgent: process.env.WHMCS_USERAGENT || 'node-whmcs', 49 | accessKey: process.env.WHMCS_AK, 50 | Promise: Bluebird, 51 | }; 52 | 53 | const whmcs = new WHMCS(config); 54 | 55 | const opts = { 56 | limitstart: 0, 57 | limitnum: 1 58 | }; 59 | 60 | const promise = whmcs.system.getActivityLog(opts); 61 | expect(promise).to.be.instanceOf(Bluebird); 62 | 63 | return promise.then(function (res) { 64 | expect(res).to.have.a.property('result').to.equal('success'); 65 | }); 66 | }); 67 | 68 | it('should throw an error if Promise library is invalid', function () { 69 | const config = { 70 | apiIdentifier: process.env.WHMCS_API_IDENTIFIER || 'apiIdentifier', 71 | apiSecret: process.env.WHMCS_API_SECRET || 'apiSecret', 72 | serverUrl: process.env.WHMCS_URL || 'http://192.168.1.1', 73 | userAgent: process.env.WHMCS_USERAGENT || 'node-whmcs', 74 | accessKey: process.env.WHMCS_AK, 75 | Promise: {} 76 | }; 77 | 78 | const fn = function () { 79 | return new WHMCS(config); 80 | }; 81 | 82 | expect(fn).to.throw(Error, 'Invalid promise library.'); 83 | }); 84 | 85 | it('should handle XML response', async function () { 86 | const config = { 87 | apiIdentifier: process.env.WHMCS_API_IDENTIFIER || 'apiIdentifier', 88 | apiSecret: process.env.WHMCS_API_SECRET || 'apiSecret', 89 | serverUrl: process.env.WHMCS_URL || 'http://192.168.1.1', 90 | userAgent: process.env.WHMCS_USERAGENT || 'node-whmcs', 91 | accessKey: process.env.WHMCS_AK, 92 | responseType: 'xml' 93 | }; 94 | 95 | const whmcs = new WHMCS(config); 96 | 97 | const opts = { 98 | limitstart: 0, 99 | limitnum: 1 100 | }; 101 | 102 | const res = await whmcs.system.getActivityLog(opts); 103 | expect(res).to.have.a.property('result').to.equal('success'); 104 | expect(res).to.have.a.property('action').to.equal('getactivitylog'); 105 | }); 106 | 107 | it('should authenticate with username and password', async function () { 108 | const config = { 109 | username: process.env.WHMCS_USER || 'username', 110 | password: process.env.WHMCS_PASSWORD || 'password', 111 | serverUrl: process.env.WHMCS_URL || 'http://192.168.1.1', 112 | userAgent: process.env.WHMCS_USERAGENT || 'node-whmcs', 113 | accessKey: process.env.WHMCS_AK, 114 | }; 115 | 116 | const whmcs = new WHMCS(config); 117 | 118 | const opts = { 119 | limitstart: 0, 120 | limitnum: 1 121 | }; 122 | 123 | const res = await whmcs.system.getActivityLog(opts); 124 | expect(res).to.have.a.property('result').to.equal('success'); 125 | }); 126 | }); -------------------------------------------------------------------------------- /test/module.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Module"', function () { 6 | 7 | it('should get the module queue', async function () { 8 | const res = await conf.whmcs.module.getModuleQueue(); 9 | expect(res).to.have.a.property('result').to.equal('success'); 10 | expect(res).to.have.a.property('queue').to.be.an('array'); 11 | }); 12 | 13 | it('should get the module configuration parameters', async function () { 14 | const opts = { 15 | moduleType: 'gateway', 16 | moduleName: 'paypal' 17 | }; 18 | 19 | const res = await conf.whmcs.module.getModuleConfigurationParameters(opts); 20 | expect(res).to.have.a.property('result').to.equal('success'); 21 | expect(res).to.have.a.property('parameters').to.be.an('array'); 22 | }); 23 | 24 | it('should activate a module', async function () { 25 | const opts = { 26 | moduleType: 'gateway', 27 | moduleName: 'paypal' 28 | }; 29 | 30 | let res; 31 | 32 | try { 33 | res = await conf.whmcs.module.activateModule(opts); 34 | expect(res).to.have.a.property('result').to.equal('success'); 35 | } catch (e) { 36 | if (e instanceof WhmcsError) { 37 | const possibleErr = ['Failed to activate:', 'An unexpected error occurred:', 'Module activation not supported by module type.', 'Invalid module name provided.', 'Invalid module type provided. Supported module types include:']; 38 | expect(possibleErr.some(err => { 39 | return e.message.indexOf(err) > -1; 40 | })).to.be.true; 41 | } else { 42 | throw e; 43 | } 44 | } 45 | }); 46 | 47 | it('should update module configuration parameters', async function () { 48 | const opts = { 49 | moduleType: 'gateway', 50 | moduleName: 'paypal' 51 | }; 52 | 53 | const res = await conf.whmcs.module.updateModuleConfiguration(opts); 54 | expect(res).to.have.a.property('result').to.equal('success'); 55 | }); 56 | 57 | it('should deactivate a module', async function () { 58 | const opts = { 59 | moduleType: 'gateway', 60 | moduleName: 'paypal', 61 | newGateway: 'paypal' 62 | }; 63 | 64 | try { 65 | const res = await conf.whmcs.module.deactivateModule(opts); 66 | expect(res).to.have.a.property('result').to.equal('success'); 67 | } catch (e) { 68 | if (e instanceof WhmcsError) { 69 | expect(e.message).to.have.string('Module deactivation not supported by module type'); 70 | } else { 71 | throw e; 72 | } 73 | } 74 | }); 75 | 76 | }); -------------------------------------------------------------------------------- /test/orders.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Orders"', function () { 6 | 7 | it('should add an order', async function () { 8 | const opts = { 9 | clientid: conf.demoClientId, 10 | paymentmethod: conf.demoPaymentMethod, 11 | 'domain[0]': 'domaintest.com', 12 | 'domaintype[0]': 'register', 13 | 'regperiod[0]': 1 14 | }; 15 | const res = await conf.whmcs.orders.addOrder(opts); 16 | expect(res).to.have.a.property('result').to.equal('success'); 17 | expect(res).to.have.a.property('orderid').to.not.be.null; 18 | }); 19 | 20 | it('should get order statuses', async function () { 21 | const res = await conf.whmcs.orders.getOrderStatuses(); 22 | expect(res).to.have.a.property('result').to.equal('success'); 23 | expect(res).to.have.a.property('statuses').to.be.an('object'); 24 | expect(res.statuses).to.have.a.property('status').to.be.an('array'); 25 | }); 26 | 27 | it('should get promotions', async function () { 28 | const res = await conf.whmcs.orders.getPromotions(); 29 | expect(res).to.have.a.property('result').to.equal('success'); 30 | expect(res).to.have.a.property('totalresults').to.not.be.null; 31 | if (parseInt(res.totalresults > 0)) { 32 | expect(res).to.have.a.property('promotions').to.be.an('object'); 33 | expect(res.promotions.to.have.a.property('promotion').to.be.an('array')); 34 | } 35 | }); 36 | 37 | describe('Product', function () { 38 | let demoPid; 39 | 40 | before(async function () { 41 | const _this = this; 42 | const opts = { 43 | name: 'Test product', 44 | gid: process.env.WHMCS_TEST_GID || '1', 45 | type: 'hostingaccount' 46 | }; 47 | const res = await conf.whmcs.products.addProduct(opts); 48 | expect(res).to.have.a.property('result').to.equal('success'); 49 | expect(res).to.have.a.property('pid'); 50 | demoPid = res.pid; 51 | }); 52 | 53 | it('should get product by ID', async function () { 54 | const opts = { 55 | pid: demoPid 56 | }; 57 | const res = await conf.whmcs.orders.getProducts(opts); 58 | expect(res).to.have.a.property('result').to.equal('success'); 59 | expect(res).to.have.a.property('products') 60 | .to.be.an('object') 61 | .to.have.a.property('product') 62 | .to.be.an('array').to.have.lengthOf(1); 63 | expect(res.products.product[0]).to.have.a.property('pid').to.not.be.null; 64 | expect(res.products.product[0].pid == demoPid).to.equal(true); 65 | }); 66 | }); 67 | 68 | describe('Order', function () { 69 | let demoOrderId; 70 | 71 | beforeEach(async function () { 72 | const opts = { 73 | clientid: conf.demoClientId, 74 | paymentmethod: conf.demoPaymentMethod, 75 | 'domain[0]': 'domaintest.com', 76 | 'domaintype[0]': 'register', 77 | 'regperiod[0]': 1 78 | }; 79 | const res = await conf.whmcs.orders.addOrder(opts); 80 | expect(res).to.have.a.property('result').to.equal('success'); 81 | expect(res).to.have.a.property('orderid').to.not.be.null; 82 | demoOrderId = res.orderid; 83 | }); 84 | 85 | it('should get order by ID', async function () { 86 | const opts = { 87 | id: demoOrderId 88 | }; 89 | 90 | const res = await conf.whmcs.orders.getOrders(opts); 91 | expect(res).to.have.a.property('result').to.equal('success'); 92 | expect(res).to.have.a.property('orders') 93 | .to.be.an('object') 94 | .to.have.a.property('order') 95 | .to.be.an('array') 96 | .to.have.lengthOf(1); 97 | expect(res.orders.order[0]).to.have.a.property('id').to.not.be.null; 98 | expect(res.orders.order[0].id == demoOrderId).to.equal(true); 99 | }); 100 | 101 | it('should mark the order as fraudulent', async function () { 102 | const opts = { 103 | orderid: demoOrderId 104 | }; 105 | const res = await conf.whmcs.orders.fraudOrder(opts); 106 | expect(res).to.have.a.property('result').to.equal('success'); 107 | }); 108 | 109 | it('should run a fraud check', async function () { 110 | const opts = { 111 | orderid: demoOrderId 112 | }; 113 | 114 | try { 115 | const res = await conf.whmcs.orders.orderFraudCheck(opts); 116 | expect(res).to.have.a.property('result').to.equal('success'); 117 | } catch (e) { 118 | if (e instanceof WhmcsError) { 119 | const possibleErr = ['No Active Fraud Module']; 120 | expect(possibleErr.some(err => { 121 | return e.message.indexOf(err) > -1; 122 | })).to.be.true; 123 | } else { 124 | throw e; 125 | } 126 | } 127 | }); 128 | 129 | it('should set an order to pending', async function () { 130 | const opts = { 131 | orderid: demoOrderId 132 | }; 133 | const res = await conf.whmcs.orders.pendingOrder(opts); 134 | expect(res).to.have.a.property('result').to.equal('success'); 135 | }); 136 | 137 | it('should cancel a pending order', async function () { 138 | const pendingOpts = { 139 | orderid: demoOrderId 140 | }; 141 | const pendingRes = await conf.whmcs.orders.pendingOrder(pendingOpts); 142 | expect(pendingRes).to.have.a.property('result').to.equal('success'); 143 | 144 | const cancelOpts = { 145 | orderid: demoOrderId 146 | }; 147 | const cancelRes = await conf.whmcs.orders.cancelOrder(cancelOpts); 148 | expect(cancelRes).to.have.a.property('result').to.equal('success'); 149 | }); 150 | 151 | it('should accept an order', async function () { 152 | const opts = { 153 | orderid: demoOrderId 154 | }; 155 | const res = await conf.whmcs.orders.acceptOrder(opts); 156 | expect(res).to.have.a.property('result').to.equal('success'); 157 | }); 158 | 159 | it('should delete a cancelled order', async function () { 160 | const cancelOpts = { 161 | orderid: demoOrderId 162 | }; 163 | const cancelRes = await conf.whmcs.orders.cancelOrder(cancelOpts); 164 | expect(cancelRes).to.have.a.property('result').to.equal('success'); 165 | 166 | const opts = { 167 | orderid: demoOrderId 168 | }; 169 | const res = await conf.whmcs.orders.deleteOrder(opts); 170 | expect(res).to.have.a.property('result').to.equal('success'); 171 | }); 172 | }); 173 | 174 | }); -------------------------------------------------------------------------------- /test/products.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Products"', function () { 6 | 7 | it('should create a new product', async function () { 8 | const _this = this; 9 | const opts = { 10 | name: 'Test product', 11 | gid: process.env.WHMCS_TEST_GID || '1', 12 | type: 'hostingaccount', 13 | 14 | }; 15 | 16 | const res = await conf.whmcs.products.addProduct(opts); 17 | expect(res).to.have.a.property('result').to.equal('success'); 18 | expect(res).to.have.a.property('pid').to.not.be.null; 19 | }); 20 | }); -------------------------------------------------------------------------------- /test/projectmanagement.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Project Management"', function () { 6 | let demoProjectId; 7 | 8 | before(async function () { 9 | const opts = { 10 | title: 'demo project', 11 | adminid: 1 12 | }; 13 | 14 | const res = await conf.whmcs.projectManagement.createProject(opts); 15 | demoProjectId = res.projectid; 16 | }); 17 | 18 | it('should create a project', async function () { 19 | const opts = { 20 | title: 'untitled project', 21 | adminid: 1 22 | }; 23 | const res = await conf.whmcs.projectManagement.createProject(opts); 24 | expect(res).to.have.a.property('projectid').to.not.be.null; 25 | }); 26 | 27 | it('should get projects', async function () { 28 | const opts = { 29 | limitstart: 0, 30 | limitnum: 1 31 | }; 32 | const res = await conf.whmcs.projectManagement.getProjects(opts); 33 | expect(res).to.have.a.property('numreturned').to.not.be.null; 34 | expect(res).to.have.a.property('projects').to.be.an.an('array').to.have.length.greaterThan(0); 35 | }); 36 | 37 | it('should get project details by project id', async function () { 38 | const opts = { 39 | projectid: demoProjectId 40 | }; 41 | const res = await conf.whmcs.projectManagement.getProject(opts); 42 | expect(res).to.have.a.property('projectinfo').to.be.an.an('object'); 43 | }); 44 | 45 | it('should update a project', async function () { 46 | const updateOpts = { 47 | projectid: demoProjectId, 48 | title: 'space oddity' 49 | }; 50 | const updateRes = await conf.whmcs.projectManagement.updateProject(updateOpts); 51 | expect(updateRes).to.have.a.property('message').to.equal('Project Has Been Updated'); 52 | 53 | const getOpts = { 54 | projectid: demoProjectId 55 | }; 56 | const getRes = await conf.whmcs.projectManagement.getProject(getOpts); 57 | expect(getRes).to.have.a.property('projectinfo').to.be.an.an('object'); 58 | expect(getRes.projectinfo).to.have.a.property('title').to.equal('space oddity'); 59 | }); 60 | 61 | it('should add a message to a project', async function () { 62 | const addOpts = { 63 | projectid: demoProjectId, 64 | message: 'can you hear me major tom?' 65 | }; 66 | 67 | const addRes = await conf.whmcs.projectManagement.addProjectMessage(addOpts); 68 | expect(addRes).to.have.a.property('message').to.equal('Message has been added'); 69 | 70 | const getOpts = { 71 | projectid: demoProjectId 72 | }; 73 | const getRes = await conf.whmcs.projectManagement.getProject(getOpts); 74 | expect(getRes).to.have.a.property('messages').to.be.an.an('object'); 75 | expect(getRes.messages).to.have.a.property('message').to.be.an('array').to.have.lengthOf(1); 76 | expect(getRes.messages.message[0]).to.have.a.property('message').to.equal('can you hear me major tom?'); 77 | }); 78 | 79 | it('should add a task to a project', async function () { 80 | const addOpts = { 81 | projectid: demoProjectId, 82 | duedate: '1969-07-11', 83 | task: 'leave the capsule' 84 | }; 85 | 86 | const addRes = await conf.whmcs.projectManagement.addProjectTask(addOpts); 87 | expect(addRes).to.have.a.property('message').to.equal('Task has been added'); 88 | 89 | 90 | const getOpts = { 91 | projectid: demoProjectId 92 | }; 93 | const getRes = await conf.whmcs.projectManagement.getProject(getOpts); 94 | expect(getRes).to.have.a.property('tasks').to.be.an.an('object'); 95 | expect(getRes.tasks).to.have.a.property('task').to.be.an('array').to.have.lengthOf(1); 96 | expect(getRes.tasks.task[0]).to.have.a.property('task').to.equal('leave the capsule'); 97 | demoTaskId = getRes.tasks.task[0].id; 98 | }); 99 | 100 | describe('Project task', function () { 101 | let demoTaskId; 102 | 103 | before(async function () { 104 | const addOpts = { 105 | projectid: demoProjectId, 106 | duedate: '1969-07-11', 107 | task: 'leave the capsule' 108 | }; 109 | 110 | const addRes = await conf.whmcs.projectManagement.addProjectTask(addOpts); 111 | expect(addRes).to.have.a.property('message').to.equal('Task has been added'); 112 | 113 | const getOpts = { 114 | projectid: demoProjectId 115 | }; 116 | const getRes = await conf.whmcs.projectManagement.getProject(getOpts); 117 | expect(getRes).to.have.a.property('tasks').to.be.an.an('object'); 118 | expect(getRes.tasks).to.have.a.property('task').to.be.an('array').to.have.length.greaterThan(0); 119 | expect(getRes.tasks.task[0]).to.have.a.property('task').to.equal('leave the capsule'); 120 | demoTaskId = getRes.tasks.task[0].id; 121 | }); 122 | 123 | it('should update a project task', async function () { 124 | const updateOpts = { 125 | taskid: demoTaskId, 126 | task: 'step through the door' 127 | }; 128 | const updateRes = await conf.whmcs.projectManagement.updateProjectTask(updateOpts); 129 | expect(updateRes).to.have.a.property('message').to.equal('Task has been updated'); 130 | 131 | const getOpts = { 132 | projectid: demoProjectId 133 | }; 134 | const getRes = await conf.whmcs.projectManagement.getProject(getOpts); 135 | expect(getRes).to.have.a.property('tasks').to.be.an.an('object'); 136 | expect(getRes.tasks).to.have.a.property('task').to.be.an('array').to.have.length.greaterThan(0); 137 | expect(getRes.tasks.task[0]).to.have.a.property('task').to.equal('step through the door'); 138 | }); 139 | 140 | it('should start and then end a project task timer', async function () { 141 | const timerOpts = { 142 | taskid: demoTaskId, 143 | projectid: demoProjectId 144 | }; 145 | const timerRes = await conf.whmcs.projectManagement.startTaskTimer(timerOpts); 146 | expect(timerRes).to.have.a.property('message').to.equal('Start Timer Has Been Set'); 147 | 148 | const getOpts = { 149 | projectid: demoProjectId 150 | }; 151 | const getRes = await conf.whmcs.projectManagement.getProject(getOpts); 152 | expect(getRes).to.have.a.property('tasks').to.be.an.an('object'); 153 | expect(getRes.tasks).to.have.a.property('task').to.be.an('array').to.have.length.greaterThan(0); 154 | expect(getRes.tasks.task[0]).to.have.a.property('timelogs').to.be.an.an('object'); 155 | expect(getRes.tasks.task[0].timelogs).to.have.a.property('timelog').to.be.an.an('array').to.have.length.greaterThan(0); 156 | expect(getRes.tasks.task[0].timelogs.timelog[0]).to.have.a.property('id').to.not.be.null; 157 | demoTimerId = getRes.tasks.task[0].timelogs.timelog[0].id; 158 | 159 | const endOpts = { 160 | timerid: demoTimerId, 161 | projectid: demoProjectId 162 | }; 163 | const endRes = await conf.whmcs.projectManagement.endTaskTimer(endOpts); 164 | expect(endRes).to.have.a.property('message').to.equal('Timer Has Ended'); 165 | }); 166 | 167 | it('should delete a project task', async function () { 168 | const deleteOpts = { 169 | projectid: demoProjectId, 170 | taskid: demoTaskId 171 | }; 172 | const deleteRes = await conf.whmcs.projectManagement.deleteProjectTask(deleteOpts); 173 | expect(deleteRes).to.have.a.property('message').to.equal('Task has been deleted'); 174 | }); 175 | }); 176 | }); -------------------------------------------------------------------------------- /test/servers.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Servers"', function () { 6 | 7 | it('should get servers', async function () { 8 | const res = await conf.whmcs.servers.getServers(); 9 | expect(res).to.have.a.property('result').to.equal('success'); 10 | }); 11 | 12 | it('should get health status', async function () { 13 | const res = await conf.whmcs.servers.getHealthStatus(); 14 | expect(res).to.have.a.property('result').to.equal('success'); 15 | }); 16 | 17 | }); -------------------------------------------------------------------------------- /test/service.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | function isModuleNotAssignedError(msg) { 6 | const possibleErr = ['Service not assigned to a module', 'Server response message']; 7 | return possibleErr.some(err => { return msg.indexOf(err) > -1 }); 8 | } 9 | 10 | describe('Module "Service"', function () { 11 | let demoPid, demoOrderId, demoServiceId; 12 | 13 | before(async function () { 14 | const _this = this; 15 | this.timeout(30000); 16 | 17 | const productOpts = { 18 | name: 'Test product', 19 | gid: process.env.WHMCS_TEST_GID || '1', 20 | type: 'hostingaccount', 21 | }; 22 | 23 | const productRes = await conf.whmcs.products.addProduct(productOpts); 24 | expect(productRes).to.have.a.property('result').to.equal('success'); 25 | expect(productRes).to.have.a.property('pid').to.not.be.null; 26 | demoPid = productRes.pid; 27 | 28 | const orderOpts = { 29 | clientid: conf.demoClientId, 30 | paymentmethod: conf.demoPaymentMethod, 31 | 'pid[0]': demoPid, 32 | 'domain[0]': 'hostingtest.com', 33 | 'billingcycle[0]': 'monthly', 34 | 'priceoverride[0]': 1 35 | }; 36 | const orderRes = await conf.whmcs.orders.addOrder(orderOpts); 37 | expect(orderRes).to.have.a.property('result').to.equal('success'); 38 | expect(orderRes).to.have.a.property('orderid').to.not.be.null; 39 | demoOrderId = orderRes.orderid; 40 | 41 | const productsOpts = { 42 | domain: 'hostingtest.com', 43 | limitstart: 0, 44 | limitnum: 1 45 | }; 46 | const productsRes = await conf.whmcs.client.getClientsProducts(productsOpts); 47 | expect(productsRes).to.have.a.property('result').to.equal('success'); 48 | expect(productsRes).to.have.a.property('products').to.be.an('object').to.have.a.property('product').to.be.an('array'); 49 | expect(productsRes.products.product[0]).to.have.a.property('id').to.be.a('string'); 50 | demoServiceId = productsRes.products.product[0].id; 51 | }); 52 | 53 | it('should update a client service', async function () { 54 | const opts = { 55 | serviceid: demoServiceId, 56 | notes: 'this service was updated' 57 | }; 58 | const res = await conf.whmcs.service.updateClientProduct(opts); 59 | expect(res).to.have.a.property('result').to.equal('success'); 60 | }); 61 | 62 | it('should run the module create', async function () { 63 | const opts = { 64 | serviceid: demoServiceId 65 | }; 66 | 67 | try { 68 | const res = await conf.whmcs.service.moduleCreate(opts); 69 | expect(res).to.have.a.property('result').to.equal('success'); 70 | } 71 | catch (e) { 72 | if (e instanceof WhmcsError) { 73 | expect(isModuleNotAssignedError(e.message)).to.be.true; 74 | } else { 75 | throw e; 76 | } 77 | } 78 | }); 79 | 80 | it('should run the change package action', async function () { 81 | const opts = { 82 | serviceid: demoServiceId 83 | }; 84 | 85 | try { 86 | const res = await conf.whmcs.service.moduleChangePackage(opts); 87 | expect(res).to.have.a.property('result').to.equal('success'); 88 | } 89 | catch (e) { 90 | if (e instanceof WhmcsError) { 91 | expect(isModuleNotAssignedError(e.message)).to.be.true; 92 | } else { 93 | throw e; 94 | } 95 | } 96 | }); 97 | 98 | it('should run the change pw action', async function () { 99 | const opts = { 100 | serviceid: demoServiceId 101 | }; 102 | 103 | try { 104 | const res = await conf.whmcs.service.moduleChangePw(opts); 105 | expect(res).to.have.a.property('result').to.equal('success'); 106 | } 107 | catch (e) { 108 | if (e instanceof WhmcsError) { 109 | expect(isModuleNotAssignedError(e.message)).to.be.true; 110 | } else { 111 | throw e; 112 | } 113 | } 114 | }); 115 | 116 | it('should run a custom module action', async function () { 117 | const opts = { 118 | serviceid: demoServiceId, 119 | func_name: 'test' 120 | }; 121 | 122 | try { 123 | const res = await conf.whmcs.service.moduleCustom(opts); 124 | expect(res).to.have.a.property('result').to.equal('success'); 125 | } 126 | catch (e) { 127 | if (e instanceof WhmcsError) { 128 | expect(isModuleNotAssignedError(e.message)).to.be.true; 129 | } else { 130 | throw e; 131 | } 132 | } 133 | }); 134 | 135 | it('should run the module suspend action', async function () { 136 | const opts = { 137 | serviceid: demoServiceId 138 | }; 139 | 140 | try { 141 | const res = await conf.whmcs.service.moduleSuspend(opts); 142 | expect(res).to.have.a.property('result').to.equal('success'); 143 | } 144 | catch (e) { 145 | if (e instanceof WhmcsError) { 146 | expect(isModuleNotAssignedError(e.message)).to.be.true; 147 | } else { 148 | throw e; 149 | } 150 | } 151 | }); 152 | 153 | it('should run the module unsuspend action', async function () { 154 | const opts = { 155 | serviceid: demoServiceId 156 | }; 157 | 158 | try { 159 | const res = await conf.whmcs.service.moduleUnsuspend(opts); 160 | expect(res).to.have.a.property('result').to.equal('success'); 161 | } 162 | catch (e) { 163 | if (e instanceof WhmcsError) { 164 | expect(isModuleNotAssignedError(e.message)).to.be.true; 165 | } else { 166 | throw e; 167 | } 168 | } 169 | }); 170 | 171 | it('should update or calculate an upgrade on a product', async function () { 172 | const opts = { 173 | serviceid: demoServiceId, 174 | type: 'product', 175 | calconly: true, 176 | newproductid: demoPid, 177 | newproductbillingcycle: 'monthly' 178 | }; 179 | 180 | try { 181 | const res = await conf.whmcs.service.upgradeProduct(opts); 182 | expect(res).to.have.a.property('result').to.equal('success'); 183 | } catch (e) { 184 | if (e instanceof WhmcsError) { 185 | expect(e.message).to.have.string('Invalid Billing Cycle Requested'); 186 | } else { 187 | throw e; 188 | } 189 | } 190 | }); 191 | 192 | }); -------------------------------------------------------------------------------- /test/support.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Support"', function () { 6 | 7 | it('should add an announcement', async function () { 8 | const opts = { 9 | date: '1969-07-11', 10 | title: 'There\'s something wrong', 11 | announcement: 'Your circuit\'s dead' 12 | }; 13 | 14 | const res = await conf.whmcs.support.addAnnouncement(opts); 15 | expect(res).to.have.a.property('result').to.equal('success'); 16 | expect(res).to.have.a.property('announcementid').to.not.be.null; 17 | }); 18 | 19 | it('should add a cancel request', async function () { 20 | const opts = { 21 | serviceid: conf.demoServiceId 22 | }; 23 | const res = await conf.whmcs.support.addCancelRequest(opts); 24 | expect(res).to.have.a.property('result').to.equal('success'); 25 | }); 26 | 27 | it('should add a client note', async function () { 28 | const opts = { 29 | userid: conf.demoClientId, 30 | notes: 'Planet Earth is blue and there\'s nothing I can do' 31 | }; 32 | 33 | const res = await conf.whmcs.support.addClientNote(opts); 34 | expect(res).to.have.a.property('result').to.equal('success'); 35 | }); 36 | 37 | it('should open a ticket', async function () { 38 | const opts = { 39 | deptid: conf.demoDeptId, 40 | clientid: conf.demoClientId, 41 | subject: 'this is a subject', 42 | message: 'this is a message' 43 | }; 44 | 45 | const res = await conf.whmcs.support.openTicket(opts); 46 | expect(res).to.have.a.property('result').to.equal('success'); 47 | expect(res).to.have.a.property('id').to.not.be.null; 48 | expect(res).to.have.a.property('tid').to.not.be.null; 49 | expect(res).to.have.a.property('c').to.not.be.null; 50 | }); 51 | 52 | describe('Announcement', function () { 53 | let demoAnnouncementId; 54 | 55 | before(async function () { 56 | const opts = { 57 | date: '1969-07-11', 58 | title: 'There\'s something wrong', 59 | announcement: 'Your circuit\'s dead' 60 | }; 61 | 62 | const res = await conf.whmcs.support.addAnnouncement(opts); 63 | expect(res).to.have.a.property('result').to.equal('success'); 64 | expect(res).to.have.a.property('announcementid').to.not.be.null; 65 | demoAnnouncementId = res.announcementid; 66 | }); 67 | 68 | it('should get announcements', async function () { 69 | const opts = { 70 | limitstart: 0, 71 | limitnum: 1 72 | }; 73 | 74 | const res = await conf.whmcs.support.getAnnouncements(opts); 75 | expect(res).to.have.a.property('result').to.equal('success'); 76 | expect(res).to.have.a.property('announcements').to.be.an.an('object'); 77 | expect(res.announcements).to.have.a.property('announcement').to.be.an('array').to.have.length.above(0); 78 | }); 79 | 80 | it('should delete an announcement', async function () { 81 | const deleteOpts = { 82 | announcementid: demoAnnouncementId 83 | }; 84 | const deleteRes = await conf.whmcs.support.deleteAnnouncement(deleteOpts); 85 | expect(deleteRes).to.have.a.property('result').to.equal('success'); 86 | }); 87 | 88 | }); 89 | 90 | describe('Ticket', function () { 91 | let demoTicketId; 92 | 93 | before(async function () { 94 | const opts = { 95 | deptid: conf.demoDeptId, 96 | clientid: conf.demoClientId, 97 | subject: 'this is a subject', 98 | message: 'this is a message' 99 | }; 100 | 101 | const res = await conf.whmcs.support.openTicket(opts); 102 | expect(res).to.have.a.property('result').to.equal('success'); 103 | expect(res).to.have.a.property('id').to.not.be.null; 104 | expect(res).to.have.a.property('tid').to.not.be.null; 105 | expect(res).to.have.a.property('c').to.not.be.null; 106 | demoTicketId = res.id; 107 | }); 108 | 109 | it('should add a note to the ticket', async function () { 110 | const addOpts = { 111 | message: 'this is a ticket note', 112 | ticketid: demoTicketId 113 | }; 114 | 115 | const addRes = await conf.whmcs.support.addTicketNote(addOpts); 116 | expect(addRes).to.have.a.property('result').to.equal('success'); 117 | }); 118 | 119 | it('should add a reply to the ticket', async function () { 120 | const opts = { 121 | ticketid: demoTicketId, 122 | clientid: conf.demoClientId, 123 | message: 'this is a new reply' 124 | }; 125 | 126 | const res = await conf.whmcs.support.addTicketReply(opts); 127 | expect(res).to.have.a.property('result').to.equal('success'); 128 | }); 129 | 130 | it('should update a ticket', async function () { 131 | const opts = { 132 | ticketid: demoTicketId, 133 | subject: 'this is an updated ticket' 134 | }; 135 | 136 | const res = await conf.whmcs.support.updateTicket(opts); 137 | expect(res).to.have.a.property('result').to.equal('success'); 138 | expect(res).to.have.a.property('ticketid').to.equal(demoTicketId); 139 | }); 140 | 141 | it('should create another ticket and merge it', async function () { 142 | const openOpts = { 143 | deptid: process.env.WHMCS_TEST_DEPTID || 1, 144 | clientid: conf.demoClientId, 145 | subject: 'this is another subject', 146 | message: 'this is another message' 147 | }; 148 | 149 | const openRes = await conf.whmcs.support.openTicket(openOpts); 150 | expect(openRes).to.have.a.property('result').to.equal('success'); 151 | expect(openRes).to.have.a.property('id').to.not.be.null; 152 | expect(openRes).to.have.a.property('tid').to.not.be.null; 153 | expect(openRes).to.have.a.property('c').to.not.be.null; 154 | 155 | const mergeOpts = { 156 | ticketid: demoTicketId, 157 | mergeticketids: openRes.id, 158 | newsubject: 'this is a merged ticket' 159 | }; 160 | 161 | const mergeRes = await conf.whmcs.support.mergeTicket(mergeOpts); 162 | expect(mergeRes).to.have.a.property('result').to.equal('success'); 163 | expect(mergeRes).to.have.a.property('ticketid').to.equal(demoTicketId); 164 | }); 165 | 166 | it('should block a ticket sender', async function () { 167 | const opts = { 168 | ticketid: demoTicketId 169 | }; 170 | 171 | try { 172 | const res = await conf.whmcs.support.blockTicketSender(opts); 173 | expect(res).to.have.a.property('result').to.equal('success'); 174 | } catch (e) { 175 | if (e instanceof WhmcsError) { 176 | const possibleErr = ['A Client Cannot Be Blocked']; 177 | expect(possibleErr.some(err => { 178 | return e.message.indexOf(err) > -1; 179 | })).to.be.true; 180 | } else { 181 | throw e; 182 | } 183 | } 184 | }); 185 | 186 | describe('Ticket reply', function () { 187 | let demoReplyId; 188 | 189 | before(async function () { 190 | const replyOpts = { 191 | ticketid: demoTicketId, 192 | clientid: conf.demoClientId, 193 | message: 'this is a new reply' 194 | }; 195 | 196 | const replyRes = await conf.whmcs.support.addTicketReply(replyOpts); 197 | expect(replyRes).to.have.a.property('result').to.equal('success'); 198 | 199 | const getOpts = { 200 | ticketid: demoTicketId 201 | }; 202 | 203 | const getRes = await conf.whmcs.tickets.getTicket(getOpts); 204 | expect(getRes).to.have.a.property('result').to.equal('success'); 205 | expect(getRes).to.have.a.property('replies').to.be.an('object').to.have.a.property('reply').to.be.an('array').to.have.length.greaterThan(1); 206 | const lastReply = getRes.replies.reply[getRes.replies.reply.length - 1]; 207 | expect(lastReply).to.have.a.property('replyid').to.not.be.null; 208 | demoReplyId = getRes.replies.reply[1].replyid; 209 | }); 210 | 211 | it('should update a ticket reply', async function () { 212 | const opts = { 213 | replyid: demoReplyId, 214 | message: 'this is an updated reply' 215 | }; 216 | const res = await conf.whmcs.support.updateTicketReply(opts); 217 | expect(res).to.have.a.property('result').to.equal('success'); 218 | }); 219 | 220 | it('should delete a ticket reply', async function () { 221 | const opts = { 222 | ticketid: demoTicketId, 223 | replyid: demoReplyId 224 | }; 225 | const res = await conf.whmcs.support.deleteTicketReply(opts); 226 | expect(res).to.have.a.property('result').to.equal('success'); 227 | }); 228 | }); 229 | 230 | describe('Ticket Note', function () { 231 | let demoTicketNoteId; 232 | 233 | before(async function () { 234 | const addOpts = { 235 | message: 'this is a ticket note', 236 | ticketid: demoTicketId 237 | }; 238 | 239 | const addRes = await conf.whmcs.support.addTicketNote(addOpts); 240 | expect(addRes).to.have.a.property('result').to.equal('success'); 241 | 242 | const ticketOpts = { 243 | ticketid: demoTicketId 244 | }; 245 | 246 | const ticketRes = await conf.whmcs.tickets.getTicket(ticketOpts); 247 | expect(ticketRes).to.have.a.property('result').to.equal('success'); 248 | expect(ticketRes).to.have.a.property('notes').to.be.an('object').to.have.a.property('note').to.be.an('array').to.have.length.greaterThan(0); 249 | expect(ticketRes.notes.note[0]).to.have.a.property('noteid'); 250 | 251 | demoTicketNoteId = ticketRes.notes.note[0].noteid; 252 | }); 253 | 254 | it('should delete a ticket note', async function () { 255 | const deleteOpts = { 256 | noteid: demoTicketNoteId 257 | }; 258 | 259 | const deleteRes = await conf.whmcs.support.deleteTicketNote(deleteOpts); 260 | expect(deleteRes).to.have.a.property('result').to.equal('success'); 261 | }); 262 | 263 | }); 264 | 265 | describe('Ticket removal', function () { 266 | it('should delete a ticket', async function () { 267 | const opts = { 268 | ticketid: demoTicketId 269 | }; 270 | const res = await conf.whmcs.support.deleteTicket(opts); 271 | expect(res).to.have.a.property('result').to.equal('success'); 272 | }); 273 | }); 274 | }); 275 | 276 | }); -------------------------------------------------------------------------------- /test/system.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "System"', function () { 6 | 7 | it('should add an ip to ban list', async function () { 8 | const opts = { 9 | ip: '1.2.3.4', 10 | reason: 'just because', 11 | days: 1 12 | }; 13 | 14 | const res = await conf.whmcs.system.addBannedIp(opts); 15 | expect(res).to.have.a.property('result').to.equal('success'); 16 | }); 17 | 18 | describe('Password encryption', function () { 19 | let demoPassword = 'n2w47bVW#QABW63vVw', 20 | encryptedPassword; 21 | 22 | it('should encrypt a password', async function () { 23 | const opts = { 24 | password2: demoPassword 25 | }; 26 | 27 | const res = await conf.whmcs.system.encryptPassword(opts); 28 | expect(res).to.have.a.property('result').to.equal('success'); 29 | expect(res).to.have.a.property('password').to.be.a.string; 30 | encryptedPassword = res.password; 31 | }); 32 | 33 | it('should decrypt a password', async function () { 34 | const opts = { 35 | password2: encryptedPassword 36 | }; 37 | 38 | const res = await conf.whmcs.system.decryptPassword(opts); 39 | expect(res).to.have.a.property('result').to.equal('success'); 40 | expect(res).to.have.a.property('password').to.equal(demoPassword); 41 | }); 42 | }); 43 | 44 | it('should get activity log', async function () { 45 | const opts = { 46 | limitstart: 0, 47 | limitnum: 1 48 | }; 49 | 50 | const res = await conf.whmcs.system.getActivityLog(opts); 51 | expect(res).to.have.a.property('result').to.equal('success'); 52 | expect(res).to.have.a.property('activity').to.be.an('object'); 53 | expect(res.activity).to.have.a.property('entry').to.be.an('array'); 54 | 55 | }); 56 | 57 | it('should get admin details', async function () { 58 | const res = await conf.whmcs.system.getAdminDetails(); 59 | expect(res).to.have.a.property('result').to.equal('success'); 60 | expect(res).to.have.a.property('adminid').to.not.be.null; 61 | }); 62 | 63 | it('should get admin users', async function () { 64 | const res = await conf.whmcs.system.getAdminUsers(); 65 | expect(res).to.have.a.property('admin_users').to.be.an('array'); 66 | }); 67 | 68 | it('should get automation log', async function () { 69 | const res = await conf.whmcs.system.getAutomationLog(); 70 | expect(res).to.have.a.property('result').to.equal('success'); 71 | expect(res).to.have.a.property('currentDatetime').to.not.be.null; 72 | }); 73 | 74 | it('should get configuration value', async function () { 75 | const opts = { 76 | setting: 'Language' 77 | }; 78 | const res = await conf.whmcs.system.getConfigurationValue(opts); 79 | expect(res).to.have.a.property('result').to.equal('success'); 80 | expect(res).to.have.a.property('setting').to.not.be.null; 81 | 82 | }); 83 | 84 | it('should get currencies', async function () { 85 | const res = await conf.whmcs.system.getCurrencies(); 86 | expect(res).to.have.a.property('result').to.equal('success'); 87 | expect(res).to.have.a.property('currencies').to.be.an.an('object'); 88 | expect(res.currencies).to.have.a.property('currency').to.be.an.an('array') 89 | }); 90 | 91 | it('should get email templates', async function () { 92 | const res = await conf.whmcs.system.getEmailTemplates(); 93 | expect(res).to.have.a.property('result').to.equal('success'); 94 | expect(res).to.have.a.property('emailtemplates').to.be.an.an('object'); 95 | expect(res.emailtemplates).to.have.a.property('emailtemplate').to.be.an.an('array'); 96 | }); 97 | 98 | it('should get payment methods', async function () { 99 | const res = await conf.whmcs.system.getPaymentMethods(); 100 | expect(res).to.have.a.property('result').to.equal('success'); 101 | expect(res).to.have.a.property('paymentmethods').to.be.an.an('object'); 102 | expect(res.paymentmethods).to.have.a.property('paymentmethod').to.be.an.an('array'); 103 | }); 104 | 105 | it('should get staff online', async function () { 106 | const res = await conf.whmcs.system.getStaffOnline(); 107 | expect(res).to.have.a.property('result').to.equal('success'); 108 | expect(res).to.have.a.property('staffonline').to.be.an.an('object'); 109 | expect(res.staffonline).to.have.a.property('staff').to.be.an.an('array'); 110 | }); 111 | 112 | it('should get stats', async function () { 113 | const res = await conf.whmcs.system.getStats(); 114 | expect(res).to.have.a.property('result').to.equal('success'); 115 | expect(res).to.have.a.property('income_today').to.not.be.null; 116 | }); 117 | 118 | it('should get todo items', async function () { 119 | const res = await conf.whmcs.system.getToDoItems(); 120 | expect(res).to.have.a.property('result').to.equal('success'); 121 | }); 122 | 123 | it('should get todo item statuses', async function () { 124 | const res = await conf.whmcs.system.getToDoItemStatuses(); 125 | expect(res).to.have.a.property('result').to.equal('success'); 126 | expect(res).to.have.a.property('todoitemstatuses').to.be.an.an('object'); 127 | expect(res.todoitemstatuses).to.have.a.property('status').to.be.an.an('array'); 128 | }); 129 | 130 | it('should create a log activity', async function () { 131 | const opts = { 132 | clientid: conf.demoClientId, 133 | description: 'log activity test' 134 | }; 135 | const res = await conf.whmcs.system.logActivity(opts); 136 | expect(res).to.have.a.property('result').to.equal('success'); 137 | }); 138 | 139 | it('should send an admin email notification', async function () { 140 | const opts = { 141 | customsubject: 'notification test', 142 | custommessage: 'this is a notification test' 143 | }; 144 | const res = await conf.whmcs.system.sendAdminEmail(opts); 145 | expect(res).to.have.a.property('result').to.equal('success'); 146 | }); 147 | 148 | it('should send a client email notification', async function () { 149 | const opts = { 150 | id: conf.demoClientId, 151 | customsubject: 'notification test', 152 | custommessage: 'this is a notification test', 153 | customtype: 'general' 154 | }; 155 | const res = await conf.whmcs.system.sendEmail(opts); 156 | expect(res).to.have.a.property('result').to.equal('success'); 157 | }); 158 | 159 | it('should set a configuration value', async function () { 160 | const opts = { 161 | setting: 'CompanyName', 162 | value: 'My company' 163 | }; 164 | let res; 165 | 166 | try { 167 | res = await conf.whmcs.system.setConfigurationValue(opts); 168 | expect(res).to.have.a.property('result').to.equal('success'); 169 | } catch (e) { 170 | if (e instanceof WhmcsError) { 171 | const possibleErr = ['API Command Restricted to Internal API']; 172 | expect(possibleErr.some(err => { 173 | return e.message.indexOf(err) > -1; 174 | })).to.be.true; 175 | } else { 176 | throw e; 177 | } 178 | } 179 | }); 180 | 181 | it('should trigger a custom notification event', async function () { 182 | const opts = { 183 | title: 'Notification test', 184 | message: 'this is a custom notification', 185 | notification_identifier: 'test' 186 | }; 187 | const res = await conf.whmcs.system.triggerNotificationEvent(opts); 188 | expect(res).to.have.a.property('result').to.equal('success'); 189 | }); 190 | 191 | it('should update admin notes', async function () { 192 | const opts = { 193 | notes: 'This is a note' 194 | }; 195 | const res = await conf.whmcs.system.updateAdminNotes(opts); 196 | expect(res).to.have.a.property('result').to.equal('success'); 197 | }); 198 | 199 | describe('Announcements', function () { 200 | let demoAnnouncementId; 201 | 202 | before(async function () { 203 | const opts = { 204 | date: '1969-07-11', 205 | title: 'There\'s something wrong', 206 | announcement: 'Your circuit\'s dead' 207 | }; 208 | 209 | const res = await conf.whmcs.support.addAnnouncement(opts); 210 | expect(res).to.have.a.property('result').to.equal('success'); 211 | expect(res).to.have.a.property('announcementid').to.not.be.null; 212 | demoAnnouncementId = res.announcementid; 213 | }); 214 | 215 | it('should update an announcement', async function () { 216 | const opts = { 217 | announcementid: demoAnnouncementId, 218 | title: 'Can you hear me Major Tom?' 219 | }; 220 | const res = await conf.whmcs.system.updateAnnouncement(opts); 221 | expect(res).to.have.a.property('result').to.equal('success'); 222 | }); 223 | }); 224 | 225 | it('should get whmcs details', async function () { 226 | const res = await conf.whmcs.system.whmcsDetails(); 227 | expect(res).to.have.a.property('result').to.equal('success'); 228 | expect(res).to.have.a.property('whmcs').to.not.be.null; 229 | }); 230 | }); -------------------------------------------------------------------------------- /test/tickets.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Tickets"', function () { 6 | 7 | it('should get support departments', async function () { 8 | const res = await conf.whmcs.tickets.getSupportDepartments(); 9 | expect(res).to.have.a.property('result').to.equal('success'); 10 | expect(res).to.have.a.property('totalresults').to.not.be.null; 11 | if (parseInt(res.totalresults) > 0) { 12 | expect(res).to.have.a.property('departments').to.be.an('object'); 13 | expect(res.departments).to.have.a.property('department').to.be.an('array'); 14 | } 15 | }); 16 | 17 | it('should get support statuses', async function () { 18 | const res = await conf.whmcs.tickets.getSupportStatuses(); 19 | expect(res).to.have.a.property('result').to.equal('success'); 20 | expect(res).to.have.a.property('totalresults').to.not.be.null; 21 | if (parseInt(res.totalresults) > 0) { 22 | expect(res).to.have.a.property('statuses').to.be.an('object') 23 | .to.have.a.property('status').to.be.an('array'); 24 | } 25 | }); 26 | 27 | it('should get support statuses', async function () { 28 | const res = await conf.whmcs.tickets.getTicketCounts(); 29 | expect(res).to.have.a.property('result').to.equal('success'); 30 | expect(res).to.have.a.property('allActive').to.not.be.null; 31 | }); 32 | 33 | it('should get predefined cats', async function () { 34 | const res = await conf.whmcs.tickets.getTicketPredefinedCats(); 35 | expect(res).to.have.a.property('result').to.equal('success'); 36 | expect(res).to.have.a.property('totalresults').to.not.be.null; 37 | if (parseInt(res.totalresults) > 0) { 38 | expect(res).to.have.a.property('categories').to.be.an('object') 39 | .to.have.a.property('category').to.be.an('array'); 40 | } 41 | }); 42 | 43 | it('should get predefined replies', async function () { 44 | const res = await conf.whmcs.tickets.getTicketPredefinedReplies(); 45 | expect(res).to.have.a.property('result').to.equal('success'); 46 | expect(res).to.have.a.property('totalresults').to.not.be.null; 47 | if (parseInt(res.totalresults) > 0) { 48 | expect(res).to.have.a.property('predefinedreplies').to.be.an('object') 49 | .to.have.a.property('predefinedreply').to.be.an('array'); 50 | } 51 | }); 52 | 53 | describe('Ticket', function () { 54 | let demoTicketId; 55 | 56 | before(async function () { 57 | const opts = { 58 | deptid: conf.demoDeptId, 59 | clientid: conf.demoClientId, 60 | subject: 'this is a subject', 61 | message: 'this is a message' 62 | }; 63 | 64 | const res = await conf.whmcs.support.openTicket(opts); 65 | expect(res).to.have.a.property('result').to.equal('success'); 66 | expect(res).to.have.a.property('id').to.not.be.null; 67 | demoTicketId = res.id; 68 | }); 69 | 70 | it('should get tickets', async function () { 71 | const opts = { 72 | clientid: conf.demoClientId, 73 | ignore_dept_assignments: true 74 | }; 75 | 76 | const res = await conf.whmcs.tickets.getTickets(opts); 77 | expect(res).to.have.a.property('result').to.equal('success'); 78 | expect(res).to.have.a.property('tickets').to.be.an('object') 79 | .to.have.a.property('ticket').to.be.an('array'); 80 | }); 81 | 82 | it('should get ticket notes', async function () { 83 | const opts = { 84 | ticketid: demoTicketId 85 | }; 86 | 87 | const res = await conf.whmcs.tickets.getTicketNotes(opts); 88 | expect(res).to.have.a.property('result').to.equal('success'); 89 | expect(res).to.have.a.property('notes').to.be.an('object'); 90 | expect(res.notes).to.have.a.property('note').to.be.an('array'); 91 | }); 92 | 93 | it('should get ticket details by ticket id', async function () { 94 | const opts = { 95 | ticketid: demoTicketId 96 | }; 97 | 98 | const res = await conf.whmcs.tickets.getTicket(opts); 99 | expect(res).to.have.a.property('result').to.equal('success'); 100 | expect(res).to.have.a.property('id').to.equal(demoTicketId); 101 | }); 102 | 103 | it('should get ticket attachment', async function () { 104 | const opts = { 105 | relatedid: demoTicketId, 106 | type: 'ticket', 107 | index: 0 108 | }; 109 | 110 | try { 111 | const res = await conf.whmcs.tickets.getTicketAttachment(opts); 112 | expect(res).to.have.a.property('result').to.equal('success'); 113 | } catch (e) { 114 | if (e instanceof WhmcsError) { 115 | expect(e.message).to.have.string('No Attachments Found'); 116 | } else { 117 | throw e; 118 | } 119 | } 120 | }); 121 | 122 | }); 123 | }); -------------------------------------------------------------------------------- /test/users.js: -------------------------------------------------------------------------------- 1 | const expect = require('chai').expect, 2 | conf = require('./conf'), 3 | WhmcsError = require('../lib/whmcserror'); 4 | 5 | describe('Module "Users"', function () { 6 | it('should send an invite to manage a client', async function () { 7 | const opts = { 8 | client_id: conf.demoClientId, 9 | email: 'johndoefriend@john.doe', 10 | permissions: 'products,domains' 11 | } 12 | const res = await conf.whmcs.users.createClientInvite(opts); 13 | expect(res).to.have.a.property('result').to.equal('success'); 14 | }); 15 | 16 | it('should get a list of permissions that can be used when creating a user', async function () { 17 | const res = await conf.whmcs.users.getPermissionsList(); 18 | expect(res).to.have.a.property('permissions').to.be.an('object'); 19 | expect(res.permissions).to.have.a.property('permission').to.be.an('array').to.have.length.above(0); 20 | }); 21 | 22 | it('should get the permissions of an user, for a client', async function () { 23 | const opts = { 24 | user_id: conf.demoUserId, 25 | client_id: conf.demoClientId 26 | }; 27 | const res = await conf.whmcs.users.getUserPermissions(opts); 28 | expect(res).to.have.a.property('result').to.equal('success'); 29 | }); 30 | 31 | it('should get users according to search limit', async function () { 32 | const opts = { 33 | limitstart: 0, 34 | limitnum: 25 35 | }; 36 | const res = await conf.whmcs.users.getUsers(opts); 37 | expect(res).to.have.a.property('result').to.equal('success'); 38 | expect(res).to.have.a.property('users').to.be.an('array') 39 | expect(res.users).to.have.length.above(0); 40 | expect(res.users).to.have.length.below(26); 41 | }); 42 | 43 | it('should start the password reset process for an user, by user id', async function () { 44 | const opts = { 45 | id: conf.demoUserId 46 | }; 47 | const res = await conf.whmcs.users.resetPassword(opts); 48 | expect(res).to.have.a.property('result').to.equal('success'); 49 | }); 50 | 51 | it('should update an user', async function () { 52 | const opts = { 53 | user_id: conf.demoUserId, 54 | lastname: 'updated lastname' 55 | }; 56 | const res = await conf.whmcs.users.updateUser(opts); 57 | expect(res).to.have.a.property('result').to.equal('success'); 58 | }); 59 | 60 | it('should get an user by email', async function () { 61 | const opts = { 62 | search: 'johndoe@john.doe' 63 | } 64 | const res = await conf.whmcs.users.getUsers(opts); 65 | expect(res).to.have.a.property('result').to.equal('success'); 66 | expect(res).to.have.a.property('numreturned').to.equal(1); 67 | expect(res).to.have.a.property('users'); 68 | expect(res.users).to.be.an('array'); 69 | expect(res.users).to.have.lengthOf(1); 70 | }); 71 | }); -------------------------------------------------------------------------------- /whmcs.js: -------------------------------------------------------------------------------- 1 | const WhmcsHttpClient = require('./lib/whmcshttpclient'); 2 | const modules = require('./modules/index'); 3 | 4 | class WHMCS { 5 | /** 6 | * Creates a WHMCS object 7 | * @param {Object} options Configuration parameters (key-value pairs) 8 | */ 9 | constructor(options) { 10 | this.whmcsHttpClient = new WhmcsHttpClient(options); 11 | 12 | this.orders = new modules.Orders(this.whmcsHttpClient); 13 | this.billing = new modules.Billing(this.whmcsHttpClient); 14 | this.module = new modules.Module(this.whmcsHttpClient); 15 | this.support = new modules.Support(this.whmcsHttpClient); 16 | this.system = new modules.System(this.whmcsHttpClient); 17 | this.client = new modules.Client(this.whmcsHttpClient); 18 | this.products = new modules.Products(this.whmcsHttpClient); 19 | this.projectManagement = new modules.ProjectManagement(this.whmcsHttpClient); 20 | this.users = new modules.Users(this.whmcsHttpClient); 21 | this.affiliates = new modules.Affiliates(this.whmcsHttpClient); 22 | this.authentication = new modules.Authentication(this.whmcsHttpClient); 23 | this.domains = new modules.Domains(this.whmcsHttpClient); 24 | this.servers = new modules.Servers(this.whmcsHttpClient); 25 | this.tickets = new modules.Tickets(this.whmcsHttpClient); 26 | this.service = new modules.Service(this.whmcsHttpClient); 27 | this.addons = new modules.Addons(this.whmcsHttpClient); 28 | } 29 | 30 | /** 31 | * Executes an action in WHMCS. You can use this to execute an action that is not defined in the pre-loaded modules. 32 | * @param {String} action Command name 33 | * @param {Object} parameters Request parameters (key-value pairs) 34 | * @param {Function} callback Optional callback. If not set the method returns a Promise. 35 | */ 36 | callApi(action, parameters, callback) { 37 | return this.whmcsHttpClient.callApi(action, parameters, callback); 38 | }; 39 | } 40 | 41 | module.exports = WHMCS; --------------------------------------------------------------------------------