tiagocaus Posted July 29, 2019 Share Posted July 29, 2019 I have a car rental system. I am creating a module to control sales through WHMCS. I need two of your help. 1º) How to make the field USERNAME receive the first name of the register? 2º) In the custom field, called CHAVE , how do I automatically generate an MD5 number? Thank you. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted July 29, 2019 Share Posted July 29, 2019 In the provisioning module's create function, update the service details with the username you want to use. You can also use a hook to do this before the order is accepted. As for the custom field, you would save the custom field with API with for example the following. $CustomFields = base64_encode( serialize( array('CHAVE' => md5('example.') ) ); $AccountIDadd = localAPI('updateclientproduct', array("username"=>$User,"password"=>$UserPass,'serviceid'=>$params['serviceid'],'customfields' => $CustomFields)); You can also use that for the first item mentioned. 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted July 29, 2019 Author Share Posted July 29, 2019 (edited) 9 minutes ago, steven99 said: In the provisioning module's create function, update the service details with the username you want to use. You can also use a hook to do this before the order is accepted. As for the custom field, you would save the custom field with API with for example the following. $CustomFields = base64_encode( serialize( array('CHAVE' => md5('example.') ) ); $AccountIDadd = localAPI('updateclientproduct', array("username"=>$User,"password"=>$UserPass,'serviceid'=>$params['serviceid'],'customfields' => $CustomFields)); You can also use that for the first item mentioned. Hi Steven, I'm still lost, this is the first time I have made a module for WHMCS. Inside my folder whmcs > module > servers I created my folder called /carros7. Inside the folder /carros7/ I have these files: carros7.php and hooks.php Do I put the code you sent me into the hooks.php file? Thank you. Edited July 29, 2019 by tiagocaus 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted July 29, 2019 Share Posted July 29, 2019 You would use that within the _CreateAccount function of the provisioning module you're developing, in this case in the carros7.php file. So for example, you complete your backend processes for deploying the car to the renter and then you save the details using that code. 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted July 29, 2019 Author Share Posted July 29, 2019 (edited) 30 minutes ago, steven99 said: To help me in development, I found the CentosWebPanel system modules. Link https://wiki.centos-webpanel.com/whmcs-module-for-cwp-api In their module, they create using the GET method, send the variables by URL. I was just stuck with these two fields, USERNAME and the CHAVE custom field. See this is the code: <?php function carros7_ConfigOptions() { $configarray = array( "matrizFiliais" => array( "FriendlyName" => "Matris/Filiais", "Type" => "text", "Default" => "1"), "veiculos" => array( "FriendlyName" => "Veículos", "Type" => "text" , "Default" => "3",), "funcionarios" => array( "FriendlyName" => "Funcionários", "Type" => "text", "Default" => "Ilimitado", ), ); return $configarray; } function carros7_CreateAccount($params) { if ($params["server"] == 1) { $postvars = array( 'key' => $params["serveraccesshash"], 'action' => 'adicionar', 'nomeCompleto' => $params["fullname"], // Get full name {Still does not work} 'email' => $params["clientsdetails"]["email"], 'usuario' => $params["username"], //{Still does not work} 'senha' => $params["password"], 'Chave' => $params["chave"], // Key Custom Field {Still does not work} 'matrizFiliais' => $params["configoption1"], 'veiculos' => $params["configoption2"], 'funcionarios' => $params["configoption3"] ); $postdata = http_build_query($postvars); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . 'whmcs/criar.php'); curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); $answer = curl_exec($curl); logModuleCall('carroswhmcs','CreateAccount_UserAccount','https://' . $params["serverhostname"] . 'whmcs/criar.php?'.$postdata,$answer); } if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];} return $result; } THAT'S THE GENERATED LINK https://www.aaaa.com/whmcs/criar.php? key=1FB6FAC9F7D0FE2G7998FCF07EA1HE06 &action=adicionar &nomeCompleto= &email=sac.teste@teste.net &usuario= &senha=1z%232Sl%3B0mMkV8R &Chave= &matrizFiliais=1 &veiculos=3 &funcionarios=10 How should I modify this file to work? Thank you. Edited July 29, 2019 by tiagocaus 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted July 29, 2019 Share Posted July 29, 2019 function carros7_CreateAccount($params) { if ($params["server"] == 1) { $postvars = array( 'key' => $params["serveraccesshash"], 'action' => 'adicionar', 'nomeCompleto' => $params['clientsdetails']['firstname'].$params['clientsdetails']['lastname'], // Get full name {Still does not work} 'email' => $params["clientsdetails"]["email"], 'usuario' => (isset($params["username"]) and !empty($params["username"]) ? $params["username"] : $params['clientsdetails']['firstname'].$params['clientsdetails']['lastname']), 'senha' => $params["password"], 'Chave' => md5($params['configoptions']["chave"]), 'matrizFiliais' => $params["configoption1"], 'veiculos' => $params["configoption2"], 'funcionarios' => $params["configoption3"] ); $postdata = http_build_query($postvars); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . 'whmcs/criar.php'); curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); $answer = curl_exec($curl); logModuleCall('carroswhmcs','CreateAccount_UserAccount','https://' . $params["serverhostname"] . 'whmcs/criar.php?'.$postdata,$answer); } if(strpos($answer,"OK")!==false){$result='success';}else{$result=json_decode($answer,true); $result=$result['msj'];} return $result; } 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted July 30, 2019 Author Share Posted July 30, 2019 3 hours ago, steven99 said: Hi Stvens, The code above generated the following variables: https://aaa.bbbb.com.br/whmcs/criar.php? key=1FB6F6C9F7D0FE2F7998FCF07EA1BE06 &action=adicionar &nomeCompleto=Contade+Teste &email=sac.teste@teste.net &usuario=1 &senha=1z%232Sl%3B0mMkV8R &Chave=d41d8cd98f00b204e9800998ecf8427e &matrizFiliais=99999 &veiculos=99999 &funcionarios=99999 But it was not registered in the USERNAME and CHAVE fields. This data needs to be recorded in the inputs. For the intention is that when the order is made by the site already have this data recorded, because as soon as the payment is approved whmcs create the account already with the input data. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted July 31, 2019 Share Posted July 31, 2019 To save the info, you would use the first mentioned code with the function. Below is an updated version of that function with the api to save. function carros7_CreateAccount($params) { if ($params["server"] == 1) { $Chave = md5($params['configoptions']["chave"]); $postvars = array( 'key' => $params["serveraccesshash"], 'action' => 'adicionar', 'nomeCompleto' => $params['clientsdetails']['firstname'].$params['clientsdetails']['lastname'], // Get full name {Still does not work} 'email' => $params["clientsdetails"]["email"], 'usuario' => ((isset($params["username"]) and !empty($params["username"])) ? $params["username"] : $params['clientsdetails']['firstname'].$params['clientsdetails']['lastname']), 'senha' => $params["password"], 'Chave' => $Chave, 'matrizFiliais' => $params["configoption1"], 'veiculos' => $params["configoption2"], 'funcionarios' => $params["configoption3"] ); $postdata = http_build_query($postvars); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, 'https://' . $params["serverhostname"] . 'whmcs/criar.php'); curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); $answer = curl_exec($curl); logModuleCall('carroswhmcs','CreateAccount_UserAccount','https://' . $params["serverhostname"] . 'whmcs/criar.php?'.$postdata,$answer); if (strpos($answer,"OK")!==false) { $result='success'; $CustomFields = base64_encode( serialize( array('Chave' => $Chave ) ); $AccountIDadd = localAPI('updateclientproduct', array("username"=>$params["username"],'serviceid'=>$params['serviceid'],'customfields' => $CustomFields)); if ($AccountIDadd) return $result; } else { $result=json_decode($answer,true); $result=$result['msj']; } return $result; } return "unknown error"; } 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted September 10, 2020 Author Share Posted September 10, 2020 (edited) @steven99 How do I capture the value of the custom field (Key) into the file clientssummary.tpl I tried that way, but it doesn't appear: {php} echo $params['customfields']["Chave"]; {/php} Thank you. Edited September 10, 2020 by tiagocaus 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted September 10, 2020 Share Posted September 10, 2020 How do you mean capture? 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted September 10, 2020 Author Share Posted September 10, 2020 (edited) @steven99 I don't know how to capture it, I just want to be able to print the value of the custom field on the clientssummary screen, then I can handle that value the way I need to do it. But at the moment, I just need to be able to capture the value within the clientssummary. How to do this? Edited September 10, 2020 by tiagocaus 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted September 10, 2020 Author Share Posted September 10, 2020 When capturing the value of the key, I will make a select in the external database, to obtain some values, and thus show this data on the screen in a `clientssummarybox`. 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted September 10, 2020 Share Posted September 10, 2020 There are two options here: 1. Use the AdminAreaClientSummaryPage hook and inject the box with the value that you would grab from API or internal classes. 2. Check if the $product in the $productsummary array in the clientsummary.tpl file has the customfield and if so use it -- but you would need to go through all products and logic should not be in view. 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted September 10, 2020 Author Share Posted September 10, 2020 @steven99 How do I check using your option 2? 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted September 10, 2020 Share Posted September 10, 2020 Though I would not usually recommend it, doing: {php} echo print_r(var_dump_vars()); {/php} then look for the productsummary array and the product array within it. 0 Quote Link to comment Share on other sites More sharing options...
tiagocaus Posted September 10, 2020 Author Share Posted September 10, 2020 @steven99 When using the given code, this error appears: 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted September 10, 2020 Share Posted September 10, 2020 Should have been: <pre>{php} print_r(var_dump()); {/php} </pre> 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.