From 2ff3aeba4df9fe436226dc787e29c360f6987233 Mon Sep 17 00:00:00 2001 From: Ovidiu U Date: Wed, 29 Apr 2026 09:29:21 +0100 Subject: [PATCH] fix: admin tier assignment when stripe price env vars are empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit env() returns an empty string (not null) when a STRIPE_PRICE_* var is set but blank, so the ?? fallback never fired and the synthetic subscription was created with stripe_price = '' — which then resolved back to free in Plan::resolveForUser. Switch to ?: so empty strings also fall back to the synthetic price_admin_{tier}_{cadence} id, and backfill the matching Plan row's stripe_price_id_{cadence} when empty so resolution succeeds. Co-Authored-By: Claude Opus 4.7 (1M context) --- app/Filament/Resources/UserResource.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index 604254b..1ec4ce3 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -182,7 +182,14 @@ class UserResource extends Resource return; } - $priceId = config("services.stripe.prices.{$tier}.{$cadence}") ?? "price_admin_{$tier}_{$cadence}"; + $priceId = config("services.stripe.prices.{$tier}.{$cadence}") ?: "price_admin_{$tier}_{$cadence}"; + + $planColumn = $cadence === 'annual' ? 'stripe_price_id_annual' : 'stripe_price_id_monthly'; + $plan = Plan::where('name', $tier)->first(); + + if ($plan && empty($plan->{$planColumn})) { + $plan->update([$planColumn => $priceId]); + } $user->subscriptions()->create([ 'type' => 'default',