Fixes for gateway fees

This commit is contained in:
David Bomba 2020-08-26 11:14:15 +10:00
parent d57f0f9236
commit ff5d8ad871
2 changed files with 19 additions and 16 deletions

View File

@ -104,23 +104,23 @@ class PaymentController extends Controller
foreach($payable_invoices as $key => $payable_invoice)
{
$payable_invoice[$key]['amount'] = Number::parseFloat($payable_invoice['amount']);
$payable_invoice['amount'] = $payable_invoice[$key]['amount'];
$payable_invoices[$key]['amount'] = Number::parseFloat($payable_invoice['amount']);
$payable_invoice['amount'] = $payable_invoices[$key]['amount'];
$invoice = $invoices->first(function ($inv) use($payable_invoice) {
return $payable_invoice['invoice_id'] == $inv->hashed_id;
});
if($invoice)
$invoice->service()->addGatewayFee($gateway, $payable_invoice['amount'])->save();
// if($invoice)
// $invoice->service()->addGatewayFee($gateway, $payable_invoice['amount'])->save();
/*Update the payable amount to include the fee*/
$gateway_fee = $gateway->calcGatewayFee($payable_invoice['amount']);
// $gateway_fee = $gateway->calcGatewayFee($payable_invoice['amount']);
$payable_invoice[$key]['amount_with_fee'] = $payable_invoice['amount'] + $gateway_fee;
$payable_invoice[$key]['fee'] = $gateway_fee;
$payable_invoice[$key]['due_date'] = $this->formatDate($invoice->due_date, $invoice->client->date_format());
$payable_invoice[$key]['invoice_number'] = $invoice->number;
// $payable_invoices[$key]['amount_with_fee'] = $payable_invoice['amount'] + $gateway_fee;
// $payable_invoices[$key]['fee'] = $gateway_fee;
$payable_invoices[$key]['due_date'] = $this->formatDate($invoice->due_date, $invoice->client->date_format());
$payable_invoices[$key]['invoice_number'] = $invoice->number;
if(isset($invoice->po_number))
$additional_info = $invoice->po_number;
@ -129,7 +129,7 @@ class PaymentController extends Controller
else
$additional_info = $invoice->date;
$payable_invoice[$key]['additional_info'] = $additional_info;
$payable_invoices[$key]['additional_info'] = $additional_info;
}
@ -139,7 +139,7 @@ class PaymentController extends Controller
});
}
$payment_methods = auth()->user()->client->getPaymentMethods($amount);
$payment_methods = auth()->user()->client->getPaymentMethods(array_sum(array_column($payable_invoices, 'amount_with_fee')));
$payment_method_id = request()->input('payment_method_id');
$payment_hash = new PaymentHash;
@ -147,10 +147,13 @@ class PaymentController extends Controller
$payment_hash->data = $payable_invoices;
$payment_hash->save();
$invoice_totals = array_sum(array_column($payable_invoices,'amount'));
$fee_totals = $gateway->calcGatewayFee($invoice_totals);
$totals = [
'invoice_totals' => array_sum(array_column($payable_invoices,'amount')),
'fee_totals' => array_sum(array_column($payable_invoices, 'fee')),
'amount_with_fee' => array_sum(array_column($payable_invoices, 'amount_with_fee')),
'invoice_totals' => $invoice_totals,
'fee_totals' => $fee_totals,
'amount_with_fee' => $invoice_totals + $fee_totals,
];
$data = [

View File

@ -38,7 +38,7 @@
<dl>
<div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm leading-5 font-medium text-gray-500">
{{ ctrans('texts.totals') }}
{{ ctrans('texts.subtotal') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ App\Utils\Number::formatMoney($total['invoice_totals'], $client) }}
@ -50,7 +50,7 @@
{{ App\Utils\Number::formatMoney($total['fee_totals'], $client) }}
</dd>
<dt class="text-sm leading-5 font-medium text-gray-500">
{{ ctrans('texts.amount') }}
{{ ctrans('texts.total') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ App\Utils\Number::formatMoney($total['amount_with_fee'], $client) }}