Skip to content

Commit

Permalink
Merge pull request #6 from g00g1/fix-fee-on-creation
Browse files Browse the repository at this point in the history
bugfix: add fee immediately after invoice creation
  • Loading branch information
solaceten authored Apr 8, 2024
2 parents 2aefac5 + 39555d3 commit 6ac8da6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gateway Fees Plugin for WHMCS

Version: **2.5**
Version: **2.5.1**
Oct23 2022

This is an open-source forked version of the (Original) Gateway Fees plugin for WHMCS, https://github.com/ajarmoszuk/WHMCS-Gateway-Fees (now closed)
Expand Down
14 changes: 7 additions & 7 deletions modules/addons/gateway_fees/hooks.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// @ v2.5
// @ v2.5.1

use WHMCS\Session;
use WHMCS\User\Client;
Expand All @@ -15,6 +15,11 @@ function gatewayFees($vars) {
$invoiceId = $vars['invoiceid'];
$paymentMethod = $vars['paymentmethod'];

$invoiceData = localAPI('GetInvoice', ['invoiceid' => $invoiceId]);
if ($paymentMethod != $invoiceData['paymentmethod']) {
$paymentMethod = $invoiceData['paymentmethod'];
}

InvoiceItem::where(['invoiceid' => $invoiceId, 'notes' => 'gateway_fees'])->delete();

localAPI('UpdateInvoice', ['invoiceid' => $invoiceId]);
Expand All @@ -24,9 +29,6 @@ function gatewayFees($vars) {
$fee1 = $fee2 = $maxFee = 0;

$gatewayFees = AddonSetting::where('module', "gateway_fees")->get();




foreach ($gatewayFees as $fee) {
if ($fee->setting == "fixed_fee_{$paymentMethod}") {
Expand All @@ -47,8 +49,6 @@ function gatewayFees($vars) {

}

$invoiceData = localAPI('GetInvoice', ['invoiceid' => $invoiceId]);

$total = $invoiceData['subtotal'];

if ($total > 0) {
Expand Down Expand Up @@ -95,7 +95,7 @@ function gatewayFees($vars) {

}

add_hook("InvoiceCreated", 1, "gatewayFees");
add_hook("InvoiceCreation", 1, "gatewayFees");
add_hook("InvoiceChangeGateway", 1, "gatewayFees");
add_hook("InvoiceCreationAdminArea", 1, "gatewayFees");
add_hook("AdminInvoicesControlsOutput", 1, "gatewayFees");

0 comments on commit 6ac8da6

Please sign in to comment.