2

I submitted a related query: Redirect to custompage.php instead of viewinvoice.php if payment fails in WHMCS Vs 6.2.0, and I got a brilliant response which i successfully implemented.

I wish to port my code solution into a custom built WHMCS addon module if possible by leveraging the WHMCS _output function of the addon module, to output transaction failed messages from the payment gateway.

I undestand that, Hooks that the module should define within WHMCS are defined in a file named “hooks.php”. This should be within my module folder.

My design objective is to detect if I am on viewinvoice.php page, then redirect within the hook to the addon module file as shown below:

add_hook('ClientAreaPage', 1, function($templateVariables)
{
    if($templateVariables["filename"] == "viewinvoice" AND $templateVariables["paymentSuccess"] == false)
    {       
        // store variables to send to the addon module file.
        $_SESSION['bemasTransactionDetails'] = $templateVariables["invoiceid"];

        // redirect to addon page ????
        header('location:'. addon_module_file);
        die;
    }
});

This is not working.

How do I redirect to the WHMCS addon module file from the module hook? Or am I approaching the problem the wrong way?

Can any one give me a hint?

Community
  • 1
  • 1
Terungwa
  • 395
  • 3
  • 18

1 Answers1

1

Interesting - can you verify that the function is being called up on the client area page as expected? I haven't tried declaring the function on the fly like that. If I'm not mistaken, the add_hook function is looking for an actual string name for a function to execute - if you declare the function like that in place of providing a name, I wouldn't think it would execute. I have done something similar in a framework I wrote that works with WHMCS (Dunamis Framework) - it allows hook files to be added within a 'hooks' folder in the addon module, then the framework grabs them, and adds them to the stack at execution, but I hadn't tried this method.

To your question, I think you can use a similar approach to the other question you had. The hooks.php file in the addon module folder would also be added to the stack and executed after initializing the WHMCS application, so you could check for the name of the file you are on and for the successful payment variable and redirect from there.

You may need to add a session variable when asking for the payment and then checking for that session variable if payment fails (it looks like you are checking for payment failures, is that right?) to ensure the end user actually gets to the payment request page to begin with.

Hope that is of help...

muely2k1
  • 436
  • 2
  • 4