payment listeners

This commit is contained in:
David Bomba 2020-11-12 14:04:27 +11:00
parent 7af791a4c4
commit 5cd2ae0dbe
7 changed files with 154 additions and 8 deletions

View File

@ -11,8 +11,15 @@
namespace App\Events\Payment; namespace App\Events\Payment;
use App\Models\Client;
use App\Models\Company; use App\Models\Company;
use App\Models\Payment; use App\Models\Payment;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**
@ -20,7 +27,7 @@ use Illuminate\Queue\SerializesModels;
*/ */
class PaymentWasEmailed class PaymentWasEmailed
{ {
use SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
/** /**
* @var Payment * @var Payment

View File

@ -11,15 +11,23 @@
namespace App\Events\Payment; namespace App\Events\Payment;
use App\Models\Client;
use App\Models\Company;
use App\Models\Payment; use App\Models\Payment;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
/** /**
* Class InvoiceWasEmailedAndFailed. * Class PaymentWasEmailedAndFailed.
*/ */
class PaymentWasEmailedAndFailed class PaymentWasEmailedAndFailed
{ {
use SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
/** /**
* @var Payment * @var Payment
@ -39,7 +47,7 @@ class PaymentWasEmailedAndFailed
* @param array $errors * @param array $errors
* @param array $event_vars * @param array $event_vars
*/ */
public function __construct(Payment $payment, $company, array $errors, array $event_vars) public function __construct(Payment $payment, Company $company, array $errors, array $event_vars)
{ {
$this->payment = $payment; $this->payment = $payment;

View File

@ -46,7 +46,7 @@ class Handler extends ExceptionHandler
*/ */
protected $dontReport = [ protected $dontReport = [
PDOException::class, PDOException::class,
Swift_TransportException::class, //Swift_TransportException::class,
MaxAttemptsExceededException::class, MaxAttemptsExceededException::class,
CommandNotFoundException::class, CommandNotFoundException::class,
]; ];

View File

@ -72,7 +72,8 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue
* @return void * @return void
*/ */
public function handle() public function handle()
{info("inside email payment"); {
if($this->company->is_disabled) if($this->company->is_disabled)
return true; return true;
@ -85,8 +86,16 @@ class EmailPayment extends BaseMailerJob implements ShouldQueue
$email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build(); $email_builder = (new PaymentEmailEngine($this->payment, $this->contact))->build();
$mail = Mail::to($this->contact->email, $this->contact->present()->name()); try{
$mail->send(new TemplateEmail($email_builder, $this->contact->user, $this->contact->client));
$mail = Mail::to($this->contact->email, $this->contact->present()->name());
$mail->send(new TemplateEmail($email_builder, $this->contact->user, $this->contact->client));
}catch(\Exception $e) {
info("mailing failed with message " . $e->getMessage());
}
if (count(Mail::failures()) > 0) { if (count(Mail::failures()) > 0) {
event(new PaymentWasEmailedAndFailed($this->payment, Mail::failures(), Ninja::eventVars())); event(new PaymentWasEmailedAndFailed($this->payment, Mail::failures(), Ninja::eventVars()));

View File

@ -0,0 +1,57 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Payment;
use App\Jobs\Mail\EntityPaidMailer;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Notifications\Admin\NewPaymentNotification;
use App\Repositories\ActivityRepository;
use App\Utils\Ninja;
use App\Utils\Traits\Notifications\UserNotifies;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Notification;
class PaymentEmailFailureActivity implements ShouldQueue
{
use UserNotifies;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
}
/**
* Handle the event.
*
* @param object $event
* @return bool
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$payment = $event->payment;
info("i failed emailing {$payment->number}");
// info(print_r($event->errors,1));
}
}

View File

@ -0,0 +1,55 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Listeners\Payment;
use App\Jobs\Mail\EntityPaidMailer;
use App\Libraries\MultiDB;
use App\Models\Activity;
use App\Models\Invoice;
use App\Models\Payment;
use App\Notifications\Admin\NewPaymentNotification;
use App\Repositories\ActivityRepository;
use App\Utils\Ninja;
use App\Utils\Traits\Notifications\UserNotifies;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Notification;
class PaymentEmailedActivity implements ShouldQueue
{
use UserNotifies;
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
}
/**
* Handle the event.
*
* @param object $event
* @return bool
*/
public function handle($event)
{
MultiDB::setDb($event->company->db);
$payment = $event->payment;
info("i succeeded in emailing payment {$payment->number}");
}
}

View File

@ -51,6 +51,8 @@ use App\Events\Misc\InvitationWasViewed;
use App\Events\Payment\PaymentWasArchived; use App\Events\Payment\PaymentWasArchived;
use App\Events\Payment\PaymentWasCreated; use App\Events\Payment\PaymentWasCreated;
use App\Events\Payment\PaymentWasDeleted; use App\Events\Payment\PaymentWasDeleted;
use App\Events\Payment\PaymentWasEmailed;
use App\Events\Payment\PaymentWasEmailedAndFailed;
use App\Events\Payment\PaymentWasRefunded; use App\Events\Payment\PaymentWasRefunded;
use App\Events\Payment\PaymentWasRestored; use App\Events\Payment\PaymentWasRestored;
use App\Events\Payment\PaymentWasUpdated; use App\Events\Payment\PaymentWasUpdated;
@ -129,6 +131,8 @@ use App\Listeners\Invoice\InvoiceViewedActivity;
use App\Listeners\Invoice\UpdateInvoiceActivity; use App\Listeners\Invoice\UpdateInvoiceActivity;
use App\Listeners\Invoice\UpdateInvoiceInvitations; use App\Listeners\Invoice\UpdateInvoiceInvitations;
use App\Listeners\Misc\InvitationViewedListener; use App\Listeners\Misc\InvitationViewedListener;
use App\Listeners\Payment\PaymentEmailFailureActivity;
use App\Listeners\Payment\PaymentEmailedActivity;
use App\Listeners\Payment\PaymentNotification; use App\Listeners\Payment\PaymentNotification;
use App\Listeners\Payment\PaymentRestoredActivity; use App\Listeners\Payment\PaymentRestoredActivity;
use App\Listeners\Quote\QuoteApprovedActivity; use App\Listeners\Quote\QuoteApprovedActivity;
@ -310,6 +314,12 @@ class EventServiceProvider extends ServiceProvider
InvitationWasViewed::class => [ InvitationWasViewed::class => [
InvitationViewedListener::class, InvitationViewedListener::class,
], ],
PaymentWasEmailed::class => [
PaymentEmailedActivity::class,
],
PaymentWasEmailedAndFailed::class => [
PaymentEmailFailureActivity::class,
],
CompanyDocumentsDeleted::class => [ CompanyDocumentsDeleted::class => [
DeleteCompanyDocuments::class, DeleteCompanyDocuments::class,
], ],