Hello,
I am new to WHMCS and php and i would like to add a new custom php file that displays all the tlds and their pricing ...
For that, i have created a new file : domainList.php under /public_html/ directory :
domainList.php
<?PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.mysite.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'GetTLDPricing',
// See https://developers.whmcs.com/api/authentication
'username' => 'GGT3m7EqO7bxnrb1HcT9i1z0tKOcmA03',
'password' => 'qRFYmqc7JDNprtGxFFwKBJzHyaGxMSbv',
'currencyid' => '1',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
$jsonData = json_decode($response, true);
add_hook('ClientAreaPage', 1, function($vars) {
// Perform hook code here...
return array("response" => $response);
});
?>
i have added the part below so i can access the $response array in the domainList.tpl file
add_hook('ClientAreaPage', 1, function($vars) {
// Perform hook code here...
return array("response" => $response);
});
For now, i have some questions about my code :
1- Is my code structured the right way ? should i place it under the API/ directory ?
2 - If so, how can i access mysite.com/Domain-Listing.php and call the service domainList.php that is under the API directory ?
3- How can i set a template to this file (TPL file) ?
==> i saw some documentation here : https://developers.whmcs.com/advanced/creating-pages/ by using
# Define the template filename to be used without the .tpl extension
$ca->setTemplate('domainList');
4- is the add_hook method used the right way to access $response array directly from the TPL file ?
==> In this case, i would do the following in the domainList.TPL file :
{foreach $response['pricing'] as $tld => $price}
{$tld} : {$price['register']['1']}<br>
{/foreach}
For your information, this is the result contained in the response variable :
Thanks in advance for the help !