Skip to content

Commit

Permalink
Updated fix for Issue #412 to master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelHoughton committed Oct 4, 2017
1 parent d563114 commit 1e87a60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ public function skipTrial()
* Swap the subscription to a new Stripe plan.
*
* @param string $plan
* @param string $name
* @return $this
*/
public function swap($plan)
public function swap($plan, $name = null)
{
$subscription = $this->asStripeSubscription();

Expand Down Expand Up @@ -266,10 +267,16 @@ public function swap($plan)

$this->user->invoice();

$this->fill([
'stripe_plan' => $plan,
'ends_at' => null,
])->save();
$attributes = [
'stripe_plan' => $plan,
'ends_at' => null,
];

if ($name) {
$attributes['name'] = $name;
}

$this->fill($attributes)->save();

return $this;
}
Expand Down
7 changes: 6 additions & 1 deletion tests/CashierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public function testSubscriptionsCanBeCreated()
$this->assertEquals(1, $subscription->quantity);

// Swap Plan
$subscription->swap('monthly-10-2');
$subscription->swap('monthly-10-2', 'premium');
$this->assertEquals('premium', $subscription->name);

// Rename Plan
$subscription->swap('monthly-10-2', 'main');
$this->assertEquals('main', $subscription->name);

$this->assertEquals('monthly-10-2', $subscription->stripe_plan);

Expand Down

2 comments on commit 1e87a60

@nerdalertdk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this be released ?

@plastiik
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also waiting for it 😄

Please sign in to comment.