From bd0889e1fc602527147b638e2603c8e605191339 Mon Sep 17 00:00:00 2001 From: Richard Leishman Date: Wed, 27 Jul 2016 15:58:13 +0100 Subject: [PATCH 1/4] fixed typo causing script to fail --- whmcs.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whmcs.class.php b/whmcs.class.php index 78d4a5b..a0b34da 100644 --- a/whmcs.class.php +++ b/whmcs.class.php @@ -492,7 +492,7 @@ public function createInvoice($data){ } } - for($i = 0; $i < count($data['items']; $i++)){ + for($i = 0; $i < count($data['items']); $i++){ $params['itemdescription' . $i] = $data['items'][$i]['description']; $params['itemamount' . $i] = $data['items'][$i]['amount']; $params['itemtaxed' . $i] = $data['items'][$i]['taxed']; From c0b3c01293d9bcc911088e8a3f9400f1c4ad48c6 Mon Sep 17 00:00:00 2001 From: Richard Leishman Date: Wed, 27 Jul 2016 16:19:53 +0100 Subject: [PATCH 2/4] Fixed lots of warning errors. --- whmcs.class.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/whmcs.class.php b/whmcs.class.php index a0b34da..144c715 100644 --- a/whmcs.class.php +++ b/whmcs.class.php @@ -136,6 +136,8 @@ public function getDomainWHOIS($domainId){ * @link http://docs.whmcs.com/API:Get_Products */ public function getProducts($pid = 0, $gid = 0, $module = null){ + $params = array(); + if($pid > 0){ $params['pid'] = $pid; } @@ -176,7 +178,7 @@ public function getServices($uid = 0, $serviceId = 0, $domain = '', $productId = } $params['limitnum'] = $limit; - $params['limitstart'] = $limitstart; + //$params['limitstart'] = $limitstart; // TODO: Unused variable if($uid > 0){ $params['clientid'] = $uid; @@ -217,6 +219,8 @@ public function getServices($uid = 0, $serviceId = 0, $domain = '', $productId = * @link http://docs.whmcs.com/API:Get_Transactions */ public function getTransactions($uid = 0, $invoiceId = 0, $transactionId = 0){ + $params = array(); + if($uid > 0){ $params['clientid'] = $uid; } @@ -284,6 +288,8 @@ public function getEmails($uid, $filter = '', $filterdate = '', $start = 0, $lim * @link http://docs.whmcs.com/API:Add_Credit */ public function addCredit($data){ + $credit = array(); + $attributes = array("clientid", "description", "amount"); foreach($attributes as $k){ @@ -305,7 +311,7 @@ public function addCredit($data){ /** * Get Credits - * @param id $uid + * @param int $uid * @return object * @link http://docs.whmcs.com/API:Get_Credits */ @@ -350,7 +356,9 @@ public function updateClient($uid = 0, $update){ */ public function addClient($data){ $attributes = array("firstname", "lastname", "companyname", "email", "address1", "address2", "city", "state", "postcode", "country", "phonenumber", "password2", "currency", "clientip", "language", "groupid", "securityqid", "securityqans", "notes", "cctype", "cardnum", "expdate", "startdate", "issuenumber", "customfields", "noemail", "skipvalidation"); - + + $customer = array(); + foreach($attributes as $k){ $customer[$k] = $data[$k]; } @@ -408,6 +416,8 @@ public function getClient($uid = 0, $email = ''){ public function addContact($data){ $attributes = array("clientid", "firstname", "lastname", "companyname", "email", "address1", "address2", "city", "state", "postcode", "country", "phonenumber", "password2", "permissions", "generalemails", "productemails", "domainemails", "invoiceemails", "supportemails", "skipvalidation"); + $contact = array(); + foreach($attributes as $k){ $contact[$k] = $data[$k]; } @@ -486,6 +496,8 @@ public function createInvoice($data){ "taxrate", "taxrate2", "notes", "sendinvoice", "autoapplycredit"); + $params = array(); + foreach($attributes as $a){ if(!empty($params[$a])){ $params[$a] = $data[$a]; @@ -557,7 +569,7 @@ public function getOrders($uid = 0, $orderId = 0, $status = '', $start = 0, $lim } if($orderId > 0){ - $params['id'] = $invoiceId; + $params['id'] = $orderId; } if($status == "Pending" || $status == "Active" || $status == "Fraud" || $status == "Cancelled"){ @@ -695,6 +707,8 @@ public function acceptOrder($orderid, $serverid = null, $serviceusername = null, * @link http://docs.whmcs.com/API:Get_Stats */ public function getStats(){ + $params = array(); + $response = $this->api("getstats", $params); if($response->result == 'error'){ From 9b10b6f236830b21d8c43b44ec420cf51e60621d Mon Sep 17 00:00:00 2001 From: Richard Leishman Date: Sun, 31 Jul 2016 16:58:24 +0100 Subject: [PATCH 3/4] Instead of returning true for authenticate, I return the userID as this can be used for future requests based on this user. Can still check if true or false as anything greater than zero is true. --- whmcs.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whmcs.class.php b/whmcs.class.php index 144c715..600b9b7 100644 --- a/whmcs.class.php +++ b/whmcs.class.php @@ -26,7 +26,7 @@ public function __construct($url = 'http://whmcs.com/include/api.php', $username public function authenticate($username, $password){ $response = $this->api("validatelogin", array("email" => $username, "password2" => $password)); if($response->userid){ - return true; + return $response->userid; // Same as returning true } return false; From 162b69d8344924a865c8be64ef38878c2714c61c Mon Sep 17 00:00:00 2001 From: Richard Leishman Date: Thu, 18 Aug 2016 17:01:55 +0100 Subject: [PATCH 4/4] Get Product Groups - Custom API --- whmcs.class.php | 22 +++++++++++ whmcs/includes/api/getproductgroups.php | 49 +++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 whmcs/includes/api/getproductgroups.php diff --git a/whmcs.class.php b/whmcs.class.php index 600b9b7..574e353 100644 --- a/whmcs.class.php +++ b/whmcs.class.php @@ -126,6 +126,28 @@ public function getDomainWHOIS($domainId){ return $response; } + /** + * Get product groups - Custom API + * @param int $gid + * @return object + * @throws WhmcsException + */ + public function getProductsGroups($gid = 0){ + $params = array(); + + if($gid > 0){ + $params['gid'] = $gid; + } + + $response = $this->api("getproductgroups", $params); + + if($response->result == 'error'){ + throw new WhmcsException("WHMCS complained: ".$response->message); + } + + return $response; + } + /** * Get products * @param int $pid diff --git a/whmcs/includes/api/getproductgroups.php b/whmcs/includes/api/getproductgroups.php new file mode 100644 index 0000000..751e38d --- /dev/null +++ b/whmcs/includes/api/getproductgroups.php @@ -0,0 +1,49 @@ + array(), 'params' => array()); + if (isset($vars['cmd'])) { + //Local API mode + $array['action'] = $vars['cmd']; + $array['params'] = (object)$vars['apivalues1']; + $array['adminuser'] = $vars['adminuser']; + + } else { + //Post CURL mode + $array['action'] = $vars['_POST']['action']; + unset($vars['_POST']['username']); + unset($vars['_POST']['password']); + unset($vars['_POST']['action']); + $array['params'] = (object)$vars['_POST']; + } + return (object)$array; +} + +try { + $vars = get_defined_vars(); + //Get the parameters + $request = get_env($vars); + + $gid = (int)$request->params->gid; + + if ($gid) + $productGroups = Capsule::table('tblproductgroups')->where('id', $gid)->get(); + else + $productGroups = Capsule::table('tblproductgroups')->get(); + + if (count($productGroups)) + $apiresults = array( + "result" => "success", + "productGroups" => $productGroups + ); + else + $apiresults = array( + "result" => "error", + "message" => 'There are no product groups' + ); +} catch (Exception $e) { + $apiresults = array("result" => "error", "message" => $e->getMessage()); +} +?> \ No newline at end of file