1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Jobs/Mail/PaymentFailureMailer.php

103 lines
2.6 KiB
PHP
Raw Normal View History

<?php
2020-08-06 05:04:09 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2020-08-06 05:04:09 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-08-06 05:04:09 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Mail;
2021-02-14 11:43:44 +01:00
use App\Jobs\Mail\NinjaMailerJob;
use App\Jobs\Mail\NinjaMailerObject;
use App\Libraries\MultiDB;
use App\Mail\Admin\EntityNotificationMailer;
use App\Mail\Admin\PaymentFailureObject;
2021-02-14 11:43:44 +01:00
use App\Mail\NinjaMailer;
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;
2020-08-06 05:04:09 +02:00
/*Multi Mailer implemented*/
class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, UserNotifies;
public $client;
public $error;
public $company;
2021-02-01 22:33:04 +01:00
public $payment_hash;
2020-08-10 06:55:44 +02:00
public $settings;
/**
* Create a new job instance.
*
2020-10-28 11:10:49 +01:00
* @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;
2021-02-01 22:33:04 +01:00
$this->payment_hash = $payment_hash;
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();
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
2021-02-01 06:30:28 +01:00
//Set DB
MultiDB::setDb($this->company->db);
//iterate through company_users
2021-02-01 06:30:28 +01:00
$this->company->company_users->each(function ($company_user) {
//determine if this user has the right permissions
2021-02-01 12:26:42 +01:00
$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 PaymentFailureObject($this->client, $this->error, $this->company, $this->payment_hash))->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);
}
});
}
}