Jump to content

Payment gateway hook during viewinvoice


nitaish

Recommended Posts

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");

 

Link to comment
Share on other sites

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...

  1. the client will be logged in and therefore you can find out their currency - you don't need the currencies array.;
  2. you would have to modify the $gatewaydropdown variable (usually be removing specific gateway strings per gateway) - often easier said than done;
  3. 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.

Link to comment
Share on other sites

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...

  1. the client will be logged in and therefore you can find out their currency - you don't need the currencies array.;
  2. you would have to modify the $gatewaydropdown variable (usually be removing specific gateway strings per gateway) - often easier said than done;
  3. 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. 🙂

Link to comment
Share on other sites

  • 3 months later...
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...

  1. the client will be logged in and therefore you can find out their currency - you don't need the currencies array.;
  2. you would have to modify the $gatewaydropdown variable (usually be removing specific gateway strings per gateway) - often easier said than done;
  3. 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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated