Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions whmcs.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -136,6 +158,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;
}
Expand Down Expand Up @@ -176,7 +200,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;
Expand Down Expand Up @@ -217,6 +241,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;
}
Expand Down Expand Up @@ -284,6 +310,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){
Expand All @@ -305,7 +333,7 @@ public function addCredit($data){

/**
* Get Credits
* @param id $uid
* @param int $uid
* @return object
* @link http://docs.whmcs.com/API:Get_Credits
*/
Expand Down Expand Up @@ -350,7 +378,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];
}
Expand Down Expand Up @@ -408,6 +438,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];
}
Expand Down Expand Up @@ -486,13 +518,15 @@ public function createInvoice($data){
"taxrate", "taxrate2", "notes", "sendinvoice",
"autoapplycredit");

$params = array();

foreach($attributes as $a){
if(!empty($params[$a])){
$params[$a] = $data[$a];
}
}

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'];
Expand Down Expand Up @@ -557,7 +591,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"){
Expand Down Expand Up @@ -695,6 +729,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'){
Expand Down
49 changes: 49 additions & 0 deletions whmcs/includes/api/getproductgroups.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Capsule\Manager as Capsule;

function get_env($vars)
{
$array = array('action' => 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());
}
?>