Build better payment forms using new “embedded” Stripe Checkout

Fireship · Beginner ·🛠️ AI Tools & Apps ·2y ago

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 Social Media Style Number Formatting in JS
Social Media Style Number Formatting in JS
Beyond Fireship
2 I used 3 different File System APIs in Node.js
I used 3 different File System APIs in Node.js
Beyond Fireship
3 Time is Relative, even in JavaScript
Time is Relative, even in JavaScript
Beyond Fireship
4 How to NOT Screw Up Firebase Environment Variables
How to NOT Screw Up Firebase Environment Variables
Beyond Fireship
5 How to make your JavaScript Bundle Smaller
How to make your JavaScript Bundle Smaller
Beyond Fireship
6 Subtle, yet Beautiful Scroll Animations
Subtle, yet Beautiful Scroll Animations
Beyond Fireship
7 Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Fireship
8 How to Build a Discord Bot
How to Build a Discord Bot
Beyond Fireship
9 How to make Eyeballs that Follow You Around
How to make Eyeballs that Follow You Around
Beyond Fireship
10 Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Beyond Fireship
11 Generate Images Programmatically on the Edge
Generate Images Programmatically on the Edge
Beyond Fireship
12 WTF are all these config files for?
WTF are all these config files for?
Beyond Fireship
13 NEW Firebase Features Just Dropped
NEW Firebase Features Just Dropped
Beyond Fireship
14 Next.js 13 - The Basics
Next.js 13 - The Basics
Beyond Fireship
15 Make Crazy Art with the NEW OpenAI Dall-e API
Make Crazy Art with the NEW OpenAI Dall-e API
Beyond Fireship
16 How to Setup Node.js with TypeScript in 2023
How to Setup Node.js with TypeScript in 2023
Beyond Fireship
17 Dramatically improve website speed with Partytown
Dramatically improve website speed with Partytown
Beyond Fireship
18 The easiest realtime app I’ve ever built
The easiest realtime app I’ve ever built
Beyond Fireship
19 10 Rendering Patterns for Web Apps
10 Rendering Patterns for Web Apps
Beyond Fireship
20 You don't need Node to use NPM packages
You don't need Node to use NPM packages
Beyond Fireship
21 Sorting Algorithms Explained Visually
Sorting Algorithms Explained Visually
Beyond Fireship
22 ChatGPT Official API First Look
ChatGPT Official API First Look
Beyond Fireship
23 I built an image search engine
I built an image search engine
Beyond Fireship
24 Industrial-scale Web Scraping with AI & Proxy Networks
Industrial-scale Web Scraping with AI & Proxy Networks
Beyond Fireship
25 Next.js Server Actions...  5 awesome things you can do
Next.js Server Actions... 5 awesome things you can do
Beyond Fireship
26 The ultimate guide to web performance
The ultimate guide to web performance
Beyond Fireship
27 I built a fullstack PaLM AI app in just 2 minutes
I built a fullstack PaLM AI app in just 2 minutes
Beyond Fireship
28 I tried 8 different Postgres ORMs
I tried 8 different Postgres ORMs
Fireship
29 I built a *streaming* AI chat app
I built a *streaming* AI chat app
Fireship
30 React VS Svelte...10 Examples
React VS Svelte...10 Examples
Fireship
31 How GitHub Actions 10x my productivity
How GitHub Actions 10x my productivity
Fireship
32 PROOF JavaScript is a Multi-Threaded language
PROOF JavaScript is a Multi-Threaded language
Fireship
33 Mind-blowing page animations are easy now... View Transitions API first look
Mind-blowing page animations are easy now... View Transitions API first look
Fireship
34 I built an Apple Vision Pro app... visionOS tutorial
I built an Apple Vision Pro app... visionOS tutorial
Fireship
35 This UI component library is mind-blowing
This UI component library is mind-blowing
Fireship
36 How I deploy serverless containers for free
How I deploy serverless containers for free
Fireship
37 GitHub Copilot now controls your command line...
GitHub Copilot now controls your command line...
Fireship
Build better payment forms using new “embedded” Stripe Checkout
Build better payment forms using new “embedded” Stripe Checkout
Fireship
39 Does Deno 2 really uncomplicate JavaScript?
Does Deno 2 really uncomplicate JavaScript?
Fireship
40 JavaScript performance is weird... Write scientifically faster code with benchmarking
JavaScript performance is weird... Write scientifically faster code with benchmarking
Fireship
41 Is Next.js 15 any good? "use cache" API first look
Is Next.js 15 any good? "use cache" API first look
Beyond Fireship
42 I built a DeepSeek R1 powered VS Code extension…
I built a DeepSeek R1 powered VS Code extension…
Fireship

The video teaches how to use the embedded Stripe Checkout feature to easily accept payments on a website without redirecting users, and how to integrate it with Next.js and Supabase. This is useful for software developers who want to create seamless payment experiences for their users. By following this tutorial, developers can learn how to build better payment forms and create successful SaaS products.

Key Takeaways
  1. Sign up for a Stripe account
  2. Install the Stripe library
  3. Create a payment form
  4. Integrate Stripe Checkout
  5. Configure payment settings
  6. Test the payment form
  7. Deploy the application
💡 The embedded Stripe Checkout feature allows for a seamless payment experience without redirecting users from the website, improving conversion rates and user satisfaction.

Related AI Lessons

Up next
How to Open HPL Files (HP-GL Plotter)
File Extension Geeks
Watch →