From b29831f8a436efc036e6595318bc496e4000569d Mon Sep 17 00:00:00 2001 From: = Date: Tue, 17 May 2022 11:18:34 +1000 Subject: [PATCH] Fixes for failed payment email --- app/Jobs/Mail/PaymentFailedMailer.php | 5 +++-- app/Utils/Traits/Notifications/UserNotifies.php | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Jobs/Mail/PaymentFailedMailer.php b/app/Jobs/Mail/PaymentFailedMailer.php index 3580e38bbff8..77f7585bdac1 100644 --- a/app/Jobs/Mail/PaymentFailedMailer.php +++ b/app/Jobs/Mail/PaymentFailedMailer.php @@ -111,9 +111,10 @@ class PaymentFailedMailer implements ShouldQueue //add client payment failures here. // - if($contact = $this->client->contacts()->first() && $this->payment_hash) + if($this->client->contacts()->whereNotNull('email')->exists() && $this->payment_hash) { - + $contact = $this->client->contacts()->whereNotNull('email')->first(); + $mail_obj = (new ClientPaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build(); $nmo = new NinjaMailerObject; diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index b6139708d200..3356a1b9f0f5 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -32,7 +32,11 @@ trait UserNotifies $notifiable_methods = []; $notifications = $company_user->notifications; - if ($invitation->company->is_disabled && is_array($notifications->email) || $company_user->trashed() || $company_user->user->trashed()) { + if ($invitation->company->is_disabled && + is_array($notifications->email) || + $company_user->trashed() || + !$company_user->user || + $company_user->user->trashed()) { return []; } @@ -56,7 +60,11 @@ trait UserNotifies $notifiable_methods = []; $notifications = $company_user->notifications; - if ($entity->company->is_disabled || ! $notifications || $company_user->trashed() || $company_user->user->trashed()) { + if ($entity->company->is_disabled || + ! $notifications || + $company_user->trashed() || + ! $company_user->user || + $company_user->user->trashed()) { return []; } @@ -125,7 +133,10 @@ trait UserNotifies public function findCompanyUserNotificationType($company_user, $required_permissions) :array { - if ($company_user->company->is_disabled || $company_user->trashed() || $company_user->user->trashed()) { + if ($company_user->company->is_disabled || + $company_user->trashed() || + !$company_user->user || + $company_user->user->trashed()) { return []; }