diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 72d1c1680dae..85289b87c533 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -95,6 +95,7 @@ class InvoiceController extends Controller } $invoices->map(function ($invoice) { + $invoice->service()->removeUnpaidGatewayFees()->save(); $invoice->balance = Number::formatValue($invoice->balance, $invoice->client->currency()); $invoice->partial = Number::formatValue($invoice->partial, $invoice->client->currency()); diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index bdbb69a6f86c..c74d6721e7e5 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -163,19 +163,29 @@ class PaymentController extends Controller $first_invoice = $invoices->first(); - $fee_totals = round($gateway->calcGatewayFee($invoice_totals, true), $first_invoice->client->currency()->precision); + $starting_invoice_amount = $first_invoice->amount; - if (!$first_invoice->uses_inclusive_taxes) { - $fee_tax = 0; - $fee_tax += round(($first_invoice->tax_rate1 / 100) * $fee_totals, $first_invoice->client->currency()->precision); - $fee_tax += round(($first_invoice->tax_rate2 / 100) * $fee_totals, $first_invoice->client->currency()->precision); - $fee_tax += round(($first_invoice->tax_rate3 / 100) * $fee_totals, $first_invoice->client->currency()->precision); + // $fee_totals = round($gateway->calcGatewayFee($invoice_totals, true), $first_invoice->client->currency()->precision); - $fee_totals += $fee_tax; - } + // if (!$first_invoice->uses_inclusive_taxes) { + // $fee_tax = 0; + // $fee_tax += round(($first_invoice->tax_rate1 / 100) * $fee_totals, $first_invoice->client->currency()->precision); + // $fee_tax += round(($first_invoice->tax_rate2 / 100) * $fee_totals, $first_invoice->client->currency()->precision); + // $fee_tax += round(($first_invoice->tax_rate3 / 100) * $fee_totals, $first_invoice->client->currency()->precision); + + // $fee_totals += $fee_tax; + // } $first_invoice->service()->addGatewayFee($gateway, $invoice_totals)->save(); + /** + * + * The best way to determine the exact gateway fee is to not calculate it in isolation (due to rounding) + * but to simply add it as a line item, and then subtract the starting and finishing amounts of + * the invoice. + */ + $fee_totals = $first_invoice->amount - $starting_invoice_amount; + $payment_hash = new PaymentHash; $payment_hash->hash = Str::random(128); $payment_hash->data = $payable_invoices;