Exemple #1
0
 /**
  * Init The api
  *
  * @return json
  */
 public static function init($action, $param = false)
 {
     $url = \Config::get('whmcs.ApiURL');
     $username = \Config::get('whmcs.ApiUsername');
     # Admin username goes here
     $password = \Config::get('whmcs.ApiPassword');
     # Admin password goes here
     $postfields = array();
     $postfields["username"] = $username;
     $postfields["password"] = md5($password);
     $postfields["action"] = $action;
     $postfields["responsetype"] = "json";
     $query_string = "";
     if ($param != false) {
         foreach ($param as $key => $value) {
             $postfields[$key] = $value;
         }
     }
     if (Helper::customfields() != 'null') {
         $postfields['customfields'] = base64_encode(serialize(Helper::customfields()));
     }
     foreach ($postfields as $k => $v) {
         $query_string .= "{$k}=" . urlencode($v) . "&";
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     $jsondata = curl_exec($ch);
     if (curl_error($ch)) {
         die("Connection Error: " . curl_errno($ch) . ' - ' . curl_error($ch));
     }
     curl_close($ch);
     $arr = json_decode($jsondata);
     return $arr;
 }
 public function register()
 {
     $get = isset($_GET['email']) ? $_GET['email'] : 'null';
     if ($get != 'null') {
         $hash = Helper::hash($get, 30);
         $user = DB::table('tblclients')->where('email', '=', $get)->first();
         if ($user != null) {
             $userid = $user->id;
             $key = DB::table('tblmcsapikey')->where('client_id', '=', $userid)->first();
             if ($key == null) {
                 $insert = DB::table('tblmcsapikey')->insert(['client_id' => $userid, 'api_key' => $hash]);
                 if ($insert) {
                     $result['result'] = 'success';
                     $result['client_id'] = $userid;
                     $result['api_key'] = $hash;
                     return json_encode($result);
                 } else {
                     $result['result'] = 'error';
                     $result['message'] = 'error when inserting data to database';
                     return json_encode($result);
                 }
             } else {
                 $result['result'] = 'error';
                 $result['message'] = 'email sudah terdaftar';
                 return json_encode($result);
             }
         } else {
             $result['result'] = 'error';
             $result['message'] = 'email tidak terdaftar';
             return json_encode($result);
         }
     } else {
         $result['result'] = 'error';
         $result['message'] = 'email tidak ada';
         return json_encode($result);
     }
 }
 public function validapi()
 {
     if (\Config::get('whmcs.useApiKey') == true) {
         $getkey = Helper::api_key();
         if ($getkey != 'null') {
             $cek = Helper::cek($getkey);
             if ($cek != 0) {
                 $result['result'] = 'success';
                 $result['message'] = 'Api key sudah terdaftar';
                 return json_encode($result);
             } else {
                 $result['result'] = 'error';
                 $result['message'] = 'Api key belum terdaftar';
                 return json_encode($result);
             }
         } else {
             $result['result'] = 'error';
             $result['message'] = 'Api key belum terdaftar';
             return json_encode($result);
         }
     }
 }
 /**
  * @link http://docs.whmcs.com/API:Order_Fraud_Check
  * @param pid - can be used to just retrieve the details of a specific product ID
  * @param gid - can be passed to just retrieve products in a specific group
  * @param module - can be passed to just retrieve products assigned to a specific module
  * @return json
  */
 public function getproducts()
 {
     if (\Config::get('whmcs.useApiKey') == true) {
         $getkey = Helper::api_key();
         if ($getkey != 'null') {
             $cek = Helper::cek($getkey);
             if ($cek != 0) {
                 $action = "getproducts";
                 $datas = WhmcsBase::init($action, Helper::get());
                 $result = json_encode($datas);
                 return $result;
             } else {
                 $result['result'] = 'error';
                 $result['message'] = 'Api key belum terdaftar';
                 return json_encode($result);
             }
         } else {
             $result['result'] = 'error';
             $result['message'] = 'Your API key is missing';
             return json_encode($result);
         }
     } else {
         $action = "getproducts";
         $datas = WhmcsBase::init($action, Helper::get());
         $result = json_encode($datas);
         return $result;
     }
 }