1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-19 17:42:44 +01:00
invoiceninja/app/Jobs/Mail/EntityPaidMailer.php

91 lines
2.1 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) 2020. 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;
2020-08-06 05:04:09 +02:00
/*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;
2020-08-10 06:55:44 +02:00
public $settings;
/**
* Create a new job instance.
*
2020-10-28 11:10:49 +01:00
* @param $payment
* @param $user
* @param $company
*/
2020-11-09 11:26:36 +01:00
public function __construct($payment, $company, $user)
{
$this->company = $company;
2020-11-09 11:26:36 +01:00
$this->user = $user;
$this->payment = $payment;
2020-08-10 06:55:44 +02:00
$this->settings = $payment->client->getMergedSettings();
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
2020-08-06 05:04:09 +02: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) {
return true;
2020-11-25 15:19:52 +01:00
}
2020-11-01 04:19:03 +01: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-10-29 05:47:44 +01:00
try {
$mail_obj = (new EntityPaidObject($this->payment))->build();
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
2020-10-29 05:47:44 +01:00
//send email
Mail::to($this->user->email)
->send(new EntityNotificationMailer($mail_obj));
2020-11-12 10:41:19 +01:00
} catch (\Exception $e) {
$this->failed($e);
$this->logMailError($e->getMessage(), $this->payment->client);
}
}
}