In this episode, we dive into how to create and update a Stripe PaymentIntent in your checkout flow. First, you'll get a quick rundown of what a PaymentIntent actually is and why it's so central to how modern Stripe integrations work. If you've never used PaymentIntents directly before, don't worry—this episode breaks down the essentials and gets you comfortable with the basics.
We start by triggering the PaymentIntent creation when a user hits the checkout page with items in their cart. You'll see how to tell Stripe the payment amount, set the currency, and pass along anything else you might need (like cart IDs in the metadata if you want). The episode shows you how to keep your database in sync by storing the PaymentIntent ID in your cart model, which means you won't end up creating unnecessary new PaymentIntents every time the user reloads or changes something in their checkout.
Once you have the intent stored, you'll learn how to fetch it from Stripe, check if it needs to be updated (like if someone adds more items or changes the shipping option), and update the amount before passing everything off to the Stripe card form. The goal is to always keep the PaymentIntent in sync with your cart—so the user always gets charged the correct amount.
By the end, you’ll have a reliable way to create, store, retrieve, and update Stripe PaymentIntents throughout the checkout process, complete with best practices for keeping your app and Stripe in sync. Next up, we'll wire this into the actual Stripe payment form on the client to complete the payment!