1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Fixes for incorrect fee calculation edge case

This commit is contained in:
David Bomba 2021-09-22 11:57:03 +10:00
parent 0c89f998eb
commit a66fa1c678

View File

@ -70,7 +70,7 @@ class AutoBillInvoice extends AbstractService
/* Determine $amount */ /* Determine $amount */
if ($this->invoice->partial > 0) { if ($this->invoice->partial > 0) {
$is_partial = true; $is_partial = true;
$invoice_total = $this->invoice->amount; $invoice_total = $this->invoice->balance;
$amount = $this->invoice->partial; $amount = $this->invoice->partial;
} elseif ($this->invoice->balance > 0) { } elseif ($this->invoice->balance > 0) {
$amount = $this->invoice->balance; $amount = $this->invoice->balance;
@ -94,10 +94,14 @@ class AutoBillInvoice extends AbstractService
/* $gateway fee */ /* $gateway fee */
$this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $gateway_token->gateway_type_id, $amount)->save(); $this->invoice = $this->invoice->service()->addGatewayFee($gateway_token->gateway, $gateway_token->gateway_type_id, $amount)->save();
//change from $this->invoice->amount to $this->invoice->balance
if($is_partial) if($is_partial)
$fee = $this->invoice->amount - $invoice_total; $fee = $this->invoice->balance - $invoice_total;
else else
$fee = $this->invoice->amount - $amount; $fee = $this->invoice->balance - $amount;
if($fee > $amount)
$fee = 0;
/* Build payment hash */ /* Build payment hash */
$payment_hash = PaymentHash::create([ $payment_hash = PaymentHash::create([