Jump to content

Hooking in to After a Purchase has been made


Computer600

Recommended Posts

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

Link to comment
Share on other sites

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");

?>

Link to comment
Share on other sites

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.

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