Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added function to re-enable proration after it was disabled #716

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ public function noProrate()
return $this;
}

/**
* Indicate that the plan change should be prorated.
*
* @return $this
*/
public function prorate()
{
$this->prorate = true;

return $this;
}

/**
* Change the billing cycle anchor on a plan change.
*
Expand Down
38 changes: 38 additions & 0 deletions tests/Integration/CashierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,44 @@ public function test_subscription_state_scopes()
$this->assertTrue($user->subscriptions()->ended()->exists());
}

public function test_subscription_proration()
{
$user = User::create([
'email' => 'taylor@laravel.com',
'name' => 'Taylor Otwell',
]);

$subscription = $user->newSubscription('main', static::$premiumPlanId)
->create($this->getTestToken());

$invoice = $user->invoices()[0];

$this->assertEquals('$20.00', $invoice->total(), 'Invoice for premium plan should bill $20.00');

// swapping from premium ($20/month) to normal ($10/month)
// without proration should invoice $20
$subscription
->noProrate()
->swap(static::$planId);

$invoice = $user->invoices()[0];

$this->assertEquals('$20.00', $invoice->total(), 'Swapping from premium to cheaper plan without proration should not change the invoice amount.');

// swapping from premium ($20/month) to normal ($10/month)
// with proration should invoice $0
$subscription
->swap(static::$premiumPlanId);

$subscription
->prorate()
->swap(static::$planId);

$invoice = $user->invoices()[0];

$this->assertEquals('$0.00', $invoice->total(), 'Swapping from premium to cheaper plan with proration should change the invoice amount.');
}

public function test_update_stripe_customer()
{
$user = User::create([
Expand Down