abdelhak Posted September 9, 2020 Share Posted September 9, 2020 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. 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.