Jump to content

Add Gateway Charge - Addon Issue


pRieStaKos

Recommended Posts

Hello, im trying to make an addon for adding a gateway charge but I cant make it run after the client checks the payment method and proceed to view invoice.

 

My hook is the following:

 

function hook_fee_InvoiceChangeGateway($vars)
{
   include "lang/greek.php";
   try {
       $invoiceid = $vars['invoiceid'];
       $paymentmethod = $vars['paymentmethod'];

       // Get invoice subtotal
       $query = Capsule::table('tblinvoices')
           ->where('id', $invoiceid)
           ->where('paymentmethod', $paymentmethod)
           ->get();
       $totalDue = $query->subtotal;
       $userid = $query->userid;

       if ($paymentmethod == 'paypal') {
           // Get Gateway fee
           $query = Capsule::table('mod_fee')->where('gateway', $paymentmethod)->get();
           // Recalculate
           $percentageFee = $query->percentage;
           $amountFee = ($percentageFee / 100) * $totalDue;
           // Add gateway charge to invoice as item
           Capsule::table('tblinvoiceitems')->insert(
               [
                   'invoiceid' => $invoiceid,
                   'userid' => $userid,
                   'type' => 'GatewayCharge',
                   'relid' => '',
                   'description' => 'Paypal 3.40%',
                   'amount' => $amountFee,
                   'taxed' => 1,
                   'duedate' => 1,
                   'paymentmethod' => $paymentmethod,
                   'notes' => '',
               ]
           );
           echo "Gateway Charge of {$amountFee} is added to Invoice {$invoiceid}";
       } else {
           Capsule::table('tblinvoiceitems')
               ->where('type', 'GatewayCharge')
               ->where('invoiceid', $invoiceid)
               ->delete();
       }
   } catch (\Exception $e) {
       echo "Uh oh! {$e->getMessage()}";
   }
}
add_hook('InvoiceChangeGateway', 1, 'hook_fee_InvoiceChangeGateway');

 

Any suggestions why this hook is not running and not adding a new invoiceitem in the invoice with the charge ?

 

Thank you in advance

Edited by priestakos
Link to comment
Share on other sites

Hello Priestakos,

 

I am trying to do the same thing, however, I have found a module from ModulesGarden that does this for any payment gateway. It's called "Payment Gateway Charges". Have you looked into this? I'm having some issues with it so I was looking for other solutions, it seems you are developing your own addon to do the same thing, are you making it for a specific gateway? I am interested to know how it is going for you.

 

Thanks,

Nick

Link to comment
Share on other sites

there is an third-party module available from the App Store...

 

http://www.whmcs.com/appstore/1626/Set-Gateway-Transaction-Fee.html

 

I don't know if it's been updated for v6 (you should check with the developer before purchase), but their website (using v6) is still offering the module for a one-off $20.

 

also, there is an open-source Gateway Fee module @ GitHub... which, going by it's age, I assume works for v5 but probably not v6 - but it may help with your coding. :idea:

 

https://github.com/delta360/WHMCS-Gateway-Fees

Link to comment
Share on other sites

Hello Priestakos,

 

I am trying to do the same thing, however, I have found a module from ModulesGarden that does this for any payment gateway. It's called "Payment Gateway Charges". Have you looked into this? I'm having some issues with it so I was looking for other solutions, it seems you are developing your own addon to do the same thing, are you making it for a specific gateway? I am interested to know how it is going for you.

 

Thanks,

Nick

 

I manage to make progress, with a little help from my friend zstergios but I haven't finish it completly. I'm on a summer break.

 

Payment Gateway Charges from ModulesGarden got miss-calculate issues and on every update, I have to contact them in order to fix the calculation function again. I dont have the luxury to do it on every update. So I will do it on my own.

 

there is an third-party module available from the App Store...

 

http://www.whmcs.com/appstore/1626/Set-Gateway-Transaction-Fee.html

 

I don't know if it's been updated for v6 (you should check with the developer before purchase), but their website (using v6) is still offering the module for a one-off $20.

 

also, there is an open-source Gateway Fee module @ GitHub... which, going by it's age, I assume works for v5 but probably not v6 - but it may help with your coding. :idea:

 

https://github.com/delta360/WHMCS-Gateway-Fees

 

I already seen this and other open-source modules, even the WHMCS documentation (that should have been updated already, but its not). I already got the idea, but WHMCS seems not to run or log many of my functions.

 

Note: Due to development, I already updated my module source code, so I overcome many of my issues with WHMCS not running the hook. The above function code is old and changed.

Edited by priestakos
Link to comment
Share on other sites

Priestakos,

 

I tried private messaging you but I don't believe I have sufficient permissions as I am new on the forum. Would you be willing to possibly sell the module you're developing? I've considered purchasing the other third-party module from the App store that brian! mentioned but it has not been updated in quite some time so I am skeptical. Let me know if its even a possibility for you, we can discuss it further privately.

 

Nick

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