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

.<br />

1 if ($user->onGracePeriod()) {<br />

2 //<br />

3 }<br />

Resuming Subscriptions<br />

If a user has cancelled their subscription and you wish to resume it, use the resume method:<br />

.<br />

1 $user->subscription('monthly')->resume($creditCardToken);<br />

If the user cancels a subscription and then resumes that subscription before the subscription has fully<br />

expired, they will not be billed immediately. Instead, their subscription will simply be re-activated,<br />

and they will be billed on the original billing cycle.<br />

Handling Stripe Webhooks<br />

Failed Subscriptions<br />

What if a customer’s credit card expires? No worries - Cashier includes a Webhook controller that<br />

can easily cancel the customer’s subscription for you. Just point a route to the controller:<br />

.<br />

1 Route::post('stripe/webhook', 'Laravel\Cashier\WebhookController@handleWebhook');<br />

That’s it! Failed payments will be captured and handled by the controller. The controller will cancel<br />

the customer’s subscription when Stripe determines the subscription has failed (normally after three<br />

failed payment attempts). Don’t forget: you will need to configure the webhook URI in your Stripe<br />

control panel settings.<br />

Since Stripe webhooks need to bypass Laravel’s CSRF verification, be sure to list the URI an exception<br />

in your VerifyCsrfToken middleware:<br />

.

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

Saved successfully!

Ooh no, something went wrong!