1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 16:13:20 +01:00
invoiceninja/app/Mail/Admin/PaymentFailureObject.php

117 lines
3.3 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @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)
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Mail\Admin;
2021-10-17 12:40:40 +02:00
use App\Models\Client;
use App\Models\Company;
use App\Models\PaymentHash;
2021-06-29 11:46:40 +02:00
use App\Utils\Ninja;
use App\Utils\Number;
use App\Utils\Traits\MakesHash;
2021-06-29 11:46:40 +02:00
use Illuminate\Support\Facades\App;
2021-10-17 12:40:40 +02:00
use stdClass;
class PaymentFailureObject
{
2021-02-02 06:11:33 +01:00
use MakesHash;
/**
* Create a new job instance.
*
* @param $client
* @param $message
* @param $company
* @param $amount
*/
2023-06-07 08:25:41 +02:00
public function __construct(public Client $client, public string $error, public Company $company, public float $amount, public ?PaymentHash $payment_hash, protected bool $use_react_url)
{
}
public function build()
{
2021-06-29 11:46:40 +02:00
App::forgetInstance('translator');
/* Init a new copy of the translator*/
$t = app('translator');
/* Set the locale*/
App::setLocale($this->company->getLocale());
/* Set customized translations _NOW_ */
$t->replace(Ninja::transformTranslations($this->company->settings));
2020-10-28 11:10:49 +01:00
$mail_obj = new stdClass;
$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;
}
private function getAmount()
{
return $this->amount;
}
private function getSubject()
{
return
ctrans(
'texts.payment_failed_subject',
2021-02-01 12:26:42 +01:00
['client' => $this->client->present()->name()]
);
}
private function getData()
{
$signature = $this->client->getSetting('email_signature');
$data = [
'title' => ctrans(
'texts.payment_failed_subject',
[
'client' => $this->client->present()->name(),
]
),
2021-10-17 12:40:40 +02:00
'content' => ctrans(
'texts.notification_invoice_payment_failed',
[
'client' => $this->client->present()->name(),
'invoice' => $this->getDescription(),
'amount' => Number::formatMoney($this->amount, $this->client),
2023-02-16 02:36:09 +01: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,
2023-06-07 08:25:41 +02:00
'url' => $this->client->portalUrl($this->use_react_url),
'button' => $this->use_react_url ? ctrans('texts.view_client') : ctrans('texts.login'),
'additional_info' => $this->error,
];
2023-03-22 07:45:33 +01:00
if (strlen($this->error > 1)) {
$data['content'] .= "\n\n".$this->error;
}
return $data;
}
2021-10-17 12:40:40 +02:00
public function getDescription(bool $abbreviated = false)
{
if (! $this->payment_hash) {
return '';
}
2021-10-17 12:40:40 +02:00
return \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray());
}
}