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(); +});