mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactoring emails
This commit is contained in:
parent
92c83100e0
commit
13e96121d7
@ -1,103 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityFailedSendObject;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\EntitySentObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/*Multi Mailer implemented*/
|
||||
|
||||
class EntityFailedSendMailer extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $user;
|
||||
|
||||
public $invitation;
|
||||
|
||||
public $entity_type;
|
||||
|
||||
public $entity;
|
||||
|
||||
public $settings;
|
||||
|
||||
public $template;
|
||||
|
||||
public $message;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $invitation
|
||||
* @param $entity_type
|
||||
* @param $user
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct($invitation, $entity_type, $user, $company, $template, $message)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->invitation = $invitation;
|
||||
|
||||
$this->entity = $invitation->{$entity_type};
|
||||
|
||||
$this->entity_type = $entity_type;
|
||||
|
||||
$this->settings = $invitation->contact->client->getMergedSettings();
|
||||
|
||||
$this->template = $template;
|
||||
|
||||
$this->message = $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled)
|
||||
return true;
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
//if we need to set an email driver do it now
|
||||
$this->setMailDriver();
|
||||
|
||||
$mail_obj = (new EntityFailedSendObject($this->invitation, $this->entity_type, $this->template, $this->message))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
try {
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
} catch (\Exception $e) {
|
||||
nlog("failing in EntityFailedSendMailer");
|
||||
//$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->entity->client);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\EntityPaidObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/*Multi Mailer implemented*/
|
||||
|
||||
class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $user;
|
||||
|
||||
public $payment;
|
||||
|
||||
public $entity_type;
|
||||
|
||||
public $entity;
|
||||
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $payment
|
||||
* @param $user
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct($payment, $company, $user)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->payment = $payment;
|
||||
|
||||
$this->settings = $payment->client->getMergedSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
//if we need to set an email driver do it now
|
||||
$this->setMailDriver();
|
||||
|
||||
try {
|
||||
$mail_obj = (new EntityPaidObject($this->payment))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
//send email
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
} catch (\Exception $e) {
|
||||
// //$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->payment->client);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\EntitySentObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/*Multi Mailer implemented*/
|
||||
|
||||
class EntitySentMailer extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $user;
|
||||
|
||||
public $invitation;
|
||||
|
||||
public $entity_type;
|
||||
|
||||
public $entity;
|
||||
|
||||
public $settings;
|
||||
|
||||
public $template;
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $invitation
|
||||
* @param $entity_type
|
||||
* @param $user
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct($invitation, $entity_type, $user, $company, $template)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->invitation = $invitation;
|
||||
|
||||
$this->entity = $invitation->{$entity_type};
|
||||
|
||||
$this->entity_type = $entity_type;
|
||||
|
||||
$this->settings = $invitation->contact->client->getMergedSettings();
|
||||
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled)
|
||||
return true;
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
//if we need to set an email driver do it now
|
||||
$this->setMailDriver();
|
||||
|
||||
$mail_obj = (new EntitySentObject($this->invitation, $this->entity_type, $this->template))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
try {
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
} catch (\Exception $e) {
|
||||
// //$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->entity->client);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Jobs\Mail;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\EntityViewedObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
/*Multi Mailer implemented*/
|
||||
|
||||
class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $company;
|
||||
|
||||
public $user;
|
||||
|
||||
public $invitation;
|
||||
|
||||
public $entity_type;
|
||||
|
||||
public $entity;
|
||||
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $invitation
|
||||
* @param $entity_type
|
||||
* @param $user
|
||||
* @param $company
|
||||
*/
|
||||
public function __construct($invitation, $entity_type, $user, $company)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->user = $user;
|
||||
|
||||
$this->invitation = $invitation;
|
||||
|
||||
$this->entity = $invitation->{$entity_type};
|
||||
|
||||
$this->entity_type = $entity_type;
|
||||
|
||||
$this->settings = $invitation->contact->client->getMergedSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
/*If we are migrating data we don't want to fire these notification*/
|
||||
if ($this->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
//Set DB
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
//if we need to set an email driver do it now
|
||||
$this->setMailDriver();
|
||||
|
||||
$mail_obj = (new EntityViewedObject($this->invitation, $this->entity_type))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
//send email
|
||||
try {
|
||||
Mail::to($this->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
} catch (\Exception $e) {
|
||||
//$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->entity->client);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace App\Listeners\Credit;
|
||||
|
||||
use App\Jobs\Mail\EntitySentMailer;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
@ -64,7 +63,6 @@ class CreditEmailedNotification implements ShouldQueue
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
//EntitySentMailer::dispatch($event->invitation, 'credit', $user, $event->invitation->company, $event->template);
|
||||
$first_notification_sent = false;
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,11 @@
|
||||
|
||||
namespace App\Listeners\Invoice;
|
||||
|
||||
use App\Jobs\Mail\EntitySentMailer;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntitySentObject;
|
||||
use App\Notifications\Admin\EntitySentNotification;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -41,6 +44,12 @@ class InvoiceEmailedNotification implements ShouldQueue
|
||||
$invoice->last_sent_date = now();
|
||||
$invoice->save();
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new NinjaMailer( (new EntitySentObject($event->invitation, 'invoice', $event->template))->build() );
|
||||
$nmo->company = $invoice->company;
|
||||
$nmo->settings = $invoice->company->settings;
|
||||
|
||||
|
||||
/* We loop through each user and determine whether they need to be notified */
|
||||
foreach ($event->invitation->company->company_users as $company_user) {
|
||||
|
||||
@ -57,8 +66,11 @@ class InvoiceEmailedNotification implements ShouldQueue
|
||||
if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) {
|
||||
unset($methods[$key]);
|
||||
|
||||
EntitySentMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company, $event->template);
|
||||
|
||||
$nmo->to_user = $user;
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
/* This prevents more than one notification being sent */
|
||||
$first_notification_sent = false;
|
||||
}
|
||||
|
@ -11,9 +11,11 @@
|
||||
|
||||
namespace App\Listeners\Invoice;
|
||||
|
||||
use App\Jobs\Mail\EntityFailedSendMailer;
|
||||
use App\Jobs\Mail\EntitySentMailer;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityFailedSendObject;
|
||||
use App\Notifications\Admin\EntitySentNotification;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -44,6 +46,11 @@ class InvoiceFailedEmailNotification implements ShouldQueue
|
||||
$invoice->last_sent_date = now();
|
||||
$invoice->save();
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new NinjaMailer( (new EntityFailedSendObject($event->invitation, 'invoice', $event->template, $event->message))->build() );
|
||||
$nmo->company = $invoice->company;
|
||||
$nmo->settings = $invoice->company->settings;
|
||||
|
||||
foreach ($event->invitation->company->company_users as $company_user) {
|
||||
$user = $company_user->user;
|
||||
|
||||
@ -54,7 +61,10 @@ class InvoiceFailedEmailNotification implements ShouldQueue
|
||||
if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) {
|
||||
unset($methods[$key]);
|
||||
|
||||
EntityFailedSendMailer::dispatch($event->invitation, 'invoice', $user, $event->invitation->company, $event->template, $event->message);
|
||||
$nmo->to_user = $user;
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
$first_notification_sent = false;
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,11 @@
|
||||
|
||||
namespace App\Listeners\Misc;
|
||||
|
||||
use App\Jobs\Mail\EntityViewedMailer;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityViewedObject;
|
||||
use App\Notifications\Admin\EntityViewedNotification;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -46,6 +49,12 @@ class InvitationViewedListener implements ShouldQueue
|
||||
|
||||
$notification = new EntityViewedNotification($invitation, $entity_name);
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new NinjaMailer( (new EntityViewedObject($invitation, $entity_name))->build() );
|
||||
$nmo->company = $invitation->company;
|
||||
$nmo->settings = $invitation->company->settings;
|
||||
|
||||
|
||||
foreach ($invitation->company->company_users as $company_user) {
|
||||
$entity_viewed = "{$entity_name}_viewed";
|
||||
|
||||
@ -54,7 +63,9 @@ class InvitationViewedListener implements ShouldQueue
|
||||
if (($key = array_search('mail', $methods)) !== false) {
|
||||
unset($methods[$key]);
|
||||
|
||||
EntityViewedMailer::dispatch($invitation, $entity_name, $company_user->user, $invitation->company);
|
||||
$nmo->to_user = $company_user->user;
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
}
|
||||
|
||||
$notification->method = $methods;
|
||||
|
@ -11,8 +11,11 @@
|
||||
|
||||
namespace App\Listeners\Payment;
|
||||
|
||||
use App\Jobs\Mail\EntityPaidMailer;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntityPaidObject;
|
||||
use App\Notifications\Admin\NewPaymentNotification;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
@ -41,12 +44,16 @@ class PaymentNotification implements ShouldQueue
|
||||
public function handle($event)
|
||||
{
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
if ($event->company->is_disabled)
|
||||
return true;
|
||||
|
||||
$payment = $event->payment;
|
||||
|
||||
if ($event->company->is_disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new NinjaMailer( (new EntityPaidObject($payment))->build() );
|
||||
$nmo->company = $event->company;
|
||||
$nmo->settings = $event->company->settings;
|
||||
|
||||
/*User notifications*/
|
||||
foreach ($payment->company->company_users as $company_user) {
|
||||
@ -57,7 +64,9 @@ class PaymentNotification implements ShouldQueue
|
||||
if (($key = array_search('mail', $methods)) !== false) {
|
||||
unset($methods[$key]);
|
||||
|
||||
EntityPaidMailer::dispatch($payment, $payment->company, $user);
|
||||
$nmo->to_user = $user;
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
}
|
||||
|
||||
$notification = new NewPaymentNotification($payment, $payment->company);
|
||||
|
@ -11,8 +11,11 @@
|
||||
|
||||
namespace App\Listeners\Quote;
|
||||
|
||||
use App\Jobs\Mail\EntitySentMailer;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Mail\Admin\EntitySentObject;
|
||||
use App\Notifications\Admin\EntitySentNotification;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -41,6 +44,12 @@ class QuoteEmailedNotification implements ShouldQueue
|
||||
$quote->last_sent_date = now();
|
||||
$quote->save();
|
||||
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new NinjaMailer( (new EntitySentObject($event->invitation, 'quote', $event->template))->build() );
|
||||
$nmo->company = $quote->company;
|
||||
$nmo->settings = $quote->company->settings;
|
||||
|
||||
|
||||
foreach ($event->invitation->company->company_users as $company_user) {
|
||||
$user = $company_user->user;
|
||||
|
||||
@ -51,7 +60,11 @@ class QuoteEmailedNotification implements ShouldQueue
|
||||
if (($key = array_search('mail', $methods)) !== false && $first_notification_sent === true) {
|
||||
unset($methods[$key]);
|
||||
|
||||
EntitySentMailer::dispatch($event->invitation, 'quote', $user, $event->invitation->company, $event->template);
|
||||
|
||||
$nmo->to_user = $user;
|
||||
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
$first_notification_sent = false;
|
||||
}
|
||||
|
||||
|
@ -76,17 +76,6 @@ class EntityViewedNotification extends Notification implements ShouldQueue
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
//@TODO THESE ARE @DEPRECATED NOW we are now using app/Mail/Admin/*
|
||||
|
||||
$data = $this->buildDataArray();
|
||||
$subject = $this->buildSubject();
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($subject)
|
||||
->markdown('email.admin.generic', $data)
|
||||
->withSwiftMessage(function ($message) {
|
||||
$message->getHeaders()->addTextHeader('Tag', $this->company->company_key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,149 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Notifications\Admin;
|
||||
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class InvoiceSentNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
//use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected $invitation;
|
||||
|
||||
protected $invoice;
|
||||
|
||||
protected $company;
|
||||
|
||||
protected $settings;
|
||||
|
||||
public $is_system;
|
||||
|
||||
protected $contact;
|
||||
|
||||
public function __construct($invitation, $company, $is_system = false, $settings = null)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->invoice = $invitation->invoice;
|
||||
$this->contact = $invitation->contact;
|
||||
$this->company = $company;
|
||||
$this->settings = $this->invoice->client->getMergedSettings();
|
||||
$this->is_system = $is_system;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return $this->is_system ? ['slack'] : ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
//@TODO THESE ARE @DEPRECATED NOW we are now using app/Mail/Admin/*
|
||||
|
||||
$amount = Number::formatMoney($this->invoice->amount, $this->invoice->client);
|
||||
$subject = ctrans(
|
||||
'texts.notification_invoice_sent_subject',
|
||||
[
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->invoice->number,
|
||||
]
|
||||
);
|
||||
|
||||
$data = [
|
||||
'title' => $subject,
|
||||
'message' => ctrans(
|
||||
'texts.notification_invoice_sent',
|
||||
[
|
||||
'amount' => $amount,
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->invoice->number,
|
||||
]
|
||||
),
|
||||
'url' => config('ninja.app_url').'/invoices/'.$this->invoice->hashed_id,
|
||||
'button' => ctrans('texts.view_invoice'),
|
||||
'signature' => $this->settings->email_signature,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
'settings' => $this->settings,
|
||||
|
||||
];
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($subject)
|
||||
->markdown('email.admin.generic', $data)
|
||||
->withSwiftMessage(function ($message) {
|
||||
$message->getHeaders()->addTextHeader('Tag', $this->company->company_key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
$logo = $this->company->present()->logo();
|
||||
$amount = Number::formatMoney($this->invoice->amount, $this->invoice->client);
|
||||
|
||||
return (new SlackMessage)
|
||||
->from(ctrans('texts.notification_bot'))
|
||||
->success()
|
||||
->image('https://app.invoiceninja.com/favicon-v2.png')
|
||||
->content(trans(
|
||||
'texts.notification_invoice_sent_subject',
|
||||
[
|
||||
'amount' => $amount,
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->invoice->number,
|
||||
]
|
||||
))
|
||||
->attachment(function ($attachment) use ($amount) {
|
||||
$attachment->title(ctrans('texts.invoice_number_placeholder', ['invoice' => $this->invoice->number]), $this->invitation->getAdminLink())
|
||||
->fields([
|
||||
ctrans('texts.client') => $this->contact->present()->name(),
|
||||
ctrans('texts.amount') => $amount,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Notifications\Admin;
|
||||
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class InvoiceViewedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
//use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected $invitation;
|
||||
|
||||
protected $invoice;
|
||||
|
||||
protected $company;
|
||||
|
||||
protected $settings;
|
||||
|
||||
public $is_system;
|
||||
|
||||
protected $contact;
|
||||
|
||||
public function __construct($invitation, $company, $is_system = false, $settings = null)
|
||||
{
|
||||
$this->invoice = $invitation->invoice;
|
||||
$this->contact = $invitation->contact;
|
||||
$this->company = $company;
|
||||
$this->settings = $this->invoice->client->getMergedSettings();
|
||||
$this->is_system = $is_system;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return $this->is_system ? ['slack'] : ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
|
||||
//@TODO THESE ARE @DEPRECATED NOW we are now using app/Mail/Admin/*
|
||||
|
||||
$amount = Number::formatMoney($this->invoice->amount, $this->invoice->client);
|
||||
$subject = ctrans(
|
||||
'texts.notification_invoice_viewed_subject',
|
||||
[
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->invoice->number,
|
||||
]
|
||||
);
|
||||
|
||||
$data = [
|
||||
'title' => $subject,
|
||||
'message' => ctrans(
|
||||
'texts.notification_invoice_viewed',
|
||||
[
|
||||
'amount' => $amount,
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->invoice->number,
|
||||
]
|
||||
),
|
||||
'url' => config('ninja.app_url').'/invoices/'.$this->invoice->hashed_id,
|
||||
'button' => ctrans('texts.view_invoice'),
|
||||
'signature' => $this->settings->email_signature,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
'settings' => $this->settings,
|
||||
|
||||
];
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($subject)
|
||||
->markdown('email.admin.generic', $data)
|
||||
->withSwiftMessage(function ($message) {
|
||||
$message->getHeaders()->addTextHeader('Tag', $this->company->company_key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
$logo = $this->company->present()->logo();
|
||||
$amount = Number::formatMoney($this->invoice->amount, $this->invoice->client);
|
||||
|
||||
return (new SlackMessage)
|
||||
->success()
|
||||
->from(ctrans('texts.notification_bot'))
|
||||
->image($logo)
|
||||
->content(ctrans(
|
||||
'texts.notification_invoice_viewed',
|
||||
[
|
||||
'amount' => $amount,
|
||||
'client' => $this->contact->present()->name(),
|
||||
'invoice' => $this->invoice->number,
|
||||
]
|
||||
));
|
||||
}
|
||||
}
|
@ -1,148 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
|
||||
namespace App\Notifications\Admin;
|
||||
|
||||
use App\Utils\Number;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class NewPartialPaymentNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
// use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected $payment;
|
||||
|
||||
protected $company;
|
||||
|
||||
protected $settings;
|
||||
|
||||
protected $is_system;
|
||||
|
||||
public function __construct($payment, $company, $is_system = false, $settings = null)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
$this->company = $company;
|
||||
$this->settings = $payment->client->getMergedSettings();
|
||||
$this->is_system = $is_system;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function via($notifiable)
|
||||
{
|
||||
return $this->is_system ? ['slack'] : ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return MailMessage
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
//@TODO THESE ARE @DEPRECATED NOW we are now using app/Mail/Admin/*
|
||||
|
||||
$amount = Number::formatMoney($this->payment->amount, $this->payment->client);
|
||||
|
||||
$invoice_texts = ctrans('texts.invoice_number_short');
|
||||
|
||||
foreach ($this->payment->invoices as $invoice) {
|
||||
$invoice_texts .= $invoice->number.',';
|
||||
}
|
||||
|
||||
$invoice_texts = substr($invoice_texts, 0, -1);
|
||||
|
||||
$data = [
|
||||
'title' => ctrans(
|
||||
'texts.notification_partial_payment_paid_subject',
|
||||
['client' => $this->payment->client->present()->name()]
|
||||
),
|
||||
'message' => ctrans(
|
||||
'texts.notification_partial_payment_paid',
|
||||
['amount' => $amount,
|
||||
'client' => $this->payment->client->present()->name(),
|
||||
'invoice' => $invoice_texts,
|
||||
]
|
||||
),
|
||||
'url' => config('ninja.app_url').'/payments/'.$this->payment->hashed_id,
|
||||
'button' => ctrans('texts.view_payment'),
|
||||
'signature' => $this->settings->email_signature,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
'settings' => $this->settings,
|
||||
];
|
||||
|
||||
return (new MailMessage)
|
||||
->subject(
|
||||
ctrans(
|
||||
'texts.notification_partial_payment_paid_subject',
|
||||
['client' => $this->payment->client->present()->name()]
|
||||
)
|
||||
)->markdown('email.admin.generic', $data)
|
||||
->withSwiftMessage(function ($message) {
|
||||
$message->getHeaders()->addTextHeader('Tag', $this->company->company_key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param mixed $notifiable
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($notifiable)
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public function toSlack($notifiable)
|
||||
{
|
||||
$logo = $this->company->present()->logo();
|
||||
$amount = Number::formatMoney($this->payment->amount, $this->payment->client);
|
||||
$invoice_texts = ctrans('texts.invoice_number_short');
|
||||
|
||||
foreach ($this->payment->invoices as $invoice) {
|
||||
$invoice_texts .= $invoice->number.',';
|
||||
}
|
||||
|
||||
$invoice_texts = substr($invoice_texts, 0, -1);
|
||||
|
||||
return (new SlackMessage)
|
||||
->success()
|
||||
//->to("#devv2")
|
||||
->from('System')
|
||||
->image($logo)
|
||||
->content(ctrans(
|
||||
'texts.notification_payment_paid',
|
||||
['amount' => $amount,
|
||||
'client' => $this->payment->client->present()->name(),
|
||||
'invoice' => $invoice_texts, ]
|
||||
));
|
||||
}
|
||||
}
|
@ -68,47 +68,6 @@ class NewPaymentNotification extends Notification implements ShouldQueue
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
//@TODO THESE ARE @DEPRECATED NOW we are now using app/Mail/Admin/*
|
||||
|
||||
$amount = Number::formatMoney($this->payment->amount, $this->payment->client);
|
||||
|
||||
$invoice_texts = ctrans('texts.invoice_number_short');
|
||||
|
||||
foreach ($this->payment->invoices as $invoice) {
|
||||
$invoice_texts .= $invoice->number.',';
|
||||
}
|
||||
|
||||
$invoice_texts = substr($invoice_texts, 0, -1);
|
||||
|
||||
$data = [
|
||||
'title' => ctrans(
|
||||
'texts.notification_payment_paid_subject',
|
||||
['client' => $this->payment->client->present()->name()]
|
||||
),
|
||||
'message' => ctrans(
|
||||
'texts.notification_payment_paid',
|
||||
['amount' => $amount,
|
||||
'client' => $this->payment->client->present()->name(),
|
||||
'invoice' => $invoice_texts,
|
||||
]
|
||||
),
|
||||
'url' => config('ninja.app_url').'/payments/'.$this->payment->hashed_id,
|
||||
'button' => ctrans('texts.view_payment'),
|
||||
'signature' => $this->settings->email_signature,
|
||||
'logo' => $this->company->present()->logo(),
|
||||
'settings' => $this->settings,
|
||||
];
|
||||
|
||||
return (new MailMessage)
|
||||
->subject(
|
||||
ctrans(
|
||||
'texts.notification_payment_paid_subject',
|
||||
['client' => $this->payment->client->present()->name()]
|
||||
)
|
||||
)->markdown('email.admin.generic', $data)
|
||||
->withSwiftMessage(function ($message) {
|
||||
$message->getHeaders()->addTextHeader('Tag', $this->company->company_key);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,8 +18,12 @@ use App\Factory\PaymentFactory;
|
||||
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
||||
use App\Jobs\Mail\AutoBillingFailureMailer;
|
||||
use App\Jobs\Mail\ClientPaymentFailureMailer;
|
||||
use App\Jobs\Mail\NinjaMailer;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use App\Jobs\Mail\PaymentFailureMailer;
|
||||
use App\Jobs\Util\SystemLogger;
|
||||
use App\Mail\Admin\ClientPaymentFailureObject;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\ClientGatewayToken;
|
||||
@ -354,12 +358,24 @@ class BaseDriver extends AbstractPaymentDriver
|
||||
$this->payment_hash
|
||||
);
|
||||
|
||||
ClientPaymentFailureMailer::dispatch(
|
||||
$gateway->client,
|
||||
$error,
|
||||
$gateway->client->company,
|
||||
$this->payment_hash
|
||||
);
|
||||
$nmo = new NinjaMailerObject;
|
||||
$nmo->mailable = new NinjaMailer( (new ClientPaymentFailureObject($gateway->client, $error, $gateway->client->company, $this->payment_hash))->build() );
|
||||
$nmo->company = $gateway->client->company;
|
||||
$nmo->settings = $gateway->client->company->settings;
|
||||
|
||||
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
|
||||
|
||||
$invoices->first()->invitations->each(function ($invitation) {
|
||||
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
|
||||
$nmo->to_user = $invitation->contact;
|
||||
NinjaMailerJob::dispatch($nmo);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
SystemLogger::dispatch(
|
||||
$gateway->payment_hash,
|
||||
|
Loading…
x
Reference in New Issue
Block a user