Files
portal/app/app/Mail/InvoicePaidNotification.php
T

83 lines
2.4 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
namespace App\Mail;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Str;
/**
* Email-уведомление об оплате тарифного счёта (ТЗ §18.5, событие
* invoice_paid).
*
* Триггер: после смены статуса saas_invoice на 'paid'. Endpoint
* биллинга / webhook ЮKassa — отдельный коммит; этот Mailable готов
* к подключению.
*/
class InvoicePaidNotification extends Mailable
{
use Queueable;
use SerializesModels;
public function __construct(
public User $recipient,
public Tenant $tenant,
public string $amountRub,
public ?string $invoiceNumber,
public ?string $tariffName,
/** Относительный путь PDF-акта на диске 'local' (для вложения). */
public ?string $actPdfPath = null,
/** Номер акта — для имени файла вложения. */
public ?string $actNumber = null,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: 'Лидерра. Счёт оплачен',
);
}
public function content(): Content
{
return new Content(
view: 'emails.invoice_paid',
with: [
'recipient' => $this->recipient,
'tenant' => $this->tenant,
'amountRub' => $this->amountRub,
'invoiceNumber' => $this->invoiceNumber,
'tariffName' => $this->tariffName,
],
);
}
/**
* Вложение: PDF закрывающего документа (Акт), если он сформирован.
*
* @return array<int, Attachment>
*/
public function attachments(): array
{
if ($this->actPdfPath === null) {
return [];
}
$name = 'Akt-'.Str::ascii((string) $this->actNumber).'.pdf';
return [
Attachment::fromStorageDisk('local', $this->actPdfPath)
->as($name)
->withMime('application/pdf'),
];
}
}