nitaish Posted December 31, 2020 Share Posted December 31, 2020 Hello All, We are trying to add a hook which will trigger when viewinvoice.php is open. we want to display payment gateway dropdown option in such a way that if client currency is INR it should show Bank transfer, ccavenue and razorpay and rest of the currency stripe as a gateway. We worked on below code but it is not working. Can anyone please guide us how we can achieve this task <?php use WHMCS\Database\Capsule; function gateway_after_switcher($vars) { /* echo "<pre>"; print_r($vars); exit; */ if ($vars['templatefile']=='viewinvoice'){ $gateways = $vars['paymentGatewayName']; $currenciess_name = $vars['currencies']; $paymentmethods['INR'] = ['banktransfer','ccavenuev2','razorpay']; $paymentmethods['USD'] = ['stripe']; $paymentmethods['AUD'] = ['stripe']; foreach($currenciess_name as $k => $data){ if($data['code'] == 'INR') { return array($paymentmethods['INR']); } else if($data['code'] == 'USD') { //echo "usd"; return array($paymentmethods['USD']); } else if($data['code'] == 'AUD') { //echo "aud"; return array($paymentmethods['AUD']); } else { } } } } add_hook("ClientAreaPageViewInvoice", 1, "gateway_after_switcher"); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 31, 2020 Share Posted December 31, 2020 25 minutes ago, nitaish said: We are trying to add a hook which will trigger when viewinvoice.php is open. well you chose the right hook point - clientareapageviewinvoice... and you won't need to check the template name. 🙂 26 minutes ago, nitaish said: we want to display payment gateway dropdown option in such a way that if client currency is INR it should show Bank transfer, ccavenue and razorpay and rest of the currency stripe as a gateway. you can't do it the way you're trying to do it... the client will be logged in and therefore you can find out their currency - you don't need the currencies array.; you would have to modify the $gatewaydropdown variable (usually be removing specific gateway strings per gateway) - often easier said than done; there are scenarios where you might have to reset the default gateway (if you're removing the existing default for that invoice) by updating the database table; I will have posted previous hooks that modified $gatewaydropdown for various purposes - I would suggest that one of those would be a better starting point. 1 Quote Link to comment Share on other sites More sharing options...
nitaish Posted January 4, 2021 Author Share Posted January 4, 2021 On 12/31/2020 at 8:52 PM, brian! said: well you chose the right hook point - clientareapageviewinvoice... and you won't need to check the template name. 🙂 you can't do it the way you're trying to do it... the client will be logged in and therefore you can find out their currency - you don't need the currencies array.; you would have to modify the $gatewaydropdown variable (usually be removing specific gateway strings per gateway) - often easier said than done; there are scenarios where you might have to reset the default gateway (if you're removing the existing default for that invoice) by updating the database table; I will have posted previous hooks that modified $gatewaydropdown for various purposes - I would suggest that one of those would be a better starting point. Thank you. 🙂 0 Quote Link to comment Share on other sites More sharing options...
weelow Posted May 1, 2021 Share Posted May 1, 2021 On 12/31/2020 at 5:22 PM, brian! said: well you chose the right hook point - clientareapageviewinvoice... and you won't need to check the template name. 🙂 you can't do it the way you're trying to do it... the client will be logged in and therefore you can find out their currency - you don't need the currencies array.; you would have to modify the $gatewaydropdown variable (usually be removing specific gateway strings per gateway) - often easier said than done; there are scenarios where you might have to reset the default gateway (if you're removing the existing default for that invoice) by updating the database table; I will have posted previous hooks that modified $gatewaydropdown for various purposes - I would suggest that one of those would be a better starting point. Regarding resting the default gateway i do that using update client api the real issue for me here is i have to manually refresh the invoice for the old default payment method to get updated and replaced by the new one. Is there any way to refresh the invoice after this update? header("Refresh:0"); this works but will refresh indefinitely. 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.