cesiumdeth Posted January 5, 2014 Share Posted January 5, 2014 I am trying to get hooks working. As a test I've created a file called myhooks.php and placed it in the /includes/hooks folder (same location as the WHMCS included hooks example file named example.php). In this file I've created a hook that should fire when an admin changes an invoice to either "Cancelled" or "Unpaid" status. To prove the hook is being called I'm trying to make an internal API call to make an entry in the activity log. I log in with my admin account (for my example we'll say my username is "cesiumdeth"), navigate to an invoice, and change the status back and forth between a status of "Cancelled" and "Unpaid" and save between each change of course. In the whmcs Activity Log I get the default log entry that notes "Modified Invoice Options - Invoice ID: 12345", but I do not see the custom log entry from the call in my code. Anyone see what I'm missing or messed up and why this isn't working? By the way the I've checked that the admin user I'm using in the code does have API permissions (it is a full administrator account with all permissions). The code in my "myhooks.php" file is as follows: <?php function wr_hook_InvoiceChange($vars) { $command = "logactivity"; $adminuser = "cesiumdeth"; $values["description"] = "proof wr_hook_InvoiceChange was called"; $results = localAPI($command,$values,$adminuser); } add_hook("InvoiceUnpaid",1,"wr_hook_InvoiceChange"); add_hook("InvoiceCancelled",1,"wr_hook_InvoiceChange"); ?> 0 Quote Link to comment Share on other sites More sharing options...
cesiumdeth Posted January 23, 2014 Author Share Posted January 23, 2014 With the help of WHMCS support I was able to figure this out. There was nothing wrong with my hook code. The problem is the InvoiceUnpaid and InvoiceCancelled hooks only fire when an admin clicks the "Mark Unpaid" or "Mark Cancelled" button while viewing an invoice. Personally I think this is a deficiency of these hook points because there are multiple ways you can set the status of an invoice to "Unpaid" or "Cancelled" (such as the sequence I described in my original post that was not firing the hooks). I also let WHMCS support know that the hook documentation for these two hook points mentions nothing about this limitation. I'm posting this hoping it helps someone find this answer faster until the WHMCS hook documentation is updated. 0 Quote Link to comment Share on other sites More sharing options...
imaticon Posted January 25, 2014 Share Posted January 25, 2014 thanks for the update. btw, why you use the localAPI to make an entry in the Activity log? There is a simply function available for this: logActivity('proof wr_hook_InvoiceChange was called'); 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.