Lesson 4 / 25
Stripe Checkout
A hosted payment page created from a Checkout Session.
Checkout Sessions
Stripe Checkout is a prebuilt payment page hosted by Stripe (an embedded variant also exists). Your server creates a Checkout Session with line items, a mode (payment, subscription or setup) and a success_url and cancel_url, then redirects the customer to session.url. Checkout handles the form, validation, localisation, wallets such as Apple Pay and Google Pay, many local payment methods and 3D Secure. When the customer pays, Stripe redirects them to your success URL and sends a checkout.session.completed webhook, which is where you fulfil the order.
Three ways to take money
Stripe offers a hosted Checkout page, an embeddable Payment Element and no-code Payment Links.
Create a session and redirect
An Express route on the server.
app.post('/create-checkout-session', async (req, res) => {
const session = await stripe.checkout.sessions.create({
mode: 'payment',
line_items: [{ price: 'price_...', quantity: 1 }],
success_url: 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
cancel_url: 'https://example.com/cart',
client_reference_id: req.user.id, // your own order or user id
});
res.redirect(303, session.url);
});
The success page is not proof of payment
Customers can close the tab before the redirect, or visit the success URL directly. Use the success page only to say thank you, and fulfil from the webhook.
Quick check: Where should you send the customer after creating a Checkout Session?
- To your success_url immediately
- To the session's url
- To the Stripe Dashboard
- To a page that asks for the card number on your server
Answer
To the session's url — Stripe hosts the payment page at session.url.