In this episode, we're finally making it possible for users to start the checkout process for a subscription! We begin by creating a new controller (called SubscriptionController
) and hooking it up to our routes. The controller's main job is simple: redirect the user to Stripe’s checkout page with the plan they want.
At first, we hard-code the monthly plan to make sure Stripe integration works smoothly, generating a real checkout session link and confirming that the redirection does its thing. You'll see how Stripe handles all the heavy lifting for payment info and subscriptions. At this stage, when a payment is successful, it only completes on Stripe’s end — syncing with our app comes later when we deal with webhooks.
But we don’t stop there! Hard-coding isn’t ideal, so we quickly refactor things. The video walks you through how to dynamically select a plan (monthly or yearly) via the query string, pulling the plan details from our configuration, and passing the correct price ID to Stripe. The end result? Users can now click either "monthly" or "yearly" and be sent to the right checkout page on Stripe, ready to subscribe!
By the end of this video, you’ll have a working, dynamic checkout flow that’s ready for users to choose their plan and be redirected to Stripe to finish payment.