Skip to content

Commit

Permalink
[12.x] End trial method (#1062)
Browse files Browse the repository at this point in the history
* end trial function

* removed code duplication

* test

* update docblock

* Cleanup

Co-authored-by: Dries Vints <dries@vints.io>
  • Loading branch information
benjamindoe and driesvints committed Feb 18, 2021
1 parent 83cf995 commit 19d3d34
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Feature/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 19d3d34

Please sign in to comment.