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 176<br />

method to manage the model’s subscription:<br />

.<br />

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

2<br />

3 $user->subscription('monthly')->create($creditCardToken);<br />

The create method will automatically create the Stripe subscription, as well as update your database<br />

with Stripe customer ID and other relevant billing information. If your plan has a trial configured<br />

in Stripe, the trial end date will also automatically be set on the user record.<br />

In you want to implement trial periods, but are managing the trials entirely within your application<br />

instead of defining them within Stripe, you must manually set the trial end date:<br />

.<br />

1 $user->trial_ends_at = Carbon::now()->addDays(14);<br />

2<br />

3 $user->save();<br />

Additional User Details<br />

If you would like to specify additional customer details, you may do so by passing them as second<br />

argument to the create method:<br />

.<br />

1 $user->subscription('monthly')->create($creditCardToken, [<br />

2 'email' => $email, 'description' => 'Our First Customer'<br />

3 ]);<br />

To learn more about the additional fields supported by Stripe, check out Stripe’s documentation on<br />

customer creation¹³¹.<br />

Coupons<br />

If you would like to apply a coupon when creating the subscription, you may use the withCoupon<br />

method:<br />

¹³¹https://stripe.com/docs/api#create_customer

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

Saved successfully!

Ooh no, something went wrong!