Skip to content

Commit 659d063

Browse files
simonhampclaude
andauthored
Treat comped users as non-subscribers on pricing page (#319)
Comped users now see the normal checkout button instead of "You're on Ultra" or the upgrade modal. Their comped subscription is canceled when they proceed to checkout, allowing a fresh paid subscription. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent de8554b commit 659d063

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

app/Livewire/Customer/Dashboard.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ public function activeSubscription()
3131
return auth()->user()->subscription();
3232
}
3333

34+
#[Computed]
35+
public function isCompedSubscription(): bool
36+
{
37+
return auth()->user()->hasCompedSubscription();
38+
}
39+
3440
#[Computed]
3541
public function subscriptionName(): ?string
3642
{

app/Livewire/MobilePricing.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public function createCheckoutSession(?string $plan, ?User $user = null)
6969
return;
7070
}
7171

72+
// Cancel any comped subscription before creating a new paid one
73+
if ($user->hasCompedSubscription()) {
74+
$user->subscription('default')->cancelNow();
75+
}
76+
7277
$user->createOrGetStripeCustomer();
7378

7479
$checkout = $user
@@ -218,7 +223,7 @@ public function render()
218223

219224
$subscription = $user->subscription('default');
220225

221-
if ($subscription && $subscription->active()) {
226+
if ($subscription && $subscription->active() && ! $user->hasCompedSubscription()) {
222227
$hasExistingSubscription = true;
223228
$isAlreadyUltra = $user->hasActiveUltraSubscription();
224229

app/Models/User.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,27 @@ public function hasMaxAccess(): bool
215215
return $this->hasActiveMaxLicense() || $this->hasActiveMaxSubLicense();
216216
}
217217

218+
/**
219+
* Check if the user's subscription is a comped (free) subscription.
220+
* Covers both legacy comped (is_comped flag) and comped Ultra price.
221+
*/
222+
public function hasCompedSubscription(): bool
223+
{
224+
$subscription = $this->subscription();
225+
226+
if (! $subscription || ! $subscription->active()) {
227+
return false;
228+
}
229+
230+
if ($subscription->is_comped) {
231+
return true;
232+
}
233+
234+
$compedPriceId = config('subscriptions.plans.max.stripe_price_id_comped');
235+
236+
return $compedPriceId && $this->subscribedToPrice($compedPriceId);
237+
}
238+
218239
public function hasActiveUltraSubscription(): bool
219240
{
220241
$subscription = $this->subscription();

tests/Feature/MobilePricingTest.php

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function ultra_subscriber_sees_already_on_ultra_message()
137137
}
138138

139139
#[Test]
140-
public function comped_max_subscriber_sees_upgrade_button()
140+
public function comped_max_subscriber_sees_checkout_button()
141141
{
142142
$user = User::factory()->create(['stripe_id' => 'cus_'.uniqid()]);
143143
Auth::login($user);
@@ -155,7 +155,37 @@ public function comped_max_subscriber_sees_upgrade_button()
155155
->create(['stripe_price' => self::MAX_PRICE_ID]);
156156

157157
Livewire::test(MobilePricing::class)
158-
->assertSee('Upgrade to Ultra')
158+
->assertSeeHtml('wire:click="createCheckoutSession(\'max\')"')
159+
->assertDontSee('Upgrade to Ultra')
160+
->assertDontSee('on Ultra', escape: false);
161+
}
162+
163+
#[Test]
164+
public function comped_ultra_price_subscriber_sees_checkout_button()
165+
{
166+
$compedPriceId = 'price_test_comped_ultra';
167+
168+
config([
169+
'subscriptions.plans.max.stripe_price_id_comped' => $compedPriceId,
170+
]);
171+
172+
$user = User::factory()->create(['stripe_id' => 'cus_'.uniqid()]);
173+
Auth::login($user);
174+
175+
$subscription = Cashier::$subscriptionModel::factory()
176+
->for($user)
177+
->active()
178+
->create([
179+
'stripe_price' => $compedPriceId,
180+
]);
181+
182+
Cashier::$subscriptionItemModel::factory()
183+
->for($subscription, 'subscription')
184+
->create(['stripe_price' => $compedPriceId]);
185+
186+
Livewire::test(MobilePricing::class)
187+
->assertSeeHtml('wire:click="createCheckoutSession(\'max\')"')
188+
->assertDontSee('Upgrade to Ultra')
159189
->assertDontSee('on Ultra', escape: false);
160190
}
161191

0 commit comments

Comments
 (0)