atlanticadigital Posted November 13, 2019 Share Posted November 13, 2019 Hi.Could someone help me develop a hook, to limit to X payment method if the invoice amount is less than or equal to X value? Thank you very much Diego 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted November 13, 2019 Share Posted November 13, 2019 For sure there are more elegant ways but this hook should work. <?php use Illuminate\Database\Capsule\Manager as Capsule; add_hook('ClientAreaPageViewInvoice', 1, function($vars) { $Data = Capsule::select(Capsule::raw('SELECT total, paymentmethod FROM tblinvoices WHERE id = "' . $vars['invoiceid'] . '" LIMIT 1')); /** * Use Gateway System Name as key and amount as value * * Invoice total 10 -> banktransfer * Invoice total 15 -> banktransfer * Invoice total 20 -> katamaze_bnlpositivity * Invoice total 30 -> katamaze_gestpay * Invoice total 40 -> katamaze_nexi */ $Gateways['banktransfer'] = 10; $Gateways['katamaze_bnlpositivity'] = 20; $Gateways['katamaze_gestpay'] = 30; $Gateways['katamaze_nexi'] = 40; foreach ($Gateways as $k => $v) { if ($Data[0]->total >= $v) { $AssignedGateway = $k; } } if ($AssignedGateway != $Data[0]->paymentmethod) { localAPI('UpdateInvoice', array('invoiceid' => $vars['invoiceid'], 'paymentmethod' => $AssignedGateway), $adminUsername); header('Location: viewinvoice.php?id=' . $vars['invoiceid']); die(); } }); Every time customer changes payment method or view the invoice, the hook triggers and set the correct payment method depending on invoice total. 0 Quote Link to comment Share on other sites More sharing options...
atlanticadigital Posted November 13, 2019 Author Share Posted November 13, 2019 Kian, Thanks. I'm going to try it and then I'll tell you. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 14, 2019 Share Posted November 14, 2019 11 hours ago, Kian said: For sure there are more elegant ways but this hook should work. if the site were multi-currency, then you would need to get the clients currency too - otherwise you wouldn't know if the invoice amount was $100, €100 or £100. 0 Quote Link to comment Share on other sites More sharing options...
atlanticadigital Posted November 14, 2019 Author Share Posted November 14, 2019 Thank you! The system uses only one currency.However I could not make it work. I do not understand the hook, how to determine if it is greater than or equal to 20 dollars for example, to use certain payment systems and if it is less than 20 dollars other certain payment systems.I feel my awkwardness. Could you explain me?Thank you 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted November 14, 2019 Share Posted November 14, 2019 (edited) 1 hour ago, atlanticadigital said: I feel my awkwardness I feel my awkwardness for posting that script. I coded it a lot of time ago for unknown reasons 😄 As I said earlier it's not very elegant and @brian! is right about multi-currency. Anyway it loops through all gateway key/value pairs to find the one with the highest limit according to invoice amount. Example: <?php $InvoiceTotal = 35; $Gateways['banktransfer'] = 10; $Gateways['bnlpositivity'] = 20; $Gateways['gestpay'] = 30; $Gateways['nexi'] = 40; foreach ($Gateways as $k => $v) { echo 'Use ' . strtoupper($k) . ' gateway when amount is greater than or equal to ' . $v . '<br>'; echo 'Is ' . $InvoiceTotal . ' (invoice amount) greater than or equal to ' . $v . '?<br>'; if ($InvoiceTotal >= $v) { echo 'Yes! Let\'s use ' . strtoupper($k); } else { echo 'Nope!'; } echo '<br><br>'; } /* Prints... Use BANKTRANSFER gateway when amount is greater than or equal to 10 Is 35 (invoice amount) greater than or equal to 10? Yes! Let's use BANKTRANSFER Use BNLPOSITIVITY gateway when amount is greater than or equal to 20 Is 35 (invoice amount) greater than or equal to 20? Yes! Let's use BNLPOSITIVITY Use GESTPAY gateway when amount is greater than or equal to 30 Is 35 (invoice amount) greater than or equal to 30? Yes! Let's use GESTPAY Use NEXI gateway when amount is greater than or equal to 40 Is 35 (invoice amount) greater than or equal to 40? Nope! */ Long story short GESTPAY will be used as gateway. If invoice amount changes to 40 the gateway will be set to NEXI. If it drops to 15 BANKTRANSFER and so on. As I said for sure there are better ways but now I wanna start playing League of Legends 😛 Edited November 14, 2019 by Kian 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 15, 2019 Share Posted November 15, 2019 16 hours ago, Kian said: As I said earlier it's not very elegant and @brian! is right about multi-currency. your solution is also dependent upon Clients Choose Gateway not being enabled - otherwise, the client can just switch to another gateway on the invoice page gateway dropdown. 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.