Skip to content

Commit ec6a740

Browse files
authored
[1.x] Fix trial ends at (#87)
* Add missing test * Fixed bug * suggested changes
1 parent 80f0800 commit ec6a740

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/Concerns/ManagesSubscriptions.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public function onGenericTrial()
8484
*/
8585
public function trialEndsAt($name = 'default')
8686
{
87-
if ($this->onGenericTrial()) {
88-
return $this->customer->trial_ends_at;
87+
if ($subscription = $this->subscription($name)) {
88+
return $subscription->trial_ends_at;
8989
}
9090

91-
return $this->subscription($name)->trial_ends_at;
91+
return $this->customer->trial_ends_at;
9292
}
9393

9494
/**

tests/Feature/CustomerTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function test_billable_models_can_create_a_customer_record()
1111
$customer = $user->createAsCustomer(['trial_ends_at' => $trialEndsAt = now()->addDays(15)]);
1212

1313
$this->assertSame($trialEndsAt->timestamp, $customer->trial_ends_at->timestamp);
14+
$this->assertSame($trialEndsAt->timestamp, $user->trialEndsAt()->timestamp);
1415
$this->assertTrue($user->onGenericTrial());
1516
}
1617

@@ -27,4 +28,12 @@ public function test_billable_models_without_having_a_customer_record_can_still_
2728
$this->assertEmpty($user->receipts);
2829
$this->assertNull($user->subscription());
2930
}
31+
32+
public function test_trial_ends_at_works_if_generic_trial_is_expired()
33+
{
34+
$user = $this->createUser();
35+
$user->createAsCustomer(['trial_ends_at' => $trialEndsAt = now()->subDays(15)]);
36+
37+
$this->assertSame($trialEndsAt->timestamp, $user->trialEndsAt()->timestamp);
38+
}
3039
}

0 commit comments

Comments
 (0)