29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Laravel Cashier 179<br />

Changing Plans<br />

After a user is subscribed to your application, they may occasionally want to change to a new<br />

subscription plan. To swap a user to a new subscription, use the swap method. For example, we may<br />

easily switch a user to the premium subscription:<br />

.<br />

1 $user = App\User::find(1);<br />

2<br />

3 $user->subscription('premium')->swap();<br />

If the user is on trial, the trial period will be maintained. Also, if a “quantity” exists for the<br />

subscription, that quantity will also be maintained. When swapping plans, you may also use the<br />

prorate method to indicate that the charges should be pro-rated. In addition, you may use the<br />

swapAndInvoice method to immediately invoice the user for the plan change:<br />

.<br />

1 $user->subscription('premium')<br />

2 ->prorate()<br />

3 ->swapAndInvoice();<br />

Subscription Quantity<br />

Sometimes subscriptions are affected by “quantity”. For example, your application might charge $10<br />

per month per user on an account. To easily increment or decrement your subscription quantity,<br />

use the increment and decrement methods:<br />

.<br />

1 $user = User::find(1);<br />

2<br />

3 $user->subscription()->increment();<br />

4<br />

5 // Add five to the subscription's current quantity...<br />

6 $user->subscription()->increment(5);<br />

7<br />

8 $user->subscription()->decrement();<br />

9<br />

10 // Subtract five to the subscription's current quantity...<br />

11 $user->subscription()->decrement(5);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!