Jump to content

Using Hooks


abdelhak

Recommended Posts

Hello WHMCS Team,

i have question about using Hooks in whmcs, my goal is to use hooks for sending  data to thrid party system with curl request, i create a php file in include/hooks/file.php and i try to use ClientAdd function  and this is a exmaple of my first hook :

add_hook('ClientAdd', 1, function ($vars)
{
     $data=array();
     $data['userid']= $vars['userid'];
     $data['firstname']= $vars['firstname'];
     $data['lastname']= $vars['lastname'];
     $data['email']= $vars['email'];
     $data['password']= $vars['password'];
     //requete Http
     $url='http://192.168.101.14/ws/ws_insert_client.php';
     $string=http_build_query($data);
     $ch=curl_init($url);
     curl_setopt($ch,CURLOPT_POST,true);
     curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
     $resultat=curl_exec($ch);
     $json_data = json_decode($resultat,true);
     curl_close($ch);
});

this code excute when a new client registred in client-area, the code well excuted and data sended successfully to the third part system and stored there.

Now i need a hook to send data when client make new order in client area and when order accepted in admin area i try the hook AfterShoppingCartCheckout for ther first one and  this exmeple of the code :

 

add_hook('AfterShoppingCartCheckout', 1, function ($vars)
{

     $data=array();
     $data['OrderID']= '1';
     $data['OrderNumber']= '2';
     $data['ServiceIDs']= '3';
     $data['AddonIDs']= '4';
     $data['DomainIDs']= '5';
     $data['RenewalIDs']= '6';
     $data['PaymentMethod']= '7';
     $data['InvoiceID']= '8';
     $data['TotalDue']= '9';
    
     //requete Http
     $url='http://192.168.101.14/ws/ws_insert_commande_whmcs.php';
     $string=http_build_query($data);
     $ch=curl_init($url);
     curl_setopt($ch,CURLOPT_POST,true);
     curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
     curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
     $resultat=curl_exec($ch);
     $json_data = json_decode($resultat,true);
     curl_close($ch);
});

and this the code for the second hook OrderAccepted

add_hook('AcceptOrder', 1, function($vars) {
   $data=array();
   $data['OrderID']=$vars['orderid'];
   //requete Http
   $url='http://192.168.101.14/ws/ws_insert_commande_whmcs.php';
   $string=http_build_query($data);
   $ch=curl_init($url);
   curl_setopt($ch,CURLOPT_POST,true);
   curl_setopt($ch,CURLOPT_POSTFIELDS,$string);
   curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
   $resultat=curl_exec($ch);
   $json_data = json_decode($resultat,true);
   curl_close($ch);
});

 

but data not sended in two cases, please help.

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