Jump to content

Payment Gateway Fee


sol2010

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

 

 

 

 

 

Link to comment
Share on other sites

  • 2 weeks later...

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. 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 3 weeks later...
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 by sol2010
Link to comment
Share on other sites

@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]);
}

 

 

 

Link to comment
Share on other sites

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 by yggdrasil
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
        }

 

 

Link to comment
Share on other sites

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 🙂 

Link to comment
Share on other sites

  • 5 months later...

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?

Link to comment
Share on other sites

  • 4 months later...

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 

Link to comment
Share on other sites

  • 7 months later...

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