Skip to content

Commit

Permalink
Implement trialEndsAt
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Sep 25, 2020
1 parent 44ed976 commit 4d0b891
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/Concerns/ManagesSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ public function onGenericTrial()
return $this->trial_ends_at && $this->trial_ends_at->isFuture();
}

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

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

/**
* Determine if the Stripe model has a given subscription.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ public function test_creating_subscription_with_an_anchored_billing_cycle()
);
}

/** @group Foo */
public function test_creating_subscription_with_trial()
{
$user = $this->createCustomer('creating_subscription_with_trial');
Expand All @@ -447,7 +448,7 @@ public function test_creating_subscription_with_trial()
$this->assertTrue($subscription->onTrial());
$this->assertFalse($subscription->recurring());
$this->assertFalse($subscription->ended());
$this->assertEquals(Carbon::today()->addDays(7)->day, $subscription->trial_ends_at->day);
$this->assertEquals(Carbon::today()->addDays(7)->day, $user->trialEndsAt('main')->day);

// Cancel Subscription
$subscription->cancel();
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public function test_customer_can_be_put_on_a_generic_trial()

$this->assertFalse($user->onGenericTrial());

$user->trial_ends_at = Carbon::tomorrow();
$user->trial_ends_at = $tomorrow = Carbon::tomorrow();

$this->assertTrue($user->onGenericTrial());
$this->assertSame($tomorrow, $user->trialEndsAt());

$user->trial_ends_at = Carbon::today()->subDays(5);

Expand Down

0 comments on commit 4d0b891

Please sign in to comment.