Build a checkout form with embedded componentsPublic preview
Use Elements and the Checkout Sessions API to build a checkout form.
Build a checkout form on your website using Stripe Elements and the Checkout Sessions API, a front-end SDK that manages tax, discounts, shipping rates, and more.
Set up the serverServer-side
Before you begin, you need to register for a Stripe account.
Use the official Stripe libraries to access the API from your application.
Set the SDK to use the custom_
beta version header.
Create a Checkout SessionServer-side
Add an endpoint on your server that creates a Checkout Session and returns its client secret to your front end. A Checkout Session represents your customer’s session as they pay for one-time purchases or subscriptions. Checkout Sessions expire 24 hours after creation.
Collect payment detailsClient-side
Collect payment details on the client with the Payment Element. The Payment Element is a prebuilt UI component that simplifies collecting payment details for a variety of payment methods.
The Payment Element contains an iframe that securely sends payment information to Stripe over an HTTPS connection. Avoid placing the Payment Element within another iframe because some payment methods require redirecting to another page for payment confirmation.
If you do choose to use an iframe and want to accept Apple Pay or Google Pay, the iframe must have the allow attribute set to equal "payment *"
.
The checkout page address must start with https://
rather than http://
for your integration to work. You can test your integration without using HTTPS, but remember to enable it when you’re ready to accept live payments.
Set up Stripe.js
Fetch the Checkout Session
Mount the Payment Element
Submit the paymentClient-side
Before submitting the payment, make sure that all required data is present by checking canConfirm. If you’re missing data, you can see what’s missing by checking confirmationRequirements.
Render a pay button
Call confirm when the customer is ready to complete checkout, such as in response to clicking a pay button.
Test your integration
- Create a Checkout Session and retrieve the client secret.
- Fill out the payment details with a payment method from the following table. For card payments:
- Enter any future date for card expiry.
- Enter any 3-digit number for CVC.
- Enter any billing postal code.
- Submit the payment to Stripe. You’re redirected to your
return_
.url - Go to the Dashboard and look for the payment on the Payments page. If your payment succeeded, you’ll see it in that list.
- Click your payment to see more details, like billing information and the list of purchased items. You can use this information to fulfill the order.
See Testing for additional information to test your integration.