Calling worldsteram.nl APIs from WHMCS

16 Jan

Calling worldsteram.nl APIs from WHMCS

Calling worldsteram.nl APIs from WHMCS.

worldsteram.nl Provides API ID, and that must be used with API Calls.
So first of all create a file named worldstream.php and it must be
uploaded to the folder /modules/servers/worldstream.

<?php
function worldstream_ConfigOptions() {
    return array(
        'API ID' => array(
            'Type' => 'text',
            'Size' => '30',
            'Default' => '_API-ID_',
            'Description' => 'REplace _API-ID_ with your API ID',
        )
    );
}

/**
 The content that we will display on the page
[server.com]/clientarea.php?action=productdetails&id=[SERVICE_ID]
**/
function worldstream_ClientArea($vars) {
    //store your api id in config option and fetch it.
    $api_id = $vars['configoption2'];
    //create a custom field to store your server id 
    //and fetch it
    if(!empty($vars['customfields']['Server ID'])){
       $server_id = $vars['customfields']['Server ID'];
    } 
    
    
      if (empty($server_id)) {
        $return_array['status'] = 0;
        return array(
            'templatefile' => 'no_serverid',
            'vars' => array(
                'response' => $return_array
            )
        );
      }

      /*
          Call the function getMyServer to get
          server details.
      */
      $result_array = getMyServer($api_id, $server_id);
      return array(
                'templatefile' => 'clientarea',
                'vars' => array(
                    'response' => $result_array
                ),
      );
}

/**
 Let's call the API get_dedicated_list 
**/
function getMyServer($api_id, $server_id) {
    $url = 'https://www.customerpanel.nl/api.php';
    $data = array(
        "api_id" => $api_id,
        "method" => "get_dedicated_list"
    );

    $options = array(
        'CURLOPT_TIMEOUT' => '300',
    );
    $response = curlCall($url, $data, $options);
    $return = array();
    $result_array = json_decode($response);
    if ($result_array->StatusCode == 1) {
        unset($result_array->StatusCode);
        unset($result_array->StatusMessage);
        foreach ($result_array as $k => $value) {
            if ($value->Server_Id == $server_id) {
                $return['Status'] = 1;
                $return['Default_Password'] =
                    $value->Default_Password;
                $return['Main_IP'] = $value->Main_IP;
                $return['IPv6'] = isset($value->IPv6)
                    ? $value->IPv6 : "None";
                $return['Max_Datatraffic'] = 
                    $value->Max_Datatraffic;
                $return['Status'] = $value->Status;
                return $return;
            } else {
                continue;
            }
        }
    }
    $return['Status'] = 0;
    return $return;
}

Create a folder named templates in the path /modules/servers/worldstream.
Within that folder create a file named clientarea.tpl.
Then store the below contents to that file.

<div class="row">
    
    <div class="col-sm-12">
        <strong class="text-center">
               Server Details:
        </strong>
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
        IPv4 Addresses:
    </div>
    <div class="col-sm-7 text-left">
       {$response['Main_IP']}
    </div>

</div>
<div class="row">
    
    <div class="col-sm-5 text-right">
       IPv6 Addresses:
    </div>
    <div class="col-sm-7 text-left">
      {$response['IPv6']}
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
           Max. Datatraffic:
    </div>
    <div class="col-sm-7 text-left">
       {$response['Max_Datatraffic']}GB
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
          Default Password:
    </div>
    <div class="col-sm-7 text-left">
          {$response['Default_Password']}
    </div>
</div>

<div class="row">
    
    <div class="col-sm-5 text-right">
          Status:
    </div>
    <div class="col-sm-7 text-left">
       {$response['Status']}
    </div>
</div>

One Comments “Calling worldsteram.nl APIs from WHMCS

  1. Hi John,

    First of all i replaced your API_ID with MY-API_ID as it should not be disclosed to others.
    You forgot the php opening tag at the top of the page? Please check my post once more and you will see the tag. If you need any help, i can assist you too.

Leave a Reply to whmcsisg8 Cancel reply

Your email address will not be published. Required fields are marked *