In this episode, we're taking care of what happens after a user makes a successful payment in our Alpine-powered frontend. Instead of handling redirection purely with JavaScript, we lean on good old HTML forms and Laravel's backend.
First, we look at a super simple method: just submitting the form and redirecting straight to the dashboard. It works, but it's not super flexible—you can't easily flash messages or show users a confirmation.
So, instead, we set up a new route (payment/redirect
), and create a controller in Laravel to handle the post-payment redirect. This lets us do backend stuff like flashing a "payment accepted" message to the session. We also touch on CSRF protection—what happens when you post and get a 419 error, and how to work around it (either by excluding your route from middleware or using Laravel's tools in your route definitions).
Lastly, we add a little styling to the flash message (it’s simple and not pretty, but it works!), and run through the full workflow: enter fake card details, make a payment, and see that satisfying confirmation message.
By the end of this video, you’ll know how to redirect users after payment, display a confirmation message, and you’re all set up to move onto handling backend events with Stripe webhooks in the next episode.