sol2010 Posted September 7, 2022 Share Posted September 7, 2022 I have forked the (now closed) original Payment gateway fee module, which is open source: https://github.com/solaceten/WHMCS-Gateway-Fees Feel free to contribute to keep it up to date. I like the free tools - shame to see it die off. @leemahoney3 @brian! 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted September 7, 2022 Share Posted September 7, 2022 Hi sol2010, Take it this doesn't work anymore? I can update it if you wish. 1 Quote Link to comment Share on other sites More sharing options...
tektaam Posted September 9, 2022 Share Posted September 9, 2022 Hi, I want to integrate WHMCS to custom payment gateway. So, I have installed the new module and uploaded it to the folder of my WHMCS. but the Custome payment gateway did not appear in the setup->payment gateway. Kindly help me this issue thank you. 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted September 9, 2022 Author Share Posted September 9, 2022 On 9/8/2022 at 4:03 AM, leemahoney3 said: Hi sol2010, Take it this doesn't work anymore? I can update it if you wish. @leemahoney3 No it works fine, I was just sharing it - seems the original dev has closed it. Good to keep it working. You can check the milestones for dev. I thought would be good to add a fee cap. 3 hours ago, tektaam said: Hi, I want to integrate WHMCS to custom payment gateway. So, I have installed the new module and uploaded it to the folder of my WHMCS. but the Custome payment gateway did not appear in the setup->payment gateway. Kindly help me this issue thank you. @tektaam this is not a payment gateway - it is an Addon. Kindly read the READ ME https://github.com/solaceten/WHMCS-Gateway-Fees 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted September 21, 2022 Author Share Posted September 21, 2022 @leemahoney3 Could you help with this ? https://github.com/solaceten/WHMCS-Gateway-Fees/milestones 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted September 21, 2022 Share Posted September 21, 2022 Couple items I noted in the code: Replace raw queries with eloquent models -- using objects will be a lot easier on you, future you, and others to read what is going on updateInvoiceTotal function call isn't defined in the module - is that an internal WHMCS function? That milestone could be done as a separate module table and an interface to manage it or a module setting with comma limited values - for example: stripe:25,mailin:1000 . To do the single field method, it would be best user wise to do the formatting for them and enter the values via javascript. Isn't there a hook floating around this community also that does this? That module is mainly a hook so may have come from that. 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted September 23, 2022 Author Share Posted September 23, 2022 On 9/22/2022 at 6:40 AM, steven99 said: Couple items I noted in the code: Replace raw queries with eloquent models -- using objects will be a lot easier on you, future you, and others to read what is going on updateInvoiceTotal function call isn't defined in the module - is that an internal WHMCS function? That milestone could be done as a separate module table and an interface to manage it or a module setting with comma limited values - for example: stripe:25,mailin:1000 . To do the single field method, it would be best user wise to do the formatting for them and enter the values via javascript. Isn't there a hook floating around this community also that does this? That module is mainly a hook so may have come from that. Thanks for your comments. Can you jump in to the GIT? 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted October 12, 2022 Author Share Posted October 12, 2022 How to add a "fee cap" to the payment gateway Go Cardless? I want to show an extra field for "Max fee" input like this: https://github.com/solaceten/WHMCS-Gateway-Fees/issues/1 @leemahoney3 @steven99 My whmcs coding is not very good 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted October 12, 2022 Author Share Posted October 12, 2022 (edited) 1 hour ago, sol2010 said: How to add a "fee cap" to the payment gateway Go Cardless? I want to show an extra field for "Max fee" input like this: https://github.com/solaceten/WHMCS-Gateway-Fees/issues/1 @leemahoney3 @steven99 My whmcs coding is not very good Have made an attempt here: https://github.com/solaceten/WHMCS-Gateway-Fees/releases/tag/2.0 Edited October 12, 2022 by sol2010 0 Quote Link to comment Share on other sites More sharing options...
pRieStaKos Posted October 12, 2022 Share Posted October 12, 2022 (edited) Besides your attempts to refactor the code, can anyone verify the correct application of the gateway fee ? Is the charged amount correct, for example on PayPal ? Edited October 12, 2022 by pRieStaKos 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted October 15, 2022 Author Share Posted October 15, 2022 @pRieStaKos Yes, it works fine, just not the maxfee part (fee cap) -- Hi @leemahoney3 I've made some tweaks and changes https://github.com/solaceten/WHMCS-Gateway-Fees/releases/tag/2.02 It's basically working with the fees, but it's not calculating the maxfee cap. Here is the code in hooks.php file - can you suggest a correction? In particular, I don't think the function below is correct. function update_gateway_fee2($vars) { $paymentmethod = $vars['paymentmethod']; delete_query("tblinvoiceitems", "invoiceid='" . $vars[invoiceid] . "' and notes='gateway_fees'"); $result = select_query("tbladdonmodules", "setting,value", "setting='fee_2PC_" . $vars['paymentmethod'] . "' or setting='fee_1VAL_" . $vars[paymentmethod] . "' or setting='maxfee_" . $vars[paymentmethod] . "'"); while ($data = mysql_fetch_array($result)) { $params[$data[0]] = $data[1]; } $fee1 = ($params['fee_1VAL_' . $paymentmethod]); $fee2 = ($params['fee_2PC_' . $paymentmethod]); $maxfee = ($params['maxfee_' . $paymentmethod]); $total = InvoiceTotal($vars['invoiceid']); if ($total > 0) { $amountdue = $fee1 + $total * $fee2 / 100; if ($fee1 > 0 & $fee2 > 0) { $newtot = $fee1 . '+' . $fee2 . "%"; } elseif ($fee2 > 0) { $newtot = $fee2 . "%"; } elseif ($fee1 > 0) { $newtot = $fee1; } // check for maxfee ? // is this enough? if (isset($maxfee) & $maxfee > 0 & $newtot > $maxfee) { $newtot = $maxfee; } } if ($newtot) { insert_query("tblinvoiceitems", array( "userid" => $_SESSION['uid'], "invoiceid" => $vars[invoiceid], "type" => "Fee", "notes" => "gateway_fees", "description" => getGatewayName2($vars['paymentmethod']) . " Fees ($newtot)", "amount" => $amountdue, "taxed" => "0", "duedate" => "now()", "paymentmethod" => $vars[paymentmethod] )); } updateInvoiceTotal($vars[invoiceid]); } 0 Quote Link to comment Share on other sites More sharing options...
yggdrasil Posted October 15, 2022 Share Posted October 15, 2022 (edited) Just a reminder to everyone that PayPal and major credit cards do not allow to pass the customer the extra fees or advertise them. I don't agree with those policies since those are indeed extra fees over your product cost, but it is what it is sadly. Use this at your own risk. Here is some reading: https://creativegeniuslaw.com/why-you-cant-charge-clients-paypal-fees-what-to-do-about-it/ Edited October 15, 2022 by yggdrasil 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted October 15, 2022 Share Posted October 15, 2022 11 hours ago, sol2010 said: @pRieStaKos Yes, it works fine, just not the maxfee part (fee cap) -- Hi @leemahoney3 I've made some tweaks and changes https://github.com/solaceten/WHMCS-Gateway-Fees/releases/tag/2.02 It's basically working with the fees, but it's not calculating the maxfee cap. Here is the code in hooks.php file - can you suggest a correction? In particular, I don't think the function below is correct. function update_gateway_fee2($vars) { $paymentmethod = $vars['paymentmethod']; delete_query("tblinvoiceitems", "invoiceid='" . $vars[invoiceid] . "' and notes='gateway_fees'"); $result = select_query("tbladdonmodules", "setting,value", "setting='fee_2PC_" . $vars['paymentmethod'] . "' or setting='fee_1VAL_" . $vars[paymentmethod] . "' or setting='maxfee_" . $vars[paymentmethod] . "'"); while ($data = mysql_fetch_array($result)) { $params[$data[0]] = $data[1]; } $fee1 = ($params['fee_1VAL_' . $paymentmethod]); $fee2 = ($params['fee_2PC_' . $paymentmethod]); $maxfee = ($params['maxfee_' . $paymentmethod]); $total = InvoiceTotal($vars['invoiceid']); if ($total > 0) { $amountdue = $fee1 + $total * $fee2 / 100; if ($fee1 > 0 & $fee2 > 0) { $newtot = $fee1 . '+' . $fee2 . "%"; } elseif ($fee2 > 0) { $newtot = $fee2 . "%"; } elseif ($fee1 > 0) { $newtot = $fee1; } // check for maxfee ? // is this enough? if (isset($maxfee) & $maxfee > 0 & $newtot > $maxfee) { $newtot = $maxfee; } } if ($newtot) { insert_query("tblinvoiceitems", array( "userid" => $_SESSION['uid'], "invoiceid" => $vars[invoiceid], "type" => "Fee", "notes" => "gateway_fees", "description" => getGatewayName2($vars['paymentmethod']) . " Fees ($newtot)", "amount" => $amountdue, "taxed" => "0", "duedate" => "now()", "paymentmethod" => $vars[paymentmethod] )); } updateInvoiceTotal($vars[invoiceid]); } Hey sol, I'll take a look at this soon. 0 Quote Link to comment Share on other sites More sharing options...
lizzus Posted October 16, 2022 Share Posted October 16, 2022 works fine! 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted October 16, 2022 Author Share Posted October 16, 2022 On 10/16/2022 at 7:31 AM, leemahoney3 said: Hey sol, I'll take a look at this soon. Thanks for assistance. I've made a few more tweaks I'm guessing the issue will be with this part: $result = select_query("tbladdonmodules", "setting,value", "setting='fee_2PC_" . $vars['paymentmethod'] . "' or setting='fee_1VAL_" . $vars[paymentmethod] . "' or setting='maxfee_" . $vars[paymentmethod] . "'"); while ($data = mysql_fetch_array($result)) { Probably need to query maxfee_ separately, Also I 'm wondering if this part should be written like this instead: // check for maxfee ? // is this enough? if (isset($maxfee) && $maxfee > 0 && $newtot => $maxfee) { $newtot == $maxfee; } 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted October 17, 2022 Share Posted October 17, 2022 On 10/16/2022 at 10:13 PM, sol2010 said: Thanks for assistance. I've made a few more tweaks I'm guessing the issue will be with this part: $result = select_query("tbladdonmodules", "setting,value", "setting='fee_2PC_" . $vars['paymentmethod'] . "' or setting='fee_1VAL_" . $vars[paymentmethod] . "' or setting='maxfee_" . $vars[paymentmethod] . "'"); while ($data = mysql_fetch_array($result)) { Probably need to query maxfee_ separately, Also I 'm wondering if this part should be written like this instead: // check for maxfee ? // is this enough? if (isset($maxfee) && $maxfee > 0 && $newtot => $maxfee) { $newtot == $maxfee; } Hey sol, Not forgetting about this, I'll try my best to take a look tomorrow 🙂 0 Quote Link to comment Share on other sites More sharing options...
leemahoney3 Posted October 17, 2022 Share Posted October 17, 2022 (edited) Hey sol, Had a chance to take a peek, I've cleaned up the code a bit and implemented the maximum fees. There's a pull request for you to review in your GitHub. (updated code is on the proposed-changes branch) Edited October 17, 2022 by leemahoney3 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted October 24, 2022 Author Share Posted October 24, 2022 Thank you @leemahoney3 really good of you to help. It's working great now. https://github.com/solaceten/WHMCS-Gateway-Fees Thanks again! 0 Quote Link to comment Share on other sites More sharing options...
sixfive Posted March 27, 2023 Share Posted March 27, 2023 Hi @sol2010 I've started using this module, and the fees show up in the invoice no issues. However when the Daily automations send the invoice for payment in Stripe, the fee added by the module is not being charged. This means we are getting every invoice paid, but it's missing the stripe fee. Super odd that the Stripe Gateway is not getting the invoice totel, including the fee. WHMCS v8.6.1 on PHP 8.1 if that may make a difference. We are in Australia and are allowed to on charge fees. Can you help me work out why that would be please? 0 Quote Link to comment Share on other sites More sharing options...
faheemsdq Posted August 20, 2023 Share Posted August 20, 2023 Hi, I converted it to make compatible with php 8.1 There are 2 issues: 1- Fee is not applying on checkout page, (good thing is that the payment without fee failed on checkout but is annoying). But once customer goes to Invoices, then the fee add to invoice 2- After Auto Termination of account, invoice gets cancelled but only fee remains in the invoice Please help to fix. =====gayeway_fees.php ===code: <?php if (!defined("WHMCS")) die("This file cannot be accessed directly"); use Illuminate\Database\Capsule\Manager as Capsule; function gateway_fees_config() { $configarray = [ "name" => "Gateway Fees for WHMCS", "description" => "Add fees based on the gateway being used.", "version" => "1.0.1", "author" => "Open Source" ]; $gateways = Capsule::table('tblpaymentgateways')->distinct()->get(['gateway']); foreach ($gateways as $gateway) { $configarray['fields']["fee_1_" . $gateway->gateway] = [ "FriendlyName" => $gateway->gateway, "Type" => "text", "Default" => "0.00", "Description" => "$" ]; $configarray['fields']["fee_2_" . $gateway->gateway] = [ "FriendlyName" => $gateway->gateway, "Type" => "text", "Default" => "0.00", "Description" => "%<br />" ]; } return $configarray; } function gateway_fees_activate() { $gateways = Capsule::table('tblpaymentgateways')->distinct()->get(['gateway']); foreach ($gateways as $gateway) { $query1 = "INSERT INTO `tbladdonmodules` (module, setting, value) VALUES ('gateway_fees', 'fee_1_" . $gateway->gateway . "', '0.00')"; Capsule::statement($query1); $query2 = "INSERT INTO `tbladdonmodules` (module, setting, value) VALUES ('gateway_fees', 'fee_2_" . $gateway->gateway . "', '0.00 ')"; Capsule::statement($query2); } } ?> ================== =======hook.php===== code: <?php function update_gateway_fee3($vars) { $id = $vars['invoiceid']; updateInvoiceTotal($id); } function update_gateway_fee1($vars) { $id = $vars['invoiceid']; $result = select_query("tblinvoices", '', ["id" => $id]); $data = mysql_fetch_array($result); update_gateway_fee2([ 'paymentmethod' => $data['paymentmethod'], "invoiceid" => $data['id'] ]); } function update_gateway_fee2($vars) { $paymentmethod = $vars['paymentmethod']; delete_query("tblinvoiceitems", "invoiceid='" . $vars['invoiceid'] . "' and notes='gateway_fees'"); $result = select_query("tbladdonmodules", "setting,value", "setting='fee_2_" . $vars['paymentmethod'] . "' or setting='fee_1_" . $vars['paymentmethod'] . "'"); while ($data = mysql_fetch_array($result)) { $params[$data[0]] = $data[1]; } $fee1 = ($params['fee_1_' . $paymentmethod]); $fee2 = ($params['fee_2_' . $paymentmethod]); $total = InvoiceTotal($vars['invoiceid']); if ($total > 0) { $amountdue = $fee1 + $total * $fee2 / 100; if ($fee1 > 0 && $fee2 > 0) { $d = $fee1 . '+' . $fee2 . "%"; } elseif ($fee2 > 0) { $d = $fee2 . "%"; } elseif ($fee1 > 0) { $d = $fee1; } } if ($d) { insert_query("tblinvoiceitems", [ "userid" => $_SESSION['uid'], "invoiceid" => $vars['invoiceid'], "type" => "Fee", "notes" => "gateway_fees", "description" => getGatewayName2($vars['paymentmethod']) . " Fees ($d)", "amount" => $amountdue, "taxed" => "0", "duedate" => "now()", "paymentmethod" => $vars['paymentmethod'] ]); } updateInvoiceTotal($vars['invoiceid']); } add_hook("InvoiceChangeGateway", 1, "update_gateway_fee2"); add_hook("InvoiceCreated", 1, "update_gateway_fee1"); add_hook("AdminInvoicesControlsOutput", 2, "update_gateway_fee3"); add_hook("AdminInvoicesControlsOutput", 1, "update_gateway_fee1"); add_hook("InvoiceCreationAdminArea", 1, "update_gateway_fee1"); add_hook("InvoiceCreationAdminArea", 2, "update_gateway_fee3"); function InvoiceTotal($id) { global $CONFIG; $result = select_query("tblinvoiceitems", "", ["invoiceid" => $id]); while ($data = mysql_fetch_array($result)) { if ($data['taxed'] == "1") { $taxsubtotal+= $data['amount']; } else { $nontaxsubtotal+= $data['amount']; } } $subtotal = $total = $nontaxsubtotal + $taxsubtotal; $result = select_query("tblinvoices", "userid,credit,taxrate,taxrate2", ["id" => $id]); $data = mysql_fetch_array($result); $userid = $data['userid']; $credit = $data['credit']; $taxrate = $data['taxrate']; $taxrate2 = $data['taxrate2']; if (!function_exists("getClientsDetails")) { require_once (dirname(__FILE__) . "/clientfunctions.php"); } $clientsdetails = getClientsDetails($userid); $tax = $tax2 = 0; if ($CONFIG['TaxEnabled'] == "on" && !$clientsdetails['taxexempt']) { if ($taxrate != "0.00") { if ($CONFIG['TaxType'] == "Inclusive") { $taxrate = $taxrate / 100 + 1; $calc1 = $taxsubtotal / $taxrate; $tax = $taxsubtotal - $calc1; } else { $taxrate = $taxrate / 100; $tax = $taxsubtotal * $taxrate; } } if ($taxrate2 != "0.00") { if ($CONFIG['TaxL2Compound']) { $taxsubtotal+= $tax; } if ($CONFIG['TaxType'] == "Inclusive") { $taxrate2 = $taxrate2 / 100 + 1; $calc1 = $taxsubtotal / $taxrate2; $tax2 = $taxsubtotal - $calc1; } else { $taxrate2 = $taxrate2 / 100; $tax2 = $taxsubtotal * $taxrate2; } } $tax = round($tax, 2); $tax2 = round($tax2, 2); } if ($CONFIG['TaxType'] == "Inclusive") { $subtotal = $subtotal - $tax - $tax2; } else { $total = $subtotal + $tax + $tax2; } if (0 < $credit) { if ($total < $credit) { $total = 0; $remainingcredit = $total - $credit; } else { $total-= $credit; } } $subtotal = format_as_currency($subtotal); $tax = format_as_currency($tax); $total = format_as_currency($total); return $total; } function getGatewayName2($modulename) { $result = select_query("tblpaymentgateways", "value", ["gateway" => $modulename, "setting" => "name"]); $data = mysql_fetch_array($result); return $data["value"]; } ?> ================ Regards 0 Quote Link to comment Share on other sites More sharing options...
sol2010 Posted April 8 Author Share Posted April 8 @sixfive Latest release fixes that: https://github.com/solaceten/WHMCS-Gateway-Fees @faheemsdq Thanks but please use our GitHub repository for all comments, issues and contributions, so we can keep it all in the same place. https://github.com/solaceten/WHMCS-Gateway-Fees 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.