Deploy Ladill Transfer / deploy (push) Successful in 1m0s
Send grace-entered and countdown emails to owners alongside recipient grace milestones so unpaid transfers get clear wallet top-up reminders before deletion. Co-authored-by: Cursor <cursoragent@cursor.com>
90 lines
2.9 KiB
PHP
90 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use App\Models\Transfer;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Messages\MailMessage;
|
|
use Illuminate\Notifications\Notification;
|
|
|
|
class TransferOwnerGraceNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
private readonly Transfer $transfer,
|
|
private readonly string $milestone,
|
|
) {}
|
|
|
|
public function via(mixed $notifiable): array
|
|
{
|
|
return ['mail', 'database'];
|
|
}
|
|
|
|
public function toMail(mixed $notifiable): MailMessage
|
|
{
|
|
$transfer = $this->transfer->loadMissing(['files', 'qrCode']);
|
|
|
|
return (new MailMessage())
|
|
->subject($this->subjectLine())
|
|
->view('mail.notifications.transfer-owner-grace', [
|
|
'transfer' => $transfer,
|
|
'milestone' => $this->milestone,
|
|
'daysRemaining' => $this->daysRemaining(),
|
|
'walletUrl' => 'https://'.config('app.account_domain', 'account.ladill.com').'/wallet',
|
|
'transferUrl' => route('transfer.transfers.show', $transfer),
|
|
]);
|
|
}
|
|
|
|
public function toArray(mixed $notifiable): array
|
|
{
|
|
return [
|
|
'title' => $this->headline(),
|
|
'message' => $this->inAppMessage(),
|
|
'icon' => 'transfer',
|
|
'url' => route('transfer.transfers.show', $this->transfer),
|
|
];
|
|
}
|
|
|
|
private function subjectLine(): string
|
|
{
|
|
return match ($this->milestone) {
|
|
'grace_entered' => "Payment needed: {$this->transfer->title} entered grace period",
|
|
'1' => "Last day to save {$this->transfer->title} from deletion",
|
|
'3' => "3 days left to save {$this->transfer->title}",
|
|
'7' => "Reminder: {$this->transfer->title} will be deleted soon",
|
|
default => "Transfer payment reminder: {$this->transfer->title}",
|
|
};
|
|
}
|
|
|
|
private function headline(): string
|
|
{
|
|
return match ($this->milestone) {
|
|
'grace_entered' => 'Transfer entered grace period',
|
|
'1' => 'Files deleted tomorrow',
|
|
default => 'Transfer deletion reminder',
|
|
};
|
|
}
|
|
|
|
private function inAppMessage(): string
|
|
{
|
|
$title = $this->transfer->title;
|
|
|
|
return match ($this->milestone) {
|
|
'grace_entered' => "{$title} could not be renewed. Top up your wallet within the grace period to keep the files.",
|
|
'1' => "{$title} will be deleted tomorrow unless your wallet is topped up.",
|
|
default => "{$title} will be deleted in {$this->daysRemaining()} days unless payment is received.",
|
|
};
|
|
}
|
|
|
|
private function daysRemaining(): ?int
|
|
{
|
|
if ($this->milestone === 'grace_entered') {
|
|
return null;
|
|
}
|
|
|
|
return is_numeric($this->milestone) ? (int) $this->milestone : null;
|
|
}
|
|
}
|