Skip to content

Commit 6eed679

Browse files
authored
wip (#116)
1 parent f0b5624 commit 6eed679

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Subscription.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public function billable(): MorphTo
7171
}
7272

7373
/**
74-
* Determine if the subscription is active, on trial, paused for free, or within its grace period.
74+
* Determine if the subscription is active, on trial, past due, paused for free, or within its grace period.
7575
*/
7676
public function valid(): bool
7777
{
7878
return $this->active() ||
7979
$this->onTrial() ||
8080
$this->pastDue() ||
81-
$this->cancelled() ||
81+
$this->onGracePeriod() ||
8282
($this->paused() && $this->pause_mode === 'free');
8383
}
8484

tests/Feature/SubscriptionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@
2323

2424
expect($subscription)->toMatchArray(['product_id' => '12345', 'variant_id' => '67890']);
2525
});
26+
27+
it('can determine if the subscription is valid while on its grace period', function () {
28+
$subscription = Subscription::factory()->cancelled()->create([
29+
'ends_at' => now()->addDays(5),
30+
]);
31+
32+
expect($subscription->valid())->toBeTrue();
33+
34+
$subscription = Subscription::factory()->cancelled()->create([
35+
'ends_at' => now()->subDays(5),
36+
]);
37+
38+
expect($subscription->valid())->toBeFalse();
39+
});

0 commit comments

Comments
 (0)