2020-05-26 10:20:50 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-05-26 10:20:50 +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-05-26 10:20:50 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Mail\Admin;
|
|
|
|
|
2021-02-02 02:04:52 +01:00
|
|
|
use App\Models\Invoice;
|
2020-05-26 10:20:50 +02:00
|
|
|
use App\Utils\Number;
|
2021-02-02 02:04:52 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-10-28 11:10:49 +01:00
|
|
|
use stdClass;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
class PaymentFailureObject
|
2020-05-26 10:20:50 +02:00
|
|
|
{
|
2021-02-02 06:11:33 +01:00
|
|
|
use MakesHash;
|
2021-02-02 02:04:52 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public $client;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
2021-02-02 02:04:52 +01:00
|
|
|
public $error;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
public $company;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
2021-02-02 02:04:52 +01:00
|
|
|
public $payment_hash;
|
|
|
|
|
|
|
|
private $invoices;
|
2020-05-26 10:20:50 +02:00
|
|
|
|
2021-02-02 02:04:52 +01:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $client
|
|
|
|
* @param $message
|
|
|
|
* @param $company
|
|
|
|
* @param $amount
|
|
|
|
*/
|
|
|
|
public function __construct($client, $error, $company, $payment_hash)
|
2020-05-26 10:20:50 +02:00
|
|
|
{
|
|
|
|
$this->client = $client;
|
2021-02-02 02:04:52 +01:00
|
|
|
|
|
|
|
$this->error = $error;
|
|
|
|
|
|
|
|
$this->company = $company;
|
|
|
|
|
|
|
|
$this->payment_hash = $payment_hash;
|
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
$this->company = $company;
|
2021-02-02 02:04:52 +01:00
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function build()
|
|
|
|
{
|
2021-02-02 02:04:52 +01:00
|
|
|
|
|
|
|
$this->invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->get();
|
|
|
|
|
2020-10-28 11:10:49 +01:00
|
|
|
$mail_obj = new stdClass;
|
2020-09-06 11:38:10 +02:00
|
|
|
$mail_obj->amount = $this->getAmount();
|
|
|
|
$mail_obj->subject = $this->getSubject();
|
|
|
|
$mail_obj->data = $this->getData();
|
|
|
|
$mail_obj->markdown = 'email.admin.generic';
|
|
|
|
$mail_obj->tag = $this->company->company_key;
|
|
|
|
|
|
|
|
return $mail_obj;
|
2020-05-26 10:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getAmount()
|
|
|
|
{
|
2021-02-02 02:04:52 +01:00
|
|
|
|
|
|
|
return array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
|
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getSubject()
|
|
|
|
{
|
2021-02-02 02:04:52 +01:00
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
return
|
|
|
|
ctrans(
|
|
|
|
'texts.payment_failed_subject',
|
2021-02-01 12:26:42 +01:00
|
|
|
['client' => $this->client->present()->name()]
|
2020-05-26 10:20:50 +02:00
|
|
|
);
|
2021-02-02 02:04:52 +01:00
|
|
|
|
2020-05-26 10:20:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function getData()
|
|
|
|
{
|
|
|
|
$signature = $this->client->getSetting('email_signature');
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$data = [
|
2020-05-26 10:20:50 +02:00
|
|
|
'title' => ctrans(
|
|
|
|
'texts.payment_failed_subject',
|
2021-02-02 02:04:52 +01:00
|
|
|
[
|
|
|
|
'client' => $this->client->present()->name()
|
|
|
|
]
|
2020-05-26 10:20:50 +02:00
|
|
|
),
|
2021-02-02 02:04:52 +01:00
|
|
|
'message' => $this->error,
|
2020-05-26 10:20:50 +02:00
|
|
|
'signature' => $signature,
|
|
|
|
'logo' => $this->company->present()->logo(),
|
2020-09-21 00:17:57 +02:00
|
|
|
'settings' => $this->client->getMergedSettings(),
|
2020-10-20 01:37:33 +02:00
|
|
|
'whitelabel' => $this->company->account->isPaid() ? true : false,
|
2021-02-01 12:26:42 +01:00
|
|
|
'url' => config('ninja.app_url'),
|
|
|
|
'button' => ctrans('texts.login'),
|
2021-02-02 02:04:52 +01:00
|
|
|
'additional_info' => $this->buildFailedInvoices()
|
2020-05-26 10:20:50 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
2021-02-02 02:04:52 +01:00
|
|
|
|
|
|
|
private function buildFailedInvoices()
|
|
|
|
{
|
|
|
|
|
|
|
|
$text = '';
|
|
|
|
|
|
|
|
foreach($this->invoices as $invoice)
|
|
|
|
{
|
|
|
|
|
|
|
|
$text .= ctrans('texts.notification_invoice_payment_failed_subject', ['invoice' => $invoice->number]) . "\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|