Search⌘ K
AI Features

Build the Checkout Form

Explore how to build a multi-step checkout form in React integrating Stripe API. Learn to handle cart display, capture billing details, and securely process payments using Stripe Elements and Payment Intents. Understand router setup, context management, and Stripe initialization to create a smooth payment experience.

Now that the server is ready for handling payments, let’s see how to build the checkout flow on the client-side. For this, we’ll focus on the frontend folder of the application directory.

Files
pages/BillingDetails.jsx
pages/Cart.jsx
pages/Pay.jsx
App.js
checkout.js
JavaScript (JSX)
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css";
import "shards-ui/dist/css/shards.min.css";
import { Container } from "shards-react";
import { Elements } from "@stripe/react-stripe-js";
import { loadStripe } from "@stripe/stripe-js";
import "./App.css";
import BillingDetailsPage from "./pages/BillingDetails";
import CartPage from "./pages/Cart";
import PayPage from "./pages/Pay";
import { CheckoutProvider } from "./checkout";
const stripePromise = loadStripe(<stripe publishable key>);
function App() {
return (
<Elements stripe={stripePromise}>
<CheckoutProvider>
<div className="App">
<Router basename="/checkout">
<Container className="app-container">
<Switch>
<Route path="/cart">
<CartPage />
</Route>
<Route path="/billing-details">
<BillingDetailsPage />
</Route>
<Route path="/pay">
<PayPage />
</Route>
</Switch>
</Container>
</Router>
</div>
</CheckoutProvider>
</Elements>
);
}
export default App;
Frontend

Routes for checkout

We have three routes on the frontend:

  1. The Cart page (
...