Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.x] Added function to see when the trial is ending #69

Merged
merged 3 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Concerns/ManagesSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ public function onGenericTrial()
return $this->customer->onGenericTrial();
}

/**
* Get the date of when the trial ends.
*
* @param string $name
* @return Illuminate\Support\Carbon|null
*/
public function trialEndsAt($name = 'default')
{
if ($this->onGenericTrial()) {
return $this->customer->trial_ends_at;
}

return $this->subscription($name)->trial_ends_at;
}

/**
* Determine if the Billable model has a given subscription.
*
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function test_customers_can_check_if_they_are_on_a_generic_trial()
$this->assertTrue($billable->onGenericTrial());
$this->assertTrue($billable->onTrial());
$this->assertFalse($billable->onTrial('main'));
$this->assertEquals($billable->trialEndsAt(), Carbon::tomorrow());
}

public function test_customers_can_check_if_their_subscription_is_on_trial()
Expand All @@ -80,6 +81,7 @@ public function test_customers_can_check_if_their_subscription_is_on_trial()
$this->assertTrue($billable->onTrial('main', 2323));
$this->assertFalse($billable->onTrial('main', 323));
$this->assertFalse($billable->onGenericTrial());
$this->assertEquals($billable->trialEndsAt('main'), Carbon::tomorrow());

$this->assertTrue($subscription->valid());
$this->assertTrue($subscription->active());
Expand Down