php-commerce/Mail/InvoiceGenerated.php
Snider a774f4e285 refactor: migrate namespace from Core\Commerce to Core\Mod\Commerce
Align commerce module with the monorepo module structure by updating
all namespaces to use the Core\Mod\Commerce convention. This change
supports the recent monorepo separation and ensures consistency with
other modules.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 16:23:12 +00:00

89 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Core\Mod\Commerce\Mail;
use Core\Mod\Commerce\Models\Invoice;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;
/**
* Email notification sent when an invoice is generated.
*/
class InvoiceGenerated extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*/
public function __construct(
public Invoice $invoice
) {}
/**
* Get the message envelope.
*/
public function envelope(): Envelope
{
$subject = $this->invoice->status === 'paid'
? "Your Host UK Invoice #{$this->invoice->invoice_number}"
: "Invoice #{$this->invoice->invoice_number} - Payment Required";
return new Envelope(
subject: $subject,
);
}
/**
* Get the message content definition.
*/
public function content(): Content
{
$this->invoice->load(['workspace', 'items']);
return new Content(
markdown: 'commerce::emails.invoice-generated',
with: [
'invoice' => $this->invoice,
'workspace' => $this->invoice->workspace,
'items' => $this->invoice->items,
'isPaid' => $this->invoice->status === 'paid',
'viewUrl' => route('hub.billing.invoices.view', $this->invoice),
'downloadUrl' => route('hub.billing.invoices.pdf', $this->invoice),
],
);
}
/**
* Get the attachments for the message.
*
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
*/
public function attachments(): array
{
// Only attach PDF if it exists
if (! $this->invoice->pdf_path) {
return [];
}
$disk = config('commerce.pdf.storage_disk', 'local');
if (! Storage::disk($disk)->exists($this->invoice->pdf_path)) {
return [];
}
return [
Attachment::fromStorageDisk($disk, $this->invoice->pdf_path)
->as("invoice-{$this->invoice->invoice_number}.pdf")
->withMime('application/pdf'),
];
}
}