Support queues for payment emails

This commit is contained in:
Hillel Coren 2017-01-11 14:06:15 +02:00
parent dc034d06dd
commit 71694d108d
3 changed files with 81 additions and 5 deletions

View File

@ -0,0 +1,78 @@
<?php
namespace App\Jobs;
use App\Models\Payment;
use App\Ninja\Mailers\ContactMailer;
use App\Ninja\Mailers\UserMailer;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Services\PushService;
use Monolog\Logger;
use Carbon;
/**
* Class SendInvoiceEmail
*/
class SendPaymentEmail extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* @var Payment
*/
protected $payment;
/**
* Create a new job instance.
* @param UserMailer $userMailer
* @param ContactMailer $contactMailer
* @param PushService $pushService
*/
public function __construct($payment)
{
$this->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);
}
*/
}

View File

@ -9,6 +9,7 @@ use App\Events\QuoteInvitationWasViewed;
use App\Events\QuoteInvitationWasApproved; use App\Events\QuoteInvitationWasApproved;
use App\Events\PaymentWasCreated; use App\Events\PaymentWasCreated;
use App\Services\PushService; use App\Services\PushService;
use App\Jobs\SendPaymentEmail;
/** /**
* Class NotificationListener * Class NotificationListener
@ -120,10 +121,7 @@ class NotificationListener
return; return;
} }
$this->contactMailer->sendPaymentConfirmation($event->payment); dispatch(new SendPaymentEmail($event->payment));
$this->sendEmails($event->payment->invoice, 'paid', $event->payment);
$this->pushService->sendNotification($event->payment->invoice, 'paid');
} }
} }

View File

@ -137,7 +137,7 @@ class ContactMailer extends Mailer
* @throws \Laracasts\Presenter\Exceptions\PresenterException * @throws \Laracasts\Presenter\Exceptions\PresenterException
*/ */
private function sendInvitation( private function sendInvitation(
Invitation$invitation, Invitation $invitation,
Invoice $invoice, Invoice $invoice,
$body, $body,
$subject, $subject,