Files
fotospiel-app/app/Notifications/Ops/AddonPurchased.php

44 lines
1.8 KiB
PHP

<?php
namespace App\Notifications\Ops;
use App\Models\EventPackageAddon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class AddonPurchased extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(private readonly EventPackageAddon $addon) {}
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
$event = $this->addon->event;
$tenant = $event?->tenant;
$label = $this->addon->metadata['label'] ?? $this->addon->addon_key;
$amount = $this->addon->amount ? number_format((float) $this->addon->amount, 2) : null;
$currency = $this->addon->currency ?? 'EUR';
return (new MailMessage)
->subject(__('emails.ops.addon.subject', ['addon' => $label]))
->greeting(__('emails.ops.addon.greeting'))
->line(__('emails.ops.addon.tenant', ['tenant' => $tenant?->name ?? __('emails.tenant_feedback.unknown_tenant')]))
->line(__('emails.ops.addon.event', ['event' => $event?->name['de'] ?? $event?->name['en'] ?? $event?->name ?? __('emails.package_limits.event_fallback')]))
->line(__('emails.ops.addon.addon', ['addon' => $label, 'quantity' => $this->addon->quantity]))
->when($amount, fn ($mail) => $mail->line(__('emails.ops.addon.amount', ['amount' => $amount, 'currency' => $currency])))
->line(__('emails.ops.addon.provider', [
'checkout' => $this->addon->checkout_id ?? '—',
'transaction' => $this->addon->transaction_id ?? '—',
]))
->line(__('emails.ops.addon.footer'));
}
}