diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index f476f1ec6120..ffb5f525d838 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -53,11 +53,11 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue * @param $user * @param $company */ - public function __construct($payment, $user, $company) + public function __construct($payment, $company) { $this->company = $company; - $this->user = $user; + $this->user = $payment->user; $this->payment = $payment; @@ -82,16 +82,25 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue //if we need to set an email driver do it now $this->setMailDriver(); - $mail_obj = (new EntityPaidObject($this->payment))->build(); - $mail_obj->from = [$this->payment->user->email, $this->payment->user->present()->name()]; + try { - //send email - Mail::to($this->user->email) - ->send(new EntityNotificationMailer($mail_obj)); + $mail_obj = (new EntityPaidObject($this->payment))->build(); + $mail_obj->from = [$this->payment->user->email, $this->payment->user->present()->name()]; - //catch errors - if (count(Mail::failures()) > 0) { - return $this->logMailError(Mail::failures(), $this->payment->client); + //send email + Mail::to($this->user->email) + ->send(new EntityNotificationMailer($mail_obj)); + + } catch (Swift_TransportException $e) { + $this->failed($e->getMessage()); + //$this->entityEmailFailed($e->getMessage()); } + + if (count(Mail::failures()) > 0) { + $this->logMailError(Mail::failures(), $this->entity->client); + } else { + // $this->entityEmailSucceeded(); + } + } } diff --git a/app/Listeners/Payment/PaymentNotification.php b/app/Listeners/Payment/PaymentNotification.php index d5cedad39aae..8bf809f35f71 100644 --- a/app/Listeners/Payment/PaymentNotification.php +++ b/app/Listeners/Payment/PaymentNotification.php @@ -62,11 +62,8 @@ class PaymentNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); - //Fire mail notification here!!! - //This allows us better control of how we - //handle the mailer + EntityPaidMailer::dispatch($payment, $payment->company); - EntityPaidMailer::dispatch($payment, $user, $payment->company); } $notification = new NewPaymentNotification($payment, $payment->company); @@ -84,7 +81,6 @@ class PaymentNotification implements ShouldQueue } /*Google Analytics Track Revenue*/ - if (isset($payment->company->google_analytics_key)) { $this->trackRevenue($event); }