Build better payment forms using new “embedded” Stripe Checkout
Skills:
AI Workflow Automation80%
Key Takeaways
The video demonstrates how to use the new embedded Stripe Checkout feature to accept payments without leaving the website, utilizing tools like Next.js and Supabase.
Full Transcript
over the years I've tried to make money with a lot of different side hustles most of them have failed miserably but some have gone on to make me literally dozens of dollars if you've ever built a piece of software as a business or side hustle one of the best ways to validate your idea is to slap a payment form on your website and see if anybody pays you for it when a project makes 0 it usually means one of two things a your product sucks or B your product is amazing but the marketing sucks however there is a third possibility the checkout form experience is so bad that people just give up trying to pay you when I first learned a code implementing payments was a nightmare you had to deal with this thing called authorized.net which had a horrible API it was expensive there were no sdks and a million different ways to shoot yourself in the foot security wise it strip payments saw an opportunity to optimize this experience for developers and that's why today the company is now processing $1 trillion in payments every year I just released a new course for fireship pro members about implementing strip payments in a software as a service product and one of the features in that course is stripe checkout which will redirect a user to a web page hosted by stripe when the user wants to buy something on your website one thing that kind of sucks about this approach though is that the user has to be redirected to a thirdparty website it just feels a little bit awkward and breaks the consistency of your brand well luckily a few months ago it became possible to embed stripe checkout directly into your own website which means that user never has to leave in today's video I'll show you exactly what that implementation looks like what you're looking at here is the demo for the full stripe course and when you click this by now button it redirects you to a website on checkout. stripe.com when the payment is complete it then redirects back to the main website that works but we can streamline this process by embedding the checkout form directly in our own website and that just feels totally frictionless like stripe checkout you don't have total control over what you can customize like you can't directly edit the CSS or anything like that but it is responsive out of the box and you can customize things like colors and fonts to fit in with your brand in this demo I'm using Daisy UI to trigger aot window then render the checkout form inside of that if the modal is wide it goes to a horizontal layout but will shrink down to a vertical layout for mobile devices now let's take a look at the code to see how it's implemented I'm here in a nextjs project which has also been configured with the stripe SDK and the first step is to create a checkout session on the server a checkout session is a Json object created by stripe that contains things like the product details that you're selling it tells stripe what the user is paying for and how to render the checkout form in your UI we could do this with nextjs server actions but I'm going to use a more traditional API route with a route. TS file the route exports a post function which will handle a post request to this URL now inside the function body we'll use the stripe SDK to create a checkout session which includes the price IDs for the products that you're selling but there's a couple of unique details first of all the UI mode is embedded as opposed to hosted on the stripe website then second you'll notice down here we have a return URL as opposed to a success and cancel URL and and it also includes the session ID as a URL parameter and that's because after the payment goes through we'll want to immediately fetch the session ID to check it status so stripe will redirect back to a URL that looks like this then in our front end code we can make a get request to the back end so it grabs the session ID from the URL it then makes a call to stripe checkout sessions retrieve that returns a big Json object that will give us the status of the payment then we can design our UI around that accordingly that takes care of our backend code now we need to figure out how to render the checkout form in the front end in react stripe.js provides built-in components to handle this in nextjs I've created this embedded checkout button component which is a client component inside of which it Imports load stripe as well as the pre-built react components currently this component is using an HTML dialogue to render a modal which is all styled with tailwind and Daisy UI by the way but from here we need to make a post request to the backend API that we just defined I'm using the browser fetch AP to do that and also wrapping it in use callback is so the function doesn't get redefined every time this component renders but most importantly the API needs to return the client secret on the checkout session now we're not going to call this function directly but instead put it as a property on an object called options which will get passed to the embedded checkout Provider from stripe let's go down into the jsx and declare that component here along with the options as a prop when this component is rendered stripe will automatically make a call to our back back end to get the client secret along with the details for the checkout session like the products the user wants to buy and by the way the client secret is a value that should never be stored in your database it's just a temporary way for stripe to show the payment form in the front end based on the data you provided for the checkout session and now at this point we should be able to open up the Modo on the UI and it will render the checkout page there and you can of course customize this in a variety of ways to fit in with your own branding now once the checkout session is complete it's going to redirect to a return URL we can Implement that with a page. TSX file which is a react server component nextjs before defining the component I'm first going to Define our data fetching logic which needs to get the session ID from the URL that stripe redirected to now we could create another API route and make a fetch call to it but because we're in a react server component here we can actually just use the stripe SDK directly and call the stripe checkout sessions retrieve method with the session ID as an argument and now in the server component all we have to do is get the search parameter session ID and pass it as an argument to this function after we fetch the session from stripe it's going to have a bunch of data on it like the session status which might be open or complete if it's open we'll tell the user their payment hasn't gone through yet but if it's complete we'll send them a thank you message congratulations you now have a secure payment form embedded directly on your website but there's a lot more to payments in that if you want to learn everything you need to know check out the full stripe course and because you graciously watch this entire video here's a discount code you can use on the course itself or on a pro membership to get get access to everything thank you for supporting the channel and I will see you in the next one
Original Description
Learn how to use the new embedded Stripe Checkout feature to easily accept payments without ever leaving your own website. Learn everything about payments for software developers in my new Stripe for SaaS featuring Next.js and Supabase:
Stripe for SaaS: https://fireship.io/courses/stripe-saas/
And use code BEYOND30 to save some money!
Full Tutorial and Code: https://fireship.io/courses/stripe-saas/bonus-embedded-checkout/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Beyond Fireship · Beyond Fireship · 38 of 42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
▶
39
40
41
42
Social Media Style Number Formatting in JS
Beyond Fireship
I used 3 different File System APIs in Node.js
Beyond Fireship
Time is Relative, even in JavaScript
Beyond Fireship
How to NOT Screw Up Firebase Environment Variables
Beyond Fireship
How to make your JavaScript Bundle Smaller
Beyond Fireship
Subtle, yet Beautiful Scroll Animations
Beyond Fireship
Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Fireship
How to Build a Discord Bot
Beyond Fireship
How to make Eyeballs that Follow You Around
Beyond Fireship
Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Beyond Fireship
Generate Images Programmatically on the Edge
Beyond Fireship
WTF are all these config files for?
Beyond Fireship
NEW Firebase Features Just Dropped
Beyond Fireship
Next.js 13 - The Basics
Beyond Fireship
Make Crazy Art with the NEW OpenAI Dall-e API
Beyond Fireship
How to Setup Node.js with TypeScript in 2023
Beyond Fireship
Dramatically improve website speed with Partytown
Beyond Fireship
The easiest realtime app I’ve ever built
Beyond Fireship
10 Rendering Patterns for Web Apps
Beyond Fireship
You don't need Node to use NPM packages
Beyond Fireship
Sorting Algorithms Explained Visually
Beyond Fireship
ChatGPT Official API First Look
Beyond Fireship
I built an image search engine
Beyond Fireship
Industrial-scale Web Scraping with AI & Proxy Networks
Beyond Fireship
Next.js Server Actions... 5 awesome things you can do
Beyond Fireship
The ultimate guide to web performance
Beyond Fireship
I built a fullstack PaLM AI app in just 2 minutes
Beyond Fireship
I tried 8 different Postgres ORMs
Fireship
I built a *streaming* AI chat app
Fireship
React VS Svelte...10 Examples
Fireship
How GitHub Actions 10x my productivity
Fireship
PROOF JavaScript is a Multi-Threaded language
Fireship
Mind-blowing page animations are easy now... View Transitions API first look
Fireship
I built an Apple Vision Pro app... visionOS tutorial
Fireship
This UI component library is mind-blowing
Fireship
How I deploy serverless containers for free
Fireship
GitHub Copilot now controls your command line...
Fireship
Build better payment forms using new “embedded” Stripe Checkout
Fireship
Does Deno 2 really uncomplicate JavaScript?
Fireship
JavaScript performance is weird... Write scientifically faster code with benchmarking
Fireship
Is Next.js 15 any good? "use cache" API first look
Beyond Fireship
I built a DeepSeek R1 powered VS Code extension…
Fireship
More on: AI Workflow Automation
View skill →
🎓
Tutor Explanation
DeepCamp AI