mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Refactoring emails
This commit is contained in:
parent
13e96121d7
commit
d4532c4d21
@ -1,109 +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\AutoBillingFailureObject;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\PaymentFailureObject;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
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 AutoBillingFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
|
||||
|
||||
public $client;
|
||||
|
||||
public $error;
|
||||
|
||||
public $company;
|
||||
|
||||
public $payment_hash;
|
||||
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $client
|
||||
* @param $message
|
||||
* @param $company
|
||||
* @param $amount
|
||||
*/
|
||||
public function __construct($client, $error, $company, $payment_hash)
|
||||
{
|
||||
$this->client = $client;
|
||||
|
||||
$this->error = $error;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
$this->payment_hash = $payment_hash;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
$this->settings = $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();
|
||||
|
||||
//iterate through company_users
|
||||
$this->company->company_users->each(function ($company_user) {
|
||||
|
||||
//determine if this user has the right permissions
|
||||
$methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure','all_notifications']);
|
||||
|
||||
//if mail is a method type -fire mail!!
|
||||
if (($key = array_search('mail', $methods)) !== false) {
|
||||
unset($methods[$key]);
|
||||
|
||||
$mail_obj = (new AutoBillingFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
//send email
|
||||
try {
|
||||
Mail::to($company_user->user->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
} catch (\Exception $e) {
|
||||
//$this->failed($e);
|
||||
$this->logMailError($e->getMessage(), $this->client);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,111 +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\ClientPaymentFailureObject;
|
||||
use App\Mail\Admin\EntityNotificationMailer;
|
||||
use App\Mail\Admin\PaymentFailureObject;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\Notifications\UserNotifies;
|
||||
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 ClientPaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies, MakesHash;
|
||||
|
||||
public $client;
|
||||
|
||||
public $error;
|
||||
|
||||
public $company;
|
||||
|
||||
public $payment_hash;
|
||||
|
||||
public $settings;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param $client
|
||||
* @param $message
|
||||
* @param $company
|
||||
* @param $amount
|
||||
*/
|
||||
public function __construct($client, $error, $company, $payment_hash)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
$this->error = $error;
|
||||
|
||||
$this->client = $client;
|
||||
|
||||
$this->payment_hash = $payment_hash;
|
||||
|
||||
$this->company = $company;
|
||||
|
||||
$this->settings = $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();
|
||||
|
||||
$this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
|
||||
|
||||
$this->invoices->first()->invitations->each(function ($invitation) {
|
||||
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
|
||||
$mail_obj = (new ClientPaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->build();
|
||||
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
||||
|
||||
//send email
|
||||
try {
|
||||
Mail::to($invitation->contact->email)
|
||||
->send(new EntityNotificationMailer($mail_obj));
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$this->logMailError($e->getMessage(), $this->client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -82,7 +82,6 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
||||
//determine if this user has the right permissions
|
||||
$methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure','all_notifications']);
|
||||
|
||||
|
||||
//if mail is a method type -fire mail!!
|
||||
if (($key = array_search('mail', $methods)) !== false) {
|
||||
unset($methods[$key]);
|
||||
|
@ -67,16 +67,6 @@ class ClientContactResetPassword extends Notification
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
if (static::$toMailCallback) {
|
||||
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
|
||||
}
|
||||
|
||||
return (new MailMessage)
|
||||
->subject('Reset Password Notification')
|
||||
->line('You are receiving this email because we received a password reset request for your account.')
|
||||
->action('Reset Password', url(config('app.url').route('client.password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
|
||||
->line('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.users.expire')])
|
||||
->line('If you did not request a password reset, no further action is required.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,8 +42,6 @@ class ResetPasswordNotification extends Notification
|
||||
*/
|
||||
public function toMail($notifiable)
|
||||
{
|
||||
return (new MailMessage)
|
||||
->view('email.auth.password-reset', ['link' => route('password.reset', $this->token)]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,8 +16,6 @@ use App\Events\Payment\PaymentWasCreated;
|
||||
use App\Exceptions\PaymentFailed;
|
||||
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;
|
||||
|
@ -466,7 +466,10 @@ trait MockAccountData
|
||||
$this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount);
|
||||
// UpdateCompanyLedgerWithInvoice::dispatchNow($this->invoice, $this->invoice->amount, $this->invoice->company);
|
||||
|
||||
$user_id = $this->invoice->user_id;
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->user_id = $user_id;
|
||||
$recurring_invoice->next_send_date = Carbon::now();
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
@ -477,6 +480,7 @@ trait MockAccountData
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->user_id = $user_id;
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(2);
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
@ -487,6 +491,7 @@ trait MockAccountData
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->user_id = $user_id;
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(10);
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
@ -497,6 +502,7 @@ trait MockAccountData
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->user_id = $user_id;
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(15);
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
@ -507,6 +513,7 @@ trait MockAccountData
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->user_id = $user_id;
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addMinutes(20);
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
@ -517,6 +524,7 @@ trait MockAccountData
|
||||
$recurring_invoice->save();
|
||||
|
||||
$recurring_invoice = InvoiceToRecurringInvoiceFactory::create($this->invoice);
|
||||
$recurring_invoice->user_id = $user_id;
|
||||
$recurring_invoice->next_send_date = Carbon::now()->addDays(10);
|
||||
$recurring_invoice->status_id = RecurringInvoice::STATUS_ACTIVE;
|
||||
$recurring_invoice->remaining_cycles = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user