diff --git a/src/Subscription.php b/src/Subscription.php index ae719977..42a4b67c 100644 --- a/src/Subscription.php +++ b/src/Subscription.php @@ -576,6 +576,30 @@ public function skipTrial() return $this; } + /** + * Force the subscription's trial to end immediately. + * + * @return $this + */ + public function endTrial() + { + if (is_null($this->trial_ends_at)) { + return $this; + } + + $subscription = $this->asStripeSubscription(); + + $subscription->trial_end = 'now'; + + $subscription->save(); + + $this->trial_ends_at = null; + + $this->save(); + + return $this; + } + /** * Extend an existing subscription's trial period. * diff --git a/tests/Feature/SubscriptionsTest.php b/tests/Feature/SubscriptionsTest.php index 9a9f3cde..6597fd17 100644 --- a/tests/Feature/SubscriptionsTest.php +++ b/tests/Feature/SubscriptionsTest.php @@ -602,6 +602,19 @@ public function test_trials_can_be_extended() $this->assertEquals($subscription->asStripeSubscription()->trial_end, $trialEndsAt->getTimestamp()); } + public function test_trials_can_be_ended() + { + $user = $this->createCustomer('trials_can_be_ended'); + + $subscription = $user->newSubscription('main', static::$planId) + ->trialDays(10) + ->create('pm_card_visa'); + + $subscription->endTrial(); + + $this->assertNull($subscription->trial_ends_at); + } + public function test_applying_coupons_to_existing_customers() { $user = $this->createCustomer('applying_coupons_to_existing_customers');