Search code examples
phpwhmcs

How do I add a hook for WHMCS for when a client pays their bill?


For the past few hours I've been trying to figure out how to add a hook to WHMCS. At first, I tried the PendingOrder hook, which never got called. Then I tried the AcceptOrder, which also seemed to never get called. Last, I tried the InvoidPaid hook, which also doesn't seem to be working. Am I doing something wrong?

I have enabled my hook in AddonModules, but it seems like I can't get any hooks to call (or I am using the wrong one)

What I'm trying to do is just run a PHP script that contains all of the custom fields that a user entered when they paid for an order.

How would I go about doing this?

My main module:

<?php
/**
 * @package    GSProv
 * @author     -
 * @copyright  -
 * @license    None
 * @version    $Id$
 * @link       -
 */

if (!defined("WHMCS"))
{
    die("Can't access this file directly!");
}
add_hook("InvoicePaid", 1, "gsprov_hook_provision");
add_hook("InvoiceUnpaid", 1, "gsprov_hook_suspend");

function gsprov_hook_provision($params)
{
    $time = time();
    mysql_connect("localhost", "root", "password");
    mysql_select_db("testdb");
    mysql_query("INSERT INTO log VALUES ($time, 'Order paid for!'");
}

function gsprov_hook_suspend($params)
{
    $time = time();
    mysql_connect("localhost", "root", "password");
    mysql_select_db("testdb");
    mysql_query("INSERT INTO log VALUES ($time, 'Order not paid for :('");
}

?>

Solution

  • There is an error in your SQL, your queries are missing the close bracket.

    mysql_query("INSERT INTO log VALUES ($time, 'Order paid for!'");
    

    Should be

    mysql_query("INSERT INTO log VALUES ($time, 'Order paid for!')");