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

143 lines
3.5 KiB
PHP
Raw Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. 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\Invoice;
2021-10-17 12:40:40 +02:00
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;
2021-10-17 12:40:40 +02:00
public Client $client;
2021-10-17 12:40:40 +02:00
public string $error;
2021-10-17 12:40:40 +02:00
public Company $company;
2021-04-06 11:07:21 +02:00
public $amount;
2021-10-17 12:40:40 +02:00
public PaymentHash $payment_hash;
2021-04-06 11:07:21 +02:00
// private $invoices;
/**
* Create a new job instance.
*
* @param $client
* @param $message
* @param $company
* @param $amount
*/
2021-10-17 12:40:40 +02:00
public function __construct(Client $client, string $error, Company $company, $amount, ?PaymentHash $payment_hash)
{
$this->client = $client;
$this->error = $error;
$this->company = $company;
2021-04-06 11:07:21 +02:00
$this->amount = $amount;
$this->company = $company;
2021-10-17 12:40:40 +02:00
$this->payment_hash = $payment_hash;
}
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()
{
2021-04-06 11:07:21 +02:00
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)
]),
'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-10-17 12:40:40 +02:00
'additional_info' => $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());
}
2021-10-17 12:40:40 +02:00
}