From 192e777209e145bb4dff674cb88196943cff0368 Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Mon, 13 Jan 2025 21:15:09 +0100 Subject: [PATCH] wip --- src/Subscription.php | 4 ++-- tests/Feature/SubscriptionTest.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Subscription.php b/src/Subscription.php index 3447303..a24d68c 100644 --- a/src/Subscription.php +++ b/src/Subscription.php @@ -71,14 +71,14 @@ public function billable(): MorphTo } /** - * Determine if the subscription is active, on trial, paused for free, or within its grace period. + * Determine if the subscription is active, on trial, past due, paused for free, or within its grace period. */ public function valid(): bool { return $this->active() || $this->onTrial() || $this->pastDue() || - $this->cancelled() || + $this->onGracePeriod() || ($this->paused() && $this->pause_mode === 'free'); } diff --git a/tests/Feature/SubscriptionTest.php b/tests/Feature/SubscriptionTest.php index a883c31..1fab106 100644 --- a/tests/Feature/SubscriptionTest.php +++ b/tests/Feature/SubscriptionTest.php @@ -23,3 +23,17 @@ expect($subscription)->toMatchArray(['product_id' => '12345', 'variant_id' => '67890']); }); + +it('can determine if the subscription is valid while on its grace period', function () { + $subscription = Subscription::factory()->cancelled()->create([ + 'ends_at' => now()->addDays(5), + ]); + + expect($subscription->valid())->toBeTrue(); + + $subscription = Subscription::factory()->cancelled()->create([ + 'ends_at' => now()->subDays(5), + ]); + + expect($subscription->valid())->toBeFalse(); +});