Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in Hook #6

Open
mortenmathiasen opened this issue May 17, 2023 · 3 comments
Open

Crash in Hook #6

mortenmathiasen opened this issue May 17, 2023 · 3 comments

Comments

@mortenmathiasen
Copy link

mortenmathiasen commented May 17, 2023

Using whmcs 8.7.2 and latest version of QuickPay module clientarea crashes when trying to change credit card details:

TypeError: http_build_query(): Argument #1 ($data) must be of type array, null given in modules/gateways/quickpay.php:862
Stack trace:
#0 modules/gateways/quickpay.php(862): http_build_query(NULL, '', '&')
#1 modules/gateways/quickpay.php(456): helper_quickpay_request('e76457161e8d05...', 'subscriptions/3...', NULL, 'GET')
#2 includes/hooks/quickpay_hook_product_view.php(114): helper_update_subscription(Array)
#3 includes/hooks/quickpay_hook_product_view.php(40): handle_change_card_request('999999999', 97)
#4 [internal function]: WHMCS\Utility\SafeInclude::{closure}(Array)
#5 vendor/whmcs/whmcs-foundation/lib/Hook/Manager.php(0): call_user_func(Object(Closure), Array)
#6 vendor/illuminate/support/Facades/Facade.php(261): WHMCS\Hook\Manager->run('ClientAreaProdu...', Array, false)
#7 includes/functions.php(0): Illuminate\Support\Facades\Facade::__callStatic('run', Array)
#8 clientarea.php(0): run_hook('ClientAreaProdu...', Array)
#9 {main}

What is going on here?

@CorwinDev
Copy link
Collaborator

Hi, can you check if this still happens if you use the latest version?

@saitix
Copy link

saitix commented Sep 6, 2024

It stil happens, even in the latest version ( 2.5.1 )
I have a fix for this:

in modules/gateways/quickpay.php, before line #865, where the Request parameters is built, correct the $param so that it is always an array ( as on card update it is sent as NULL )

  if(is_null($params))$params = [];                                                                                                                                                                                           
   /** Request parameters */                                                                                                                                                                                                   
   $options = [                                                                                                                                                                                                                
       CURLOPT_RETURNTRANSFER => true,                                                                                                                                                                                         
       CURLOPT_SSL_VERIFYPEER => true,                                                                                                                                                                                         
       CURLOPT_HTTPAUTH => CURLAUTH_BASIC,                                                                                                                                                                                     
       CURLOPT_HTTPHEADER => $headers,                                                                                                                                                                                         
       CURLOPT_CUSTOMREQUEST => $method,                                                                                                                                                                                       
       CURLOPT_URL => $url,                                                                                                                                                                                                    
       CURLOPT_POSTFIELDS => preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', http_build_query($params, '', '&')),                                                                                                                 
   ]; 

Also in the hook, hooks/quickpay_hook_product_view.php
in function handle_change_card_request(), after line #115, add an forced exit(0) just before the header redirect, otherwise the new WH will just ignore the header command.

    $url = helper_update_subscription($params)->url;                                                                                                                                                                            
    header("Location:" . $url);                                                                                                                                                                                                 
    exit(0);  

@Tntdruid
Copy link

Tntdruid commented Sep 6, 2024

@saitix Make a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants