From fc90861a966cd7bda0d2d659e1504b3d2f7ad6c8 Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Thu, 14 May 2026 19:55:28 -0300 Subject: [PATCH] refactor(account): move trial-end-date logic into Account::activeTrialEndsAt() Centralizes 'what date should the UI show as trial end?' on the model. Returns null when not on trial, the subscription's trial date when on trial-with-card, or the generic trial date for no-card users. --- app/Http/Controllers/App/BillingController.php | 2 +- app/Models/Account.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/App/BillingController.php b/app/Http/Controllers/App/BillingController.php index 07eda978..92e00744 100644 --- a/app/Http/Controllers/App/BillingController.php +++ b/app/Http/Controllers/App/BillingController.php @@ -139,7 +139,7 @@ public function index(Request $request): Response|RedirectResponse return Inertia::render('settings/account/Billing', [ 'hasSubscription' => $account->subscribed(Account::SUBSCRIPTION_NAME), 'onTrial' => $account->isOnTrial(), - 'trialEndsAt' => $subscription?->trial_ends_at ?? $account->trial_ends_at, + 'trialEndsAt' => $account->activeTrialEndsAt(), 'subscription' => $subscription?->only([ 'stripe_status', 'ends_at', diff --git a/app/Models/Account.php b/app/Models/Account.php index 50d49565..79f696d1 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -9,6 +9,7 @@ use App\Features\SocialAccountLimit; use App\Features\WorkspaceLimit; use App\Models\Traits\HasUsage; +use Carbon\CarbonInterface; use Database\Factories\AccountFactory; use Illuminate\Database\Eloquent\Concerns\HasUuids; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -90,6 +91,21 @@ public function isOnTrial(): bool return (bool) $this->subscription(self::SUBSCRIPTION_NAME)?->onTrial(); } + /** + * The end date of whichever trial is currently active (subscription trial + * or generic trial), or null if the account is not on any trial. + */ + public function activeTrialEndsAt(): ?CarbonInterface + { + $subscription = $this->subscription(self::SUBSCRIPTION_NAME); + + return match (true) { + (bool) $subscription?->onTrial() => $subscription->trial_ends_at, + $this->onGenericTrial() => $this->trial_ends_at, + default => null, + }; + } + /** * Returns the displayable card for the billing UI. Falls back to the first * attached payment method when the customer has no `invoice_settings.default_payment_method`