HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.naniguide.com/app/Notifications/Customer/RenewOrderCreated.php
<?php

namespace App\Notifications\Customer;

use App\Model\Order;
use App\Notifications\AppNotification;
use Illuminate\Database\Eloquent\Model;

/**
 * A renewal Order has been auto-created for the customer's subscription
 * (cron job, before period end). Surfaces in the customer bell so they
 * can review/pay the invoice before auto-charge fires.
 */
class RenewOrderCreated extends AppNotification
{
    public function __construct(public Order $order) {}

    public function audience(): string { return self::AUDIENCE_DIRECT; }
    public function category(): string { return self::CATEGORY_INFO; }
    public function severity(): string { return self::SEVERITY_INFO; }

    public function groupKey(): string
    {
        return 'renew-order:' . $this->order->id;
    }

    public function subject(): ?Model
    {
        return $this->order;
    }

    public function toArray(object $notifiable = null): array
    {
        $invoice = $this->order->getItsOnlyInvoice();
        $sub = $this->order->orderItems->first()?->subscription;

        return [
            'title' => trans('refactor/notifications.renew_order_created.title'),
            'body'  => trans('refactor/notifications.renew_order_created.body', [
                'plan'   => $sub?->plan?->name ?? '—',
                'amount' => $invoice?->formattedTotal() ?? '—',
                'date'   => optional($sub?->current_period_ends_at)->toDateString() ?? '—',
            ]),
        ];
    }
}