Computer600 Posted August 1, 2016 Share Posted August 1, 2016 Hi all, So today I've been trying to do a simple task but it is not working. My task is: when a customer purchases my product (the type of the product is Other Product/Service) I want to perform an SQL query to my other database (I know how to do that). My problem is: I've tried following the Addon Modules guide as well as the Provisioning Modules guide and have no success of the functions running (I even added a file write to make sure it isn't my SQL's fault. So far I've made an Addon Module and the hooks didn't work so I deleted it. Now I've created a Provisioning Module at the path modules/servers/testermodule/testermodule.php and this is the code I have: if (!defined("WHMCS")) { die("This file cannot be accessed directly"); } function testermodule_MetaData() { return array( 'DisplayName' => 'Tester Module', 'APIVersion' => '1.1', 'RequiresServer' => false, 'DefaultNonSSLPort' => '1111', // 'DefaultSSLPort' => '1112', // 'ServiceSingleSignOnLabel' => 'Login to Panel as User', 'AdminSingleSignOnLabel' => 'Login to Panel as Admin', ); } function testermodule_CreateAccount(array $params) { try { $file = fopen(dirname(__FILE__) .'/test.log', 'a'); fwrite($file, json_encode($params)); fclose($file); } catch (Exception $e) { // Record the error in WHMCS's module log. logModuleCall( 'testermodule', __FUNCTION__, $params, $e->getMessage(), $e->getTraceAsString() ); return $e->getMessage(); } return 'success'; } TL;DR: How can I run a function after the customer has purchased my product. Much thanks, Computer600 0 Quote Link to comment Share on other sites More sharing options...
msaunders Posted August 2, 2016 Share Posted August 2, 2016 Hi Would you use AfterModuleCreate ? http://docs.whmcs.com/Hooks:AfterModuleCreate Im using AfterRegistrarRegistration and have a hook running after someone buys a particular domain tld that sets the domain back to pending and sends an email to the customer <?php function hook_iedr_register_pending($vars) { #error_reporting(E_ALL); #ini_set('display_errors', true); $domainid = $vars['params']['domainid']; $tld= $vars['params']['tld']; if ($tld=="ie") { update_query("tbldomains",array("status"=>"Pending"),array("id"=>$domainid)); # Set Vars $command = 'SendEmail'; $values = array( 'messagename' => 'More Information Needed', 'id' => $domainid, 'customtype' => 'domain'); $adminuser = 'admin'; # Call API $results = localAPI($command,$values,$adminuser); if ($results['result']!="success") echo "An Error Occurred: ".$results['result']; #var_dump($results); #exit; } } add_hook("AfterRegistrarRegistration",1,"hook_iedr_register_pending"); ?> 0 Quote Link to comment Share on other sites More sharing options...
twhiting9275 Posted August 2, 2016 Share Posted August 2, 2016 The question is at what point do you want to do this? Aftermodulecreate will work, if you require the module to be setup, BUT that's not going to work if you want it done as soon as the payment is placed. 0 Quote Link to comment Share on other sites More sharing options...
Computer600 Posted August 3, 2016 Author Share Posted August 3, 2016 Thank you both for your replies, I did try to hook into AfterModuleCreate (when I created the addon) but it didn't work after the payment was made. Is there a reason for this? The question is at what point do you want to do this? I want the function to run after the product has been purchased so it can be setup in my other system. 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.