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
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-08-06 05:04:09 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-08-06 05:04:09 +02:00
|
|
|
*/
|
2020-05-26 10:20:50 +02:00
|
|
|
|
|
|
|
namespace App\Jobs\Mail;
|
|
|
|
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
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*/
|
|
|
|
|
2021-02-18 21:57:10 +01:00
|
|
|
class PaymentFailureMailer implements ShouldQueue
|
2020-05-26 10:20:50 +02:00
|
|
|
{
|
2020-05-26 12:22:50 +02:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
|
|
|
public $client;
|
|
|
|
|
2021-02-02 02:04:52 +01:00
|
|
|
public $error;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
|
|
|
public $company;
|
|
|
|
|
2021-04-06 11:07:21 +02:00
|
|
|
public $amount;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
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
|
|
|
*/
|
2021-04-06 11:07:21 +02:00
|
|
|
public function __construct($client, $error, $company, $amount)
|
2020-05-26 10:20:50 +02:00
|
|
|
{
|
|
|
|
$this->company = $company;
|
|
|
|
|
2021-02-02 02:04:52 +01:00
|
|
|
$this->error = $error;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
|
|
|
$this->client = $client;
|
|
|
|
|
2021-04-06 11:07:21 +02:00
|
|
|
$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()
|
|
|
|
{
|
|
|
|
//Set DB
|
|
|
|
MultiDB::setDb($this->company->db);
|
|
|
|
|
2020-05-26 12:22:50 +02:00
|
|
|
//iterate through company_users
|
2022-06-21 11:57:17 +02: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
|
2022-06-21 11:57:17 +02:00
|
|
|
$methods = $this->findCompanyUserNotificationType($company_user, ['payment_failure_all', 'payment_failure', 'payment_failure_user', 'all_notifications']);
|
2020-05-26 12:22:50 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! is_string($this->error)) {
|
|
|
|
$this->error = 'Undefined error. Please contact the administrator for further information.';
|
|
|
|
}
|
2022-02-27 01:31:01 +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]);
|
|
|
|
|
2023-08-08 10:56:31 +02:00
|
|
|
$use_react_link = false;
|
|
|
|
|
|
|
|
if(isset($company_user->react_settings->react_notification_link) && $company_user->react_settings->react_notification_link) {
|
|
|
|
$use_react_link = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$mail_obj = (new PaymentFailureObject($this->client, $this->error, $this->company, $this->amount, null, $use_react_link))->build();
|
2021-02-14 11:43:44 +01:00
|
|
|
|
|
|
|
$nmo = new NinjaMailerObject;
|
|
|
|
$nmo->mailable = new NinjaMailer($mail_obj);
|
2021-02-14 12:09:32 +01:00
|
|
|
$nmo->company = $this->company;
|
2021-02-14 11:43:44 +01:00
|
|
|
$nmo->to_user = $company_user->user;
|
|
|
|
$nmo->settings = $this->settings;
|
|
|
|
|
|
|
|
NinjaMailerJob::dispatch($nmo);
|
2020-05-26 12:22:50 +02:00
|
|
|
}
|
|
|
|
});
|
2021-10-17 04:59:43 +02:00
|
|
|
|
|
|
|
//add client payment failures here.
|
2020-05-26 10:20:50 +02:00
|
|
|
}
|
|
|
|
}
|