Jump to content

Creating a module


tiagocaus

Recommended Posts

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?

 

image.jpeg.a3ba3e391f280d46568e24aa42938285.jpeg

 

Thank you.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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 by tiagocaus
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by tiagocaus
Link to comment
Share on other sites


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;
}

 

Link to comment
Share on other sites

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.

image.png.341ad99f4f96191cbfbe30bb37c10ea1.png

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.

Link to comment
Share on other sites

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";
}
Link to comment
Share on other sites

  • 1 year later...

@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 by tiagocaus
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated