anderbytes Posted July 2, 2018 Share Posted July 2, 2018 Has anyone ever implemented any hook or template change to create some conditional logic based on payment gatway? We have one Payment Gateway that only has to appear when Invoice total is greater than X. If that's not the case, the payment gateway shouldn't even appear at the dropdown. Is that possible? Thanks! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 3, 2018 Share Posted July 3, 2018 you could modify the hook I posted in the thread below... in that instance, if total is zero, it removes all gateways apart from those specified in the hook... you could change that zero value and use multiple conditional statements to determine what gateways are shown at specific total values. 0 Quote Link to comment Share on other sites More sharing options...
anderbytes Posted July 3, 2018 Author Share Posted July 3, 2018 @brian!, thank you, that will probably work, will test it today. But I guess that still leaves one problem: the same restriction has to work when an invoice is being viewed. Technically that won't forbid the client of opening an invoice and change the payment method to the one that it shouldn't be possible. Consider that allowing clients to change payment gateway is essential, unfortunately I can't remove that possibility. Thanks! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 4, 2018 Share Posted July 4, 2018 you could use a viewinvoice hooks similar to one I posted in the previous thread... <?php # ViewInvoice Gateway Hook # Written by brian! function hook_view_invoice_gateway($vars) { if ($vars['status'] == 'Unpaid' && $vars['total']->toNumeric() <= 50) { $gatewaydropdown = $vars['gatewaydropdown']; $asiapay = '<option value="asiapay">AsiaPay</option>'; $gd2 = str_replace($asiapay, '', $gatewaydropdown) ; return array("gatewaydropdown" => $gd2); } } add_hook('ClientAreaPageViewInvoice', 1, 'hook_view_invoice_gateway'); ?> now that should work fine if your site is only using one currency, e.g any unpaid invoices less than $50.01 will not have AsiaPay as an option, but it's no good if you have a multi-currency site... e.g the above would trigger at $50.01, £50.01, €50.01 or even ฿50.01 - all of which are varying and unequal amounts. <?php # ViewInvoice Gateway Hook # Written by brian! function hook_view_invoice_gateway($vars) { $client = $vars['clientsdetails']; $currency = $client['currency']; if ($currency == '1') { $gatewaylimit = 50; } elseif ($currency == '2') { $gatewaylimit = 75; } else { $gatewaylimit = 0; } if ($vars['status'] == 'Unpaid' && $vars['total']->toNumeric() <= $gatewaylimit) { $gatewaydropdown = $vars['gatewaydropdown']; $asiapay = '<option value="asiapay">AsiaPay</option>'; $gd2 = str_replace($asiapay, '', $gatewaydropdown) ; return array("gatewaydropdown" => $gd2); } } add_hook('ClientAreaPageViewInvoice', 1, 'hook_view_invoice_gateway'); ?> so in the above hook, if we imagine currency #1 is USD and #2 is GBP, the limit for clients using USD is $50.01; the limit for those using GBP is £75.01 and so on. I suppose if you have the cron updating the exchange rates, you could just set a limit in your default currency and then get the hook to calculate that limit in the other currencies, but that would require querying the db etc. 1 Quote Link to comment Share on other sites More sharing options...
anderbytes Posted July 4, 2018 Author Share Posted July 4, 2018 Thank you! you are the best! I´ll test this tonight For the other currencies, I wouldn't bother, because this payment method that I have to limit is available only to my country (Brazil), so if I can detect what currency it is (not hard), I can just hide that gateway anyway. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 5, 2018 Share Posted July 5, 2018 16 hours ago, anderbytes said: For the other currencies, I wouldn't bother, because this payment method that I have to limit is available only to my country (Brazil), so if I can detect what currency it is (not hard), I can just hide that gateway anyway. you could detect the clients registered country from the $clientsdetails array (the same one that tells you the currency), so you could check that they are in Brazil and/or using that Currency. 0 Quote Link to comment Share on other sites More sharing options...
anderbytes Posted July 5, 2018 Author Share Posted July 5, 2018 That would be effective for invoice page, but not for cart, because when it's a new client, at the checkout page I don't know yet the client details (he/she is filling in exactly that screen). So I had to check $['language'] and when the client uses our language to browse, I have to assume that he is local and he can pay in our local gateways that can't appear to people outside our country. Anyway, everything worked perfectly! I can't thank you enough! 0 Quote Link to comment Share on other sites More sharing options...
Evolve Web Hosting Posted December 13, 2020 Share Posted December 13, 2020 How would you modify this to include 2 gateway options? @brian! I'm more than happy to pay for your time. I know you contribute a LOT around here and it all takes time. It's not as simple as this, is it? <?php # ViewInvoice Gateway Hook # Written by brian! function hook_view_invoice_gateway($vars) { $client = $vars['clientsdetails']; $currency = $client['currency']; if ($currency == '1') { $gatewaylimit = 200; } elseif ($currency == '2') { $gatewaylimit = 75; } else { $gatewaylimit = 0; } if ($vars['status'] == 'Unpaid' && $vars['total']->toNumeric() <= $gatewaylimit) { $gatewaydropdown = $vars['gatewaydropdown']; $authorize = '<option value="authorize">Credit / Debit Card</option>'; $authorizeecheck = '<option value="authorizeecheck">ACH / Direct Debit</option>'; $gd2 = str_replace($authorize, $authorizeecheck, '', $gatewaydropdown) ; return array("gatewaydropdown" => $gd2); } } add_hook('ClientAreaPageViewInvoice', 1, 'hook_view_invoice_gateway'); ?> 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 13, 2020 Share Posted December 13, 2020 11 minutes ago, evolve hosting said: It's not as simple as this, is it? nearly - I don't like the look of that str_replace line - it would either have to be two separate replace lines, or you use an array, for the string variables... $gd2 = str_replace(array($authorize, $authorizeecheck), '', $gatewaydropdown); 0 Quote Link to comment Share on other sites More sharing options...
Evolve Web Hosting Posted December 13, 2020 Share Posted December 13, 2020 There's something about it that's not allowing it to work. Would the customers default payment method matter? Right now, their default payment method is one that I do not want to offer once this hook executes. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 13, 2020 Share Posted December 13, 2020 10 minutes ago, evolve hosting said: Would the customers default payment method matter? yes - this hook wouldn't change it... it only affects the values in the dropdown menu. 19 minutes ago, evolve hosting said: Right now, their default payment method is one that I do not want to offer once this hook executes. then i'd be tempted to run a database update to change the gateway assigned to the invoice.... I wrote a hook for the thread below which might be more suitable for your needs - I don't think I posted in publicly, so i'll send it via PM... there's also a link in there to Kian's version - i'm sure at least one of them will do the job you're looking for. 🙂 0 Quote Link to comment Share on other sites More sharing options...
Evolve Web Hosting Posted December 13, 2020 Share Posted December 13, 2020 39 minutes ago, brian! said: yes - this hook wouldn't change it... it only affects the values in the dropdown menu. When I used the hook, I was hoping to see 1 of the 3 available gateways not offered. All 3 were options in the dropdown. Maybe it was a browser cache issue so I'll check that. I'm trying to force the customer to only pay by credit card or ACH (not paypal) when the invoice is over $200. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 13, 2020 Share Posted December 13, 2020 (edited) 13 minutes ago, evolve hosting said: When I used the hook, I was hoping to see 1 of the 3 available gateways not offered. All 3 were options in the dropdown. Maybe it was a browser cache issue so I'll check that. one other thing to look for would be if one of those gateways were the default or first, because their <option> code potentially wouldn't match your current strings, e.g it might include select="selected" ... using the array in the str_replace does work if the strings match. Edited December 13, 2020 by brian! 0 Quote Link to comment Share on other sites More sharing options...
J-B Posted February 18, 2021 Share Posted February 18, 2021 mhhh, it looks like this won't work anymore in 8.1.1 with twenty-one. function viewinvoice_gateway_removal_based_on_loggedin_status_hook($vars) { $client = Menu::context('client'); $paidinvoices = $vars['clientsstats']['numpaidinvoices']; if ($paidinvoices == 0) { $gatewaydropdown = $vars['gatewaydropdown']; $stripe = '<option value="stripe">VISA / Mastercard / American Express</option>'; $stripe_sepa = '<option value="stripe_sepa">SEPA Lastschrift</option>'; $gd2 = str_replace($stripe,'', $gatewaydropdown) ; $gd3 = str_replace(array ($stripe_sepa,$stripe), array ('','',), $gatewaydropdown); return array("gatewaydropdown" => $gd3); } } add_hook("ClientAreaPageViewInvoice", 1, "viewinvoice_gateway_removal_based_on_loggedin_status_hook"); Have you a idea @brian! why it no longer works? 0 Quote Link to comment Share on other sites More sharing options...
J-B Posted February 18, 2021 Share Posted February 18, 2021 I dont know, but is it a bug? The variable $gatewaydropdown has: $gatewaydropdown Origin: "Smarty object" Value "<input type="hidden" name="token" value="5af58813bf2507ab639cb9c0418f98961db8..." but not the <option> 0 Quote Link to comment Share on other sites More sharing options...
J-B Posted February 18, 2021 Share Posted February 18, 2021 Ok, the problem was the template. In six it was: <form method="post" action="{$smarty.server.PHP_SELF}?id={$invoiceid}" class="form-inline"> {$gatewaydropdown} </form> and in twenty-one: <form method="post" action="{$smarty.server.PHP_SELF}?id={$invoiceid}" class="form-inline"> {$tokenInput} <select name="gateway" class="custom-select" onchange="submit()"> {foreach $availableGateways as $gatewayModule => $gatewayName} <option value="{$gatewayModule}"{if $gatewayModule == $selectedGateway} selected="selected"{/if}>{$gatewayName}</option> {/foreach} </select> </form> Is it a secuity issue to need the $tokenInput? Or I can change back to {$gatewaydropdown}? 0 Quote Link to comment Share on other sites More sharing options...
J-B Posted February 18, 2021 Share Posted February 18, 2021 Ok I have now found a solution. Hook: $availableGateways = $vars['availableGateways']; $stripe = 'VISA / Mastercard / American Express'; $stripe_sepa = 'SEPA Lastschrift'; $gd3 = str_replace(array ($stripe_sepa,$stripe), array ('','',), $availableGateways); return array("availableGateways" => $gd3); And then change the template viewinvoice.tpl to: {foreach $availableGateways as $gatewayModule => $gatewayName} {if $gatewayName == ''} {else} <option value="{$gatewayModule}"{if $gatewayModule == $selectedGateway} selected="selected"{/if}>{$gatewayName}</option>{/if} {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted February 18, 2021 Share Posted February 18, 2021 8 hours ago, J-B said: Is it a secuity issue to need the $tokenInput? Or I can change back to {$gatewaydropdown}? oh if they've dumped gatewaydropdown in 21 and it's now a "normal" array, then stick with using the new way - that should be simpler for removing unwanted gateways. do I need to rewrite this for 21 or have you been able to do that yourself ? 0 Quote Link to comment Share on other sites More sharing options...
J-B Posted February 18, 2021 Share Posted February 18, 2021 7 minutes ago, brian! said: do I need to rewrite this for 21 or have you been able to do that yourself ? I have do. See 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted February 18, 2021 Share Posted February 18, 2021 10 hours ago, J-B said: Is it a secuity issue to need the $tokenInput? Or I can change back to {$gatewaydropdown}? You'll want the token as that is for CSRF and the token is used to ensure the request is coming from a form that was generated by the app and not some bot trying to do XSS attacks. 0 Quote Link to comment Share on other sites More sharing options...
JuanH Posted January 27, 2022 Share Posted January 27, 2022 On 12/13/2020 at 5:02 PM, evolve hosting said: How would you modify this to include 2 gateway options? @brian! I'm more than happy to pay for your time. I know you contribute a LOT around here and it all takes time. It's not as simple as this, is it? <?php # ViewInvoice Gateway Hook # Written by brian! function hook_view_invoice_gateway($vars) { $client = $vars['clientsdetails']; $currency = $client['currency']; if ($currency == '1') { $gatewaylimit = 200; } elseif ($currency == '2') { $gatewaylimit = 75; } else { $gatewaylimit = 0; } if ($vars['status'] == 'Unpaid' && $vars['total']->toNumeric() <= $gatewaylimit) { $gatewaydropdown = $vars['gatewaydropdown']; $authorize = '<option value="authorize">Credit / Debit Card</option>'; $authorizeecheck = '<option value="authorizeecheck">ACH / Direct Debit</option>'; $gd2 = str_replace($authorize, $authorizeecheck, '', $gatewaydropdown) ; return array("gatewaydropdown" => $gd2); } } add_hook('ClientAreaPageViewInvoice', 1, 'hook_view_invoice_gateway'); ?> I've tried to follow along this thread, and adapt this hook to my own needs, but struggeling to make it work. Essentially, customers can have one of two currencies on my website. If EUR (currency 1), I'd like to limit the drop down on invoices to PayPal. If ZAR (currency 2), I'd like to limit the dropdown to PayFast. This is the hook I modified from the above: <?php # ViewInvoice Gateway Hook # Written by brian! function hook_view_invoice_gateway($vars) { $client = $vars['clientsdetails']; $currency = $client['currency']; if ($vars['status'] == 'Unpaid' && $currency == '1') { $gatewaydropdown = $vars['gatewaydropdown']; $paypalcheckout = '<option value="paypalcheckout">PayPal</option>'; $gd2 = str_replace($paypalcheckout, '', $gatewaydropdown) ; return array("gatewaydropdown" => $gd2); } elseif ($vars['status'] == 'Unpaid' && $currency == '2') { $gatewaydropdown = $vars['gatewaydropdown']; $payfast = '<option value="payfast">PayFast</option>'; $gd2 = str_replace($payfast, '', $gatewaydropdown) ; return array("gatewaydropdown" => $gd2); } } add_hook('ClientAreaPageViewInvoice', 1, 'hook_view_invoice_gateway'); ?> Can someone please help me figure out where I'm going wrong? 0 Quote Link to comment Share on other sites More sharing options...
FutureX Posted July 24, 2023 Share Posted July 24, 2023 I'm trying this but it's not working. I just want to remove the 'mailin' option from the dropdown on the view invoice page. <?php # ViewInvoice Gateway Hook function hook_view_invoice_gateway($vars) { if ($vars['status'] == 'Unpaid' && $vars['total']->toNumeric() >= 0) { $gateways = $vars['availableGateways']; $remove = ['mailin']; if (isset($gateways[$remove])) { unset($gateways[$remove]); } return array("availableGateways" => $gateways); } } add_hook('ClientAreaPageViewInvoice', 1, 'hook_view_invoice_gateway'); ?> 0 Quote Link to comment Share on other sites More sharing options...
FutureX Posted August 1, 2023 Share Posted August 1, 2023 Anyone have any idea on this? 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.