React components for Stripe.js and Stripe Elements
React components for Stripe.js and Stripe Elements
React components for Stripe.js and Elements.
The minimum supported version of React is v16.8. If you use an older version,
upgrade React to use this library. If you prefer not to upgrade your React
version, we recommend using legacy
react-stripe-elements.
react-stripe-elementsreact-stripe-elements docsFor a new custom checkout page, we recommend the
Checkout Sessions API
with ui_mode: 'elements'. This lets you combine Stripe Elements with your own
React layout while Checkout Sessions manages the checkout state. If you want to
own every part of your checkout, the lower-level
Payment Intents API
provides more fine-grained control, but requires significantly more code and
ongoing maintenance.
First, install React Stripe.js and Stripe.js.
npm install @stripe/react-stripe-js @stripe/stripe-jsCreate a Checkout Session on your server using trusted product and pricing data, then return its client secret:
// POST /create-checkout-session
const session = await stripe.checkout.sessions.create({
ui_mode: 'elements',
mode: 'payment',
return_url: 'https://example.com/order/123/complete',
line_items: [
{
price_data: {
currency: 'usd',
product_data: {name: 'T-shirt'},
unit_amount: 1099,
},
quantity: 1,
},
],
});
if (!session.client_secret) {
throw new Error('Checkout Session is missing a client secret.');
}
res.json({clientSecret: session.client_secret});Client:
…React Stripe.js is packaged with TypeScript declarations. Some types are pulled
from @stripe/stripe-js—be sure to add
@stripe/stripe-js as a dependency to your project for full TypeScript support.
Typings in React Stripe.js follow the same
versioning policy as
@stripe/stripe-js.
This project is maintained by Stripe and does not accept external pull requests. If you have feedback or ideas, please open an issue.
No open issues yet, or sync has not completed.