Implement package limit notification system
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications\Packages;
|
||||
|
||||
use App\Models\TenantPackage;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class TenantPackageEventThresholdNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
private readonly TenantPackage $tenantPackage,
|
||||
private readonly float $threshold,
|
||||
private readonly int $limit,
|
||||
private readonly int $used,
|
||||
) {}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$tenant = $this->tenantPackage->tenant;
|
||||
$package = $this->tenantPackage->package;
|
||||
|
||||
$percentage = (int) round($this->threshold * 100);
|
||||
$remaining = max(0, $this->limit - $this->used);
|
||||
|
||||
$url = url('/tenant/billing');
|
||||
|
||||
return (new MailMessage)
|
||||
->subject(__('emails.package_limits.event_threshold.subject', [
|
||||
'package' => $package?->getNameForLocale() ?? $package?->name ?? __('emails.package_limits.package_fallback'),
|
||||
'percentage' => $percentage,
|
||||
]))
|
||||
->greeting(__('emails.package_limits.event_threshold.greeting', [
|
||||
'name' => $tenant?->name ?? __('emails.package_limits.team_fallback'),
|
||||
]))
|
||||
->line(__('emails.package_limits.event_threshold.body', [
|
||||
'package' => $package?->getNameForLocale() ?? $package?->name ?? __('emails.package_limits.package_fallback'),
|
||||
'percentage' => $percentage,
|
||||
'used' => $this->used,
|
||||
'limit' => $this->limit,
|
||||
'remaining' => $remaining,
|
||||
]))
|
||||
->action(__('emails.package_limits.event_threshold.action'), $url)
|
||||
->line(__('emails.package_limits.footer'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user