├── README.md └── includes ├── api ├── addcreditapi.php ├── addpromocode.php ├── getproductsactive.php ├── getproductsgroups.php └── paymentdata.php └── hooks └── customapi_register.php /README.md: -------------------------------------------------------------------------------- 1 | # WHMCS CUSTOM API's Solutions 2 | 3 | Currently WHMCS API is very limited and doesnt provide a full experience to comunicate with it. 4 | 5 | 6 | 7 | This project consists of sharing custom API solutions: 8 | 9 | ### Currently Available: 10 | - GetProductsActive 11 | - AddCreditApi 12 | - GetProductsGroups 13 | - PaymentData 14 | - AddPromoCode 15 | 16 | ### Register API's in WHMCS system to be used in Role Management 17 | 18 | Add the following hook file in /includes/hooks/ directory. Make your changes to fit your group needs. 19 | 20 | ##### GetProductsActive 21 | 22 | Currently WHMCS API GetProducts [api-reference/getproducts](https://developers.whmcs.com/api-reference/getproducts/) retrieves all products and no information regarding if the product is active or not. 23 | 24 | So I just created my own API call to handle this and only retrieve the visible (not hidden) products. 25 | 26 | Just upload to /includes/api . 27 | 28 | ##### Request Parameters "GetProductsActive" 29 | 30 | | Parameter | Type | Description | Required | 31 | | ------ | ------ | ------ | ------ | 32 | | action | string | “GetProductsActive” | Required | 33 | | pid | int | Obtain a specific product id configuration. Can be a list of ids comma separated | optional | 34 | | gid | int | Retrieve products in a specific group id | optional | 35 | 36 | ##### Response Parameters 37 | 38 | | Parameter | Type | Description 39 | | ------ | ------ | ------ | 40 | | result | string | The result of the operation: success or error | 41 | | totalresults | int | The total number of results available | 42 | | startnumber | int | The starting number for the returned results | 43 | | numreturned | int | The number of results returned | 44 | | products | array | An array of products matching the criteria passed | 45 | 46 | ### Example Request (Local API) 47 | 48 | ```php 49 | $command = 'GetProductsActive'; 50 | $postData = array( 51 | 'pid' => '1', // or gid => '1' or both 52 | ); 53 | $adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later 54 | 55 | $results = localAPI($command, $postData, $adminUsername); 56 | print_r($results); 57 | ``` 58 | 59 | ### Example Request (CURL) 60 | 61 | ```php 62 | $ch = curl_init(); 63 | curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php'); 64 | curl_setopt($ch, CURLOPT_POST, 1); 65 | curl_setopt($ch, CURLOPT_POSTFIELDS, 66 | http_build_query( 67 | array( 68 | 'action' => 'GetProductsActive', 69 | // See https://developers.whmcs.com/api/authentication 70 | 'username' => 'IDENTIFIER_OR_ADMIN_USERNAME', 71 | 'password' => 'SECRET_OR_HASHED_PASSWORD', 72 | 'pid' => '1', 73 | 'responsetype' => 'json', 74 | ) 75 | ) 76 | ); 77 | $response = curl_exec($ch); 78 | curl_close($ch); 79 | ``` 80 | 81 | #### Example output: 82 | ```json 83 | { 84 | "result": "success", 85 | "totalresults": 1, 86 | "products": { 87 | "product": [ 88 | { 89 | "pid": "123", 90 | "gid": "", 91 | "type": "", 92 | "name": "XPTO", 93 | "description": "", 94 | "module": "cpanel", 95 | "paytype": "recurring", 96 | "pricing": { 97 | "EUR": { 98 | "prefix": "", 99 | "suffix": "€", 100 | "msetupfee": "0.00", 101 | "qsetupfee": "0.00", 102 | "ssetupfee": "0.00", 103 | "asetupfee": "0.00", 104 | "bsetupfee": "0.00", 105 | "tsetupfee": "0.00", 106 | "monthly": "-1.00", 107 | "quarterly": "-1.00", 108 | "semiannually": "-1.00", 109 | "annually": "40.00", 110 | "biennially": "76.00", 111 | "triennially": "-1.00" 112 | } 113 | }, 114 | "customfields": { 115 | "customfield": [] 116 | }, 117 | "configoptions": { 118 | "configoption": [{}] 119 | } 120 | } 121 | } 122 | } 123 | ``` 124 | 125 | ##### AddCreditApi 126 | 127 | Currently WHMCS API AddCredit [api-reference/addcredit](https://developers.whmcs.com/api-reference/addcredit/) allows to add credit to a given client. 128 | 129 | I needed an API request that allowed me to charge a client for credit and after successful payment credit be added automatically. 130 | 131 | Just upload to /includes/api . 132 | 133 | ##### Request Parameters "AddCreditApi" 134 | 135 | | Parameter | Type | Description | Required | 136 | | ------ | ------ | ------ | ------ | 137 | | action | string | “AddCreditApi” | Required | 138 | | userid | int | The userid of client to make credit request | required | 139 | | itemamount | float | The amount of credit to add or remove. Must be a positive value. | required | 140 | | paymentmethod | string | The payment method to charge with | required 141 | 142 | ##### Response Parameters 143 | 144 | | Parameter | Type | Description 145 | | ------ | ------ | ------ | 146 | | result | string | The result of the operation: success or error | 147 | | invoiceid | int | invoice Number | 148 | | status | string | The status os the invoice | 149 | | paymentMethod | array | Returns the payment information | 150 | 151 | ### Example Request (Local API) 152 | 153 | ```php 154 | $command = 'AddCreditApi'; 155 | $postData = array( 156 | 'userid' => '1', 157 | 'itemamount' => '50', 158 | 'paymentmethod' => 'paypal', 159 | ); 160 | $adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later 161 | 162 | $results = localAPI($command, $postData, $adminUsername); 163 | print_r($results); 164 | ``` 165 | 166 | ### Example Request (CURL) 167 | 168 | ```php 169 | $ch = curl_init(); 170 | curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php'); 171 | curl_setopt($ch, CURLOPT_POST, 1); 172 | curl_setopt($ch, CURLOPT_POSTFIELDS, 173 | http_build_query( 174 | array( 175 | 'action' => 'AddCreditApi', 176 | // See https://developers.whmcs.com/api/authentication 177 | 'username' => 'IDENTIFIER_OR_ADMIN_USERNAME', 178 | 'password' => 'SECRET_OR_HASHED_PASSWORD', 179 | 'userid' => '1', 180 | 'itemamount' => '50', 181 | 'paymentmethod' => 'paypal', 182 | 'responsetype' => 'json', 183 | ) 184 | ) 185 | ); 186 | $response = curl_exec($ch); 187 | curl_close($ch); 188 | ``` 189 | 190 | #### Example output: 191 | ```json 192 | { 193 | "result": "success", 194 | "invoiceid": 129, 195 | "status": "Unpaid", 196 | "paymentMethod": { 197 | "amount": "52", 198 | "data": "Bank: XPTO Bank\r\n" 199 | } 200 | } 201 | ``` 202 | 203 | ##### GetProductsGroups 204 | 205 | Currently WHMCS API has no method to retrieve your current product groups. 206 | 207 | I needed an API request that allowed me to retrive the products groups I have ACTIVE in WHMCS or just a specific one for some future porpuse. 208 | 209 | Just upload to /includes/api . 210 | 211 | ##### Request Parameters "GetProductsGroups" 212 | 213 | | Parameter | Type | Description | Required | 214 | | ------ | ------ | ------ | ------ | 215 | | action | string | “GetProductsGroups” | Required | 216 | | gid | int | The group id to get information of | optional | 217 | 218 | ##### Response Parameters 219 | 220 | | Parameter | Type | Description 221 | | ------ | ------ | ------ | 222 | | result | string | The result of the operation: success or error | 223 | | groups | array | Returns the groups information | 224 | 225 | ### Example Request (Local API) 226 | 227 | ```php 228 | $command = 'GetProductsGroups'; 229 | $postData = array( 230 | 'gid' => '1', // optional data 231 | ); 232 | $adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later 233 | 234 | $results = localAPI($command, $postData, $adminUsername); 235 | print_r($results); 236 | ``` 237 | 238 | ### Example Request (CURL) 239 | 240 | ```php 241 | $ch = curl_init(); 242 | curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php'); 243 | curl_setopt($ch, CURLOPT_POST, 1); 244 | curl_setopt($ch, CURLOPT_POSTFIELDS, 245 | http_build_query( 246 | array( 247 | 'action' => 'GetProductsGroups', 248 | // See https://developers.whmcs.com/api/authentication 249 | 'username' => 'IDENTIFIER_OR_ADMIN_USERNAME', 250 | 'password' => 'SECRET_OR_HASHED_PASSWORD', 251 | 'gid' => '1', // Optional 252 | 'responsetype' => 'json', 253 | ) 254 | ) 255 | ); 256 | $response = curl_exec($ch); 257 | curl_close($ch); 258 | ``` 259 | 260 | #### Example output: 261 | ```json 262 | { 263 | "result": "success", 264 | "groups": [ 265 | { 266 | "id": "1", 267 | "name": "Web Hosting - Linux" 268 | } 269 | ] 270 | } 271 | ``` 272 | 273 | ##### PaymentData 274 | 275 | Currently WHMCS API GetInvoice [api-reference/getinvoice](https://developers.whmcs.com/api-reference/getinvoice/) retrieves a specific invoice. 276 | 277 | I needed a solution to retrieve the payment information from it 278 | 279 | Just upload to /includes/api . 280 | 281 | ##### Request Parameters "PaymentData" 282 | 283 | | Parameter | Type | Description | Required | 284 | | ------ | ------ | ------ | ------ | 285 | | action | string | “GetProductsActive” | Required | 286 | | invoiceid | int | The ID of the invoice to retrieve | Required | 287 | 288 | ##### Response Parameters 289 | 290 | | Parameter | Type | Description 291 | | ------ | ------ | ------ | 292 | | result | string | The result of the operation: success or error | 293 | | products | array | An array of invoice data and payment method | 294 | 295 | ### Example Request (Local API) 296 | 297 | ```php 298 | $command = 'PaymentData'; 299 | $postData = array( 300 | 'invoiceid' => '66', 301 | ); 302 | $adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later 303 | 304 | $results = localAPI($command, $postData, $adminUsername); 305 | print_r($results); 306 | ``` 307 | 308 | ### Example Request (CURL) 309 | 310 | ```php 311 | $ch = curl_init(); 312 | curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php'); 313 | curl_setopt($ch, CURLOPT_POST, 1); 314 | curl_setopt($ch, CURLOPT_POSTFIELDS, 315 | http_build_query( 316 | array( 317 | 'action' => 'PaymentData', 318 | // See https://developers.whmcs.com/api/authentication 319 | 'username' => 'IDENTIFIER_OR_ADMIN_USERNAME', 320 | 'password' => 'SECRET_OR_HASHED_PASSWORD', 321 | 'invoiceid' => '66', 322 | 'responsetype' => 'json', 323 | ) 324 | ) 325 | ); 326 | $response = curl_exec($ch); 327 | curl_close($ch); 328 | ``` 329 | 330 | #### Example output: 331 | ```json 332 | { 333 | "result": "success", 334 | "paymentdata": { 335 | "order": { 336 | "result": "success", 337 | "invoiceid": "66", 338 | "invoicenum": "", 339 | "userid": "1", 340 | "date": "2019-07-16", 341 | "duedate": "2019-07-16", 342 | "datepaid": "0000-00-00 00:00:00", 343 | "lastcaptureattempt": "0000-00-00 00:00:00", 344 | "subtotal": "11.99", 345 | "credit": "0.00", 346 | "tax": "2.76", 347 | "tax2": "0.00", 348 | "total": "14.75", 349 | "balance": "14.75", 350 | "taxrate": "23.00", 351 | "taxrate2": "0.00", 352 | "status": "Unpaid", 353 | "paymentmethod": "banktransfer", 354 | "notes": "", 355 | "ccgateway": false, 356 | "items": { 357 | "item": [ 358 | { 359 | "id": "121", 360 | "type": "DomainRegister", 361 | "relid": "37", 362 | "description": "Register Domain - samplesthis.com - 1 year) (16/07/2019 - 15/07/2020)\n", 363 | "amount": "14.75", 364 | "taxed": "1" 365 | } 366 | ] 367 | }, 368 | "transactions": "" 369 | }, 370 | "amount": "14.75", 371 | "data": "Bank XPTO" 372 | } 373 | } 374 | ``` 375 | 376 | ##### Request Parameters "addPromoCode" 377 | 378 | | Parameter | Type | Description | Required | 379 | | -------------- | ------ | --------------------------------------------------------- | -------- | 380 | | action | string | Either "create" (to create a new promotion) or "update" (to update an existing promotion) | Required | 381 | | code | string | The promotion code | Required | 382 | | type | string | The discount type, either 'percentage' or 'fixed' | Required | 383 | | value | float | The discount value | Required | 384 | | cycles | string | The billing cycles to which the promo code applies (e.g., 'Monthly') | Optional | 385 | | appliesto | string | A comma-separated list of product IDs the promotion applies to | Optional | 386 | | expirationdate | string | The promotion code expiration date in the format 'YYYY-MM-DD' | Optional | 387 | | maxuses | int | The maximum number of times the promo code can be used | Optional | 388 | | promotionid | int | The ID of the promotion to update (only required for 'update' action) | Conditional | 389 | 390 | ##### Response Parameters 391 | 392 | | Parameter | Type | Description | 393 | | ---------- | ------ | --------------------------------------- | 394 | | result | string | The result of the operation: success or error | 395 | | message | string | A message describing the result of the API call | 396 | | promotionid | int | The ID of the created or updated promotion | 397 | 398 | ### Example Request (Local API) 399 | 400 | ```php 401 | $command = 'addPromoCode'; 402 | $postData = array( 403 | 'action' => 'create', 404 | 'code' => 'PROMO10', 405 | 'type' => 'percentage', 406 | 'value' => '10', 407 | 'cycles' => 'Monthly', 408 | 'appliesto' => '1,2,3', 409 | 'expirationdate' => '2023-12-31', 410 | 'maxuses' => '50', 411 | ); 412 | $adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later 413 | 414 | $results = localAPI($command, $postData, $adminUsername); 415 | print_r($results); 416 | ``` 417 | 418 | #### Example JSON Output for 'create' action: 419 | 420 | ```json 421 | { 422 | "result": "success", 423 | "message": "Promotion code created successfully", 424 | "promotionid": 1234 425 | } 426 | 427 | { 428 | "result": "success", 429 | "message": "Promotion code updated successfully", 430 | "promotionid": 1234 431 | } 432 | ``` 433 | 434 | ### Todos 435 | 436 | - Share MORE API's 437 | - Wait for feedback and other developers shares 438 | 439 | License 440 | ---- 441 | 442 | MIT 443 | 444 | 445 | **Free Software, Hell Yeah!** 446 | -------------------------------------------------------------------------------- /includes/api/addcreditapi.php: -------------------------------------------------------------------------------- 1 | $postFields->userid, 38 | //'status' => 'Unpaid', 39 | 'sendinvoice' => '1', 40 | 'paymentmethod' => $postFields->paymentmethod, 41 | 'notes' => 'Credit request via API', 42 | 'itemdescription1' => 'Add Credtit', // OR other custom message 43 | 'itemamount1' => $postFields->itemamount, // Total amount to be charged 44 | ); 45 | 46 | $results = localAPI($command, $postData); 47 | 48 | //Necessary to add "AddFunds" to table row so that WHMCS process payment accordingly and adds the amount to credit 49 | $update_result = Capsule::table('tblinvoiceitems') 50 | ->where('invoiceid', $results['invoiceid']) 51 | ->update( 52 | [ 53 | 'type' => 'AddFunds', 54 | ] 55 | ); 56 | 57 | $ds_getPaymentData = array( 58 | 'invoiceid' => $results['invoiceid'], 59 | 'paymentmethod' => $postFields->paymentmethod, 60 | 'amount' => $postFields->itemamount 61 | ); 62 | 63 | $results['paymentMethod'] = ds_getPaymentData($ds_getPaymentData); //Returns the Payment data information 64 | 65 | 66 | $apiresults = $results; 67 | } catch (Exception $e) { 68 | $apiresults = array("result" => "error", "message" => $e->getMessage()); 69 | } 70 | 71 | 72 | function ds_getPaymentData($data) 73 | { 74 | 75 | $paymentmethod = $data['paymentmethod']; 76 | $invoiceid = $data['invoiceid']; 77 | 78 | $paymentdata = array( 79 | 'amount' => $data['amount'], 80 | ); 81 | 82 | $url = Capsule::table('tblconfiguration') 83 | ->where('setting', 'SystemURL') 84 | ->first(); 85 | 86 | //Customize your payment gateway information for retrieval 87 | switch ($paymentmethod) { 88 | case 'stripe': 89 | 90 | $paymentdata['data'] = ''; 91 | break; 92 | case 'paypal': 93 | $paymentdata['data'] = $url->value . 'viewinvoice.php?id=' . $invoiceid; 94 | break; 95 | default: 96 | $query = Capsule::table('tblpaymentgateways')->select('value')->where('setting', 'instructions')->where('gateway', $paymentmethod); 97 | $results = $query->get(); 98 | 99 | $paymentdata['data'] = $results[0]->value; 100 | 101 | break; 102 | } 103 | 104 | return $paymentdata; 105 | } 106 | -------------------------------------------------------------------------------- /includes/api/addpromocode.php: -------------------------------------------------------------------------------- 1 | array()); 12 | 13 | if (isset($vars['cmd'])) { 14 | // Local API mode 15 | $array['action'] = $vars['cmd']; 16 | $array['params'] = (object) $vars['apivalues1']; 17 | $array['adminuser'] = $vars['adminuser']; 18 | } else { 19 | // Post CURL mode 20 | $array['action'] = $vars['action']; 21 | unset($vars['_POST']['username']); 22 | unset($vars['_POST']['password']); 23 | unset($vars['_POST']['action']); 24 | $array['params'] = (object) $vars; 25 | } 26 | 27 | return (object) $array; 28 | } 29 | 30 | try { 31 | $post_fields = get_env(get_defined_vars()); 32 | 33 | if ($post_fields->action === 'create') { 34 | $command = 'AddPromo'; 35 | $postData = array( 36 | 'code' => $post_fields->params->code, 37 | 'type' => $post_fields->params->type, 38 | 'value' => $post_fields->params->value, 39 | 'cycles' => $post_fields->params->cycles, 40 | 'appliesto' => $post_fields->params->appliesto, 41 | 'expirationdate' => $post_fields->params->expirationdate, 42 | 'maxuses' => $post_fields->params->maxuses, 43 | ); 44 | } elseif ($post_fields->action === 'update') { 45 | $command = 'UpdatePromo'; 46 | $postData = array( 47 | 'promotionid' => $post_fields->params->promotionid, 48 | 'code' => $post_fields->params->code, 49 | 'type' => $post_fields->params->type, 50 | 'value' => $post_fields->params->value, 51 | 'cycles' => $post_fields->params->cycles, 52 | 'appliesto' => $post_fields->params->appliesto, 53 | 'expirationdate' => $post_fields->params->expirationdate, 54 | 'maxuses' => $post_fields->params->maxuses, 55 | ); 56 | } else { 57 | throw new Exception('Invalid action. Use either "create" or "update".'); 58 | } 59 | 60 | $results = localAPI($command, $postData); 61 | 62 | if ($results['result'] !== 'success') { 63 | throw new Exception('API call failed: ' . $results['message']); 64 | } 65 | 66 | $apiresults = $results; 67 | } catch (Exception $e) { 68 | $apiresults = array("result" => "error", "message" => $e->getMessage()); 69 | } 70 | -------------------------------------------------------------------------------- /includes/api/getproductsactive.php: -------------------------------------------------------------------------------- 1 | array(), 'gid' => array()); 12 | 13 | if (isset($vars['cmd'])) { 14 | //Local API mode 15 | $array['action'] = $vars['cmd']; 16 | $array['params'] = (object) $vars['apivalues1']; 17 | $array['adminuser'] = $vars['adminuser']; 18 | } else { 19 | //Post CURL mode 20 | $array['action'] = $vars['action']; 21 | unset($vars['_POST']['username']); 22 | unset($vars['_POST']['password']); 23 | unset($vars['_POST']['action']); 24 | $array['gid'] = $vars['gid']; 25 | $array['pid'] = $vars['pid']; 26 | } 27 | return (object) $array; 28 | } 29 | 30 | try { 31 | 32 | $post_fields = get_env(get_defined_vars()); 33 | 34 | $command = 'GetProducts'; 35 | 36 | $postData = array( 37 | 'gid' => $post_fields->gid, 38 | 'pid' => $post_fields->pid 39 | ); 40 | 41 | $results = localAPI($command, $postData); 42 | 43 | $query = Capsule::table('tblproducts')->select('id')->where('hidden', true); 44 | 45 | if ($post_fields->gid) 46 | $query->where('gid', $post_fields->gid); 47 | 48 | if ($post_fields->pid) 49 | $query->where('id', $post_fields->pid); 50 | 51 | $qr = $query->get(); 52 | 53 | 54 | foreach ($results['products']['product'] as $key => $value) { 55 | foreach ($qr as $k => $v) { 56 | if ($value['pid'] == $v->id) { 57 | $results['totalresults'] = $results['totalresults'] - 1; 58 | unset($results['products']['product'][$key]); 59 | } 60 | } 61 | } 62 | 63 | $products = array_values($results['products']['product']); 64 | $results['products'] = $products; 65 | if (empty($results)) { 66 | throw new Exception('No products found'); 67 | } 68 | 69 | $apiresults = $results; 70 | } catch (Exception $e) { 71 | $apiresults = array("result" => "error", "message" => $e->getMessage()); 72 | } 73 | -------------------------------------------------------------------------------- /includes/api/getproductsgroups.php: -------------------------------------------------------------------------------- 1 | array(), 'gid' => array()); 12 | 13 | if (isset($vars['cmd'])) { 14 | //Local API mode 15 | $array['action'] = $vars['cmd']; 16 | $array['params'] = (object) $vars['apivalues1']; 17 | $array['adminuser'] = $vars['adminuser']; 18 | } else { 19 | //Post CURL mode 20 | $array['action'] = $vars['action']; 21 | unset($vars['_POST']['username']); 22 | unset($vars['_POST']['password']); 23 | unset($vars['_POST']['action']); 24 | $array['gid'] = $vars['gid']; 25 | } 26 | return (object) $array; 27 | } 28 | 29 | try { 30 | 31 | $post_fields = get_env(get_defined_vars()); 32 | 33 | $query = Capsule::table('tblproductgroups')->select('id', 'name')->where('hidden', false); 34 | 35 | if (isset($post_fields->gid) && $post_fields->gid > 0) 36 | $query->where('id', $post_fields->gid); 37 | 38 | $results = $query->get(); 39 | 40 | if (empty($results)) { 41 | throw new Exception('No groups found'); 42 | } 43 | 44 | $apiresults = array("result" => "success", "groups" => $results); 45 | } catch (Exception $e) { 46 | $apiresults = array("result" => "error", "message" => $e->getMessage()); 47 | } 48 | -------------------------------------------------------------------------------- /includes/api/paymentdata.php: -------------------------------------------------------------------------------- 1 | array(), 'params' => array()); 12 | if (isset($vars['cmd'])) { 13 | //Local API mode 14 | $array['action'] = $vars['cmd']; 15 | $array['params'] = $vars['apivalues1']; 16 | $array['adminuser'] = $vars['adminuser']; 17 | $array['invoiceid'] = $vars['invoiceid']; 18 | } else { 19 | //Post CURL mode 20 | $array['action'] = $vars['action']; 21 | unset($vars['_POST']['username']); 22 | unset($vars['_POST']['password']); 23 | unset($vars['_POST']['action']); 24 | $array['invoiceid'] = $vars['invoiceid']; 25 | } 26 | return $array; 27 | } 28 | 29 | try { 30 | $params = get_env(get_defined_vars()); 31 | 32 | 33 | $command = 'GetInvoice'; 34 | $postData = array( 35 | 'invoiceid' => $params['invoiceid'] 36 | ); 37 | 38 | $results = localAPI($command, $postData); 39 | 40 | $amount = $results['total']; 41 | $paymentmethod = $results['paymentmethod']; 42 | $invoiceid = $params['invoiceid']; 43 | 44 | $paymentdata = array( 45 | 'order' => $results, 46 | 'amount' => $amount, 47 | ); 48 | 49 | $url = Capsule::table('tblconfiguration') 50 | ->where('setting', 'SystemURL') 51 | ->first(); 52 | 53 | //Customize your payment gateway information for retrieval 54 | switch ($paymentmethod) { 55 | case 'stripe': 56 | $paymentdata['data'] = ''; 57 | break; 58 | case 'paypal': 59 | $paymentdata['data'] = $url->value . 'viewinvoice.php?id=' . $invoiceid; 60 | break; 61 | default: 62 | $query = Capsule::table('tblpaymentgateways')->select('value')->where('setting', 'instructions')->where('gateway', $paymentmethod); 63 | $results = $query->get(); 64 | 65 | $paymentdata['data'] = $results[0]->value; 66 | 67 | break; 68 | } 69 | 70 | 71 | $apiresults = array("result" => "success", "paymentdata" => $paymentdata); 72 | } catch (Exception $e) { 73 | $apiresults = array("result" => "error", "message" => $e->getMessage()); 74 | } 75 | 76 | { 77 | "result": "success", 78 | "paymentdata": { 79 | "order": { 80 | "result": "success", 81 | "invoiceid": "66", 82 | "invoicenum": "", 83 | "userid": "1", 84 | "date": "2019-07-16", 85 | "duedate": "2019-07-16", 86 | "datepaid": "0000-00-00 00:00:00", 87 | "lastcaptureattempt": "0000-00-00 00:00:00", 88 | "subtotal": "11.99", 89 | "credit": "0.00", 90 | "tax": "2.76", 91 | "tax2": "0.00", 92 | "total": "14.75", 93 | "balance": "14.75", 94 | "taxrate": "23.00", 95 | "taxrate2": "0.00", 96 | "status": "Unpaid", 97 | "paymentmethod": "banktransfer", 98 | "notes": "", 99 | "ccgateway": false, 100 | "items": { 101 | "item": [ 102 | { 103 | "id": "121", 104 | "type": "DomainRegister", 105 | "relid": "37", 106 | "description": "Register Domain - samplesthis.com - 1 year) (16/07/2019 - 15/07/2020)\n", 107 | "amount": "14.75", 108 | "taxed": "1" 109 | } 110 | ] 111 | }, 112 | "transactions": "" 113 | }, 114 | "amount": "14.75", 115 | "data": "Bank XPTO" 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /includes/hooks/customapi_register.php: -------------------------------------------------------------------------------- 1 | getGroups(); 31 | if (!array_key_exists('ADD_YOUR_GROUP_KEY', $apiCatalogGroups)) 32 | \WHMCS\Api\V1\Catalog::add([], ['ADD_YOUR_GROUP_KEY' => array('name' => 'ADD YOUR GROUP NAME')]); 33 | } 34 | 35 | function apiroles_checkApiOrAdd() 36 | { 37 | $api_files = apiroles_readApiFiles(); 38 | $apiCatalogActions = \WHMCS\Api\V1\Catalog::get()->getActions(); 39 | 40 | foreach ($api_files as $k => $api) { 41 | if (!array_key_exists($api, $apiCatalogActions)) { 42 | \WHMCS\Api\V1\Catalog::add(array($api => array( 43 | 'group' => 'ADD_YOUR_GROUP_KEY', 44 | 'name' => $api, 45 | 'default' => 0 46 | ))); 47 | } 48 | } 49 | } 50 | --------------------------------------------------------------------------------