2020-05-26 10:20:50 +02:00
|
|
|
<?php
|
2020-08-06 05:04:09 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-08-06 05:04:09 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-08-06 05:04:09 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2020-05-26 10:20:50 +02:00
|
|
|
|
|
|
|
namespace App\Jobs\Mail;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Mail\Admin\EntityNotificationMailer;
|
|
|
|
use App\Mail\Admin\PaymentFailureObject;
|
|
|
|
use App\Models\User;
|
2020-05-26 12:22:50 +02:00
|
|
|
use App\Utils\Traits\Notifications\UserNotifies;
|
2020-05-26 10:20:50 +02:00
|
|
|
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;
|
|
|
|
|
2020-08-06 05:04:09 +02:00
|
|
|
/*Multi Mailer implemented*/
|
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
|
|
|
|
{
|
2020-05-26 12:22:50 +02:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
|
|
|
public $client;
|
|
|
|
|
|
|
|
public $message;
|
|
|
|
|
|
|
|
public $company;
|
|
|
|
|
|
|
|
public $amount;
|
|
|
|
|
2020-08-10 06:55:44 +02:00
|
|
|
public $settings;
|
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param $client
|
|
|
|
* @param $message
|
|
|
|
* @param $company
|
|
|
|
* @param $amount
|
2020-05-26 10:20:50 +02:00
|
|
|
*/
|
|
|
|
public function __construct($client, $message, $company, $amount)
|
|
|
|
{
|
|
|
|
$this->company = $company;
|
|
|
|
|
|
|
|
$this->message = $message;
|
|
|
|
|
|
|
|
$this->client = $client;
|
|
|
|
|
|
|
|
$this->amount = $amount;
|
2020-08-10 06:55:44 +02:00
|
|
|
|
2020-09-14 07:14:37 +02:00
|
|
|
$this->company = $company;
|
|
|
|
|
2020-08-10 06:55:44 +02:00
|
|
|
$this->settings = $client->getMergedSettings();
|
2020-05-26 10:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2021-02-01 06:30:28 +01:00
|
|
|
nlog("payment failure mailer ");
|
|
|
|
|
2020-11-01 04:19:03 +01:00
|
|
|
/*If we are migrating data we don't want to fire these notification*/
|
2020-11-25 15:19:52 +01:00
|
|
|
if ($this->company->is_disabled) {
|
2020-11-01 04:19:03 +01:00
|
|
|
return true;
|
2020-11-25 15:19:52 +01:00
|
|
|
}
|
2020-11-01 04:19:03 +01:00
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
//Set DB
|
|
|
|
MultiDB::setDb($this->company->db);
|
|
|
|
|
|
|
|
//if we need to set an email driver do it now
|
2020-08-10 06:55:44 +02:00
|
|
|
$this->setMailDriver();
|
2020-05-26 10:20:50 +02:00
|
|
|
|
2020-05-26 12:22:50 +02:00
|
|
|
//iterate through company_users
|
2021-02-01 06:30:28 +01:00
|
|
|
$this->company->company_users->each(function ($company_user) {
|
2020-05-26 12:22:50 +02:00
|
|
|
|
|
|
|
//determine if this user has the right permissions
|
|
|
|
$methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure']);
|
|
|
|
|
2021-02-01 06:30:28 +01:00
|
|
|
|
2020-05-26 12:22:50 +02:00
|
|
|
//if mail is a method type -fire mail!!
|
|
|
|
if (($key = array_search('mail', $methods)) !== false) {
|
|
|
|
unset($methods[$key]);
|
|
|
|
|
|
|
|
$mail_obj = (new PaymentFailureObject($this->client, $this->message, $this->amount, $this->company))->build();
|
2020-12-02 04:08:35 +01:00
|
|
|
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-05-26 12:22:50 +02:00
|
|
|
//send email
|
2020-11-12 10:41:19 +01:00
|
|
|
try {
|
|
|
|
Mail::to($company_user->user->email)
|
|
|
|
->send(new EntityNotificationMailer($mail_obj));
|
2020-11-25 15:19:52 +01:00
|
|
|
} catch (\Exception $e) {
|
2021-01-21 00:02:39 +01:00
|
|
|
//$this->failed($e);
|
2020-11-12 10:41:19 +01:00
|
|
|
$this->logMailError($e->getMessage(), $this->client);
|
2020-05-26 12:22:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2020-05-26 10:20:50 +02:00
|
|
|
}
|
|
|
|
}
|