Files
portal-api/app/Mail/AutoRenewFailedMail.php

48 lines
1.5 KiB
PHP

<?php
namespace App\Mail;
use App\Models\Customer;
use App\Models\Invoice;
use App\Models\Service;
use App\Services\InvoicePaymentService;
use App\Support\MailGlobals;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
class AutoRenewFailedMail extends TemplateMailable
{
use Queueable, SerializesModels;
public const SCENARIO = 'auto_renew_failed';
public function __construct(
public readonly Customer $customer,
public readonly Service $service,
public readonly Invoice $invoice,
) {}
protected function scenario(): string
{
return self::SCENARIO;
}
protected function variables(): array
{
$serverName = (string) $this->service->server_name;
$frontend = MailGlobals::frontendUrl();
return [
'client_name' => $this->customer->fullname ?? '',
'product_name' => $this->service->product?->name ?? 'Dịch vụ',
'server_name_suffix' => $serverName !== '' ? ' (' . e($serverName) . ')' : '',
'expires_at' => $this->service->expires_at?->format('d/m/Y') ?? 'N/A',
'invoice_number' => $this->invoice->invoice_number,
'outstanding' => number_format(InvoicePaymentService::outstanding($this->invoice), 0, ',', '.'),
'balance_formatted' => number_format((int) $this->customer->total, 0, ',', '.'),
'topup_url' => $frontend . '/nap-tien',
'invoice_url' => $frontend . $this->invoice->clientPath(),
];
}
}