From ac3b0dfad3afd574f304594c4ab95ff9d870c084 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 23 Apr 2021 15:26:58 +1000 Subject: [PATCH 1/2] Fixes for gateway fees --- app/Models/CompanyGateway.php | 30 ++++++++++++++++++++++++++---- app/PaymentDrivers/BaseDriver.php | 8 +++++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index 239666be3da3..6495fae14aaf 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -269,15 +269,37 @@ class CompanyGateway extends BaseModel */ public function calcGatewayFeeLabel($amount, Client $client, $gateway_type_id = GatewayType::CREDIT_CARD) :string { - $label = ''; + $label = ' '; $fee = $this->calcGatewayFee($amount, $gateway_type_id); - if ($fee > 0) { - $fee = Number::formatMoney(round($fee, 2), $client); - $label = ' - '.$fee.' '.ctrans('texts.fee'); + // if ($fee > 0) { + // $fee = Number::formatMoney(round($fee, 2), $client); + // $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; } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 32b4316ea6a6..534201dbc80b 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -271,7 +271,7 @@ class BaseDriver extends AbstractPaymentDriver $invoices->each(function ($invoice) use ($fee_total) { 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->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->each(function ($invoice){ + + $invoice->service()->deletePdf(); + + }); + $invoices->first()->invitations->each(function ($invitation) use ($nmo){ if ($invitation->contact->send_email && $invitation->contact->email) { From b4945220e8c31ce8a822a708d487aa802dd8227b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 24 Apr 2021 23:19:46 +1000 Subject: [PATCH 2/2] Analytics --- app/DataMapper/Analytics/EmailFailure.php | 18 ++++++ app/DataMapper/Analytics/EmailSuccess.php | 76 +++++++++++++++++++++++ app/Jobs/Mail/NinjaMailerJob.php | 5 +- 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 app/DataMapper/Analytics/EmailSuccess.php diff --git a/app/DataMapper/Analytics/EmailFailure.php b/app/DataMapper/Analytics/EmailFailure.php index 905888418d27..a1820f855096 100644 --- a/app/DataMapper/Analytics/EmailFailure.php +++ b/app/DataMapper/Analytics/EmailFailure.php @@ -54,4 +54,22 @@ class EmailFailure * @var string */ public $string_metric6 = ''; + + /** + * The counter + * set to 1. + * + * @var string + */ + public $int_metric1 = 1; + + /** + * Company Key + * @var string + */ + public $string_metric7 = ''; + + public function __construct($string_metric7) { + $this->string_metric7 = $string_metric7; + } } diff --git a/app/DataMapper/Analytics/EmailSuccess.php b/app/DataMapper/Analytics/EmailSuccess.php new file mode 100644 index 000000000000..760271f0da71 --- /dev/null +++ b/app/DataMapper/Analytics/EmailSuccess.php @@ -0,0 +1,76 @@ +string_metric7 = $string_metric7; + } +} diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index e4d16ec978fc..04b73dc0b052 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -12,6 +12,7 @@ namespace App\Jobs\Mail; use App\DataMapper\Analytics\EmailFailure; +use App\DataMapper\Analytics\EmailSuccess; use App\Events\Invoice\InvoiceWasEmailedAndFailed; use App\Events\Payment\PaymentWasEmailedAndFailed; use App\Jobs\Mail\NinjaMailerObject; @@ -180,6 +181,8 @@ class NinjaMailerJob implements ShouldQueue $message->getHeaders()->addTextHeader('GmailToken', $token); }); + LightLogs::create(new EmailSuccess($this->nmo->company_key->company_key)) + ->batch(); } private function logMailError($errors, $recipient_object) @@ -198,7 +201,7 @@ class NinjaMailerJob implements ShouldQueue nlog('mailer job failed'); nlog($exception->getMessage()); - $job_failure = new EmailFailure(); + $job_failure = new EmailFailure($this->nmo->company->company_key); $job_failure->string_metric5 = get_parent_class($this); $job_failure->string_metric6 = $exception->getMessage();