diff --git a/src/Concerns/ManagesSubscriptions.php b/src/Concerns/ManagesSubscriptions.php index 060e22ff..d90f74ed 100644 --- a/src/Concerns/ManagesSubscriptions.php +++ b/src/Concerns/ManagesSubscriptions.php @@ -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. * diff --git a/tests/Feature/SubscriptionsTest.php b/tests/Feature/SubscriptionsTest.php index a25e6ca6..533a15c0 100644 --- a/tests/Feature/SubscriptionsTest.php +++ b/tests/Feature/SubscriptionsTest.php @@ -447,7 +447,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(); diff --git a/tests/Unit/CustomerTest.php b/tests/Unit/CustomerTest.php index 307e1d0e..4dc203df 100644 --- a/tests/Unit/CustomerTest.php +++ b/tests/Unit/CustomerTest.php @@ -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);