Skip to content

Commit

Permalink
Fix trial ends at check (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints committed Oct 19, 2020
1 parent 4775da2 commit 39c74e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Concerns/ManagesSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public function onGenericTrial()
*/
public function trialEndsAt($name = 'default')
{
if ($this->onGenericTrial()) {
return $this->trial_ends_at;
if ($subscription = $this->subscription($name)) {
return $subscription->trial_ends_at;
}

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

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/Feature/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Laravel\Cashier\Exceptions\PaymentFailure;
use Laravel\Cashier\Payment;
use Laravel\Cashier\Subscription;
use Laravel\Cashier\Tests\Fixtures\User;
use Stripe\Coupon;
use Stripe\Invoice;
use Stripe\Plan;
Expand Down Expand Up @@ -468,6 +469,15 @@ public function test_creating_subscription_with_trial()
$this->assertEquals(Carbon::today()->addDays(7)->day, $subscription->trial_ends_at->day);
}

public function test_user_without_subscriptions_can_return_its_generic_trial_end_date()
{
$user = new User;
$user->trial_ends_at = $tomorrow = Carbon::tomorrow();

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

public function test_creating_subscription_with_explicit_trial()
{
$user = $this->createCustomer('creating_subscription_with_explicit_trial');
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/CustomerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public function test_customer_can_be_put_on_a_generic_trial()
$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 39c74e0

Please sign in to comment.