Fixes for gateway fees

This commit is contained in:
David Bomba 2021-04-23 15:26:58 +10:00
parent 92e834c4e5
commit ac3b0dfad3
2 changed files with 33 additions and 5 deletions

View File

@ -269,15 +269,37 @@ class CompanyGateway extends BaseModel
*/ */
public function calcGatewayFeeLabel($amount, Client $client, $gateway_type_id = GatewayType::CREDIT_CARD) :string public function calcGatewayFeeLabel($amount, Client $client, $gateway_type_id = GatewayType::CREDIT_CARD) :string
{ {
$label = ''; $label = ' ';
$fee = $this->calcGatewayFee($amount, $gateway_type_id); $fee = $this->calcGatewayFee($amount, $gateway_type_id);
if ($fee > 0) { // if ($fee > 0) {
$fee = Number::formatMoney(round($fee, 2), $client); // $fee = Number::formatMoney(round($fee, 2), $client);
$label = ' - '.$fee.' '.ctrans('texts.fee'); // $label = ' - '.$fee.' '.ctrans('texts.fee');
// }
if($fee > 0) {
$fees_and_limits = $this->fees_and_limits->{$gateway_type_id};
if(strlen($fees_and_limits->fee_percent) >=1)
$label .= $fees_and_limits->fee_percent . '%';
if(strlen($fees_and_limits->fee_amount) >=1){
if(strlen($label) > 1) {
$label .= ' + ' . Number::formatMoney($fees_and_limits->fee_amount, $client);
}else {
$label .= Number::formatMoney($fees_and_limits->fee_amount, $client);
}
}
} }
return $label; return $label;
} }

View File

@ -271,7 +271,7 @@ class BaseDriver extends AbstractPaymentDriver
$invoices->each(function ($invoice) use ($fee_total) { $invoices->each(function ($invoice) use ($fee_total) {
if (collect($invoice->line_items)->contains('type_id', '3')) { if (collect($invoice->line_items)->contains('type_id', '3')) {
$invoice->service()->toggleFeesPaid()->save(); $invoice->service()->toggleFeesPaid()->deletePdf()->save();
$invoice->client->service()->updateBalance($fee_total)->save(); $invoice->client->service()->updateBalance($fee_total)->save();
$invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}"); $invoice->ledger()->updateInvoiceBalance($fee_total, "Gateway fee adjustment for invoice {$invoice->number}");
} }
@ -370,6 +370,12 @@ class BaseDriver extends AbstractPaymentDriver
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get(); $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
$invoices->each(function ($invoice){
$invoice->service()->deletePdf();
});
$invoices->first()->invitations->each(function ($invitation) use ($nmo){ $invoices->first()->invitations->each(function ($invitation) use ($nmo){
if ($invitation->contact->send_email && $invitation->contact->email) { if ($invitation->contact->send_email && $invitation->contact->email) {