From 71694d108dad6fd8a0a0b4dfe064c69ff4d3ed70 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 11 Jan 2017 14:06:15 +0200 Subject: [PATCH] Support queues for payment emails --- app/Jobs/SendPaymentEmail.php | 78 ++++++++++++++++++++++++++ app/Listeners/NotificationListener.php | 6 +- app/Ninja/Mailers/ContactMailer.php | 2 +- 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 app/Jobs/SendPaymentEmail.php diff --git a/app/Jobs/SendPaymentEmail.php b/app/Jobs/SendPaymentEmail.php new file mode 100644 index 000000000000..23a1d41ee8e8 --- /dev/null +++ b/app/Jobs/SendPaymentEmail.php @@ -0,0 +1,78 @@ +payment = $payment; + } + + /** + * Execute the job. + * + * @param ContactMailer $mailer + */ + public function handle(UserMailer $userMailer, ContactMailer $contactMailer, PushService $pushService) + { + $payment = $this->payment; + $invoice = $payment->invoice; + + $contactMailer->sendPaymentConfirmation($payment); + + $payment->account->load('users'); + foreach ($payment->account->users as $user) + { + if ($user->notify_paid) + { + $userMailer->sendNotification($user, $invoice, 'paid', $payment); + } + } + + $pushService->sendNotification($invoice, 'paid'); + } + + /** + * Handle a job failure. + * + * @param ContactMailer $mailer + * @param Logger $logger + */ + /* + public function failed(ContactMailer $mailer, Logger $logger) + { + $this->jobName = $this->job->getName(); + + parent::failed($mailer, $logger); + } + */ +} diff --git a/app/Listeners/NotificationListener.php b/app/Listeners/NotificationListener.php index ad94e5767a61..bd993a3701d7 100644 --- a/app/Listeners/NotificationListener.php +++ b/app/Listeners/NotificationListener.php @@ -9,6 +9,7 @@ use App\Events\QuoteInvitationWasViewed; use App\Events\QuoteInvitationWasApproved; use App\Events\PaymentWasCreated; use App\Services\PushService; +use App\Jobs\SendPaymentEmail; /** * Class NotificationListener @@ -120,10 +121,7 @@ class NotificationListener return; } - $this->contactMailer->sendPaymentConfirmation($event->payment); - $this->sendEmails($event->payment->invoice, 'paid', $event->payment); - - $this->pushService->sendNotification($event->payment->invoice, 'paid'); + dispatch(new SendPaymentEmail($event->payment)); } } diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index d6db736a1889..f63df4b75e6e 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -137,7 +137,7 @@ class ContactMailer extends Mailer * @throws \Laracasts\Presenter\Exceptions\PresenterException */ private function sendInvitation( - Invitation$invitation, + Invitation $invitation, Invoice $invoice, $body, $subject,