June 3, 2026
11 min read
Full Checkout with Medusa, Stripe, and React: End-to-End Architecture
How to connect Medusa as an ecommerce backend with Stripe as a payment processor and a React frontend, from cart to confirmed order.
Leer en espanolThe architecture of the checkout flow
In a Medusa and Stripe integration, the Medusa backend acts as an intermediary between the frontend and Stripe. The client never calls Stripe directly with API credentials. Instead, Medusa creates a payment session on behalf of the cart and returns to the frontend the information needed for Stripe.js to confirm the payment without exposing secret keys.
The complete flow has five steps: create the cart, add items and a shipping address, select a shipping method, initialize payment sessions, and confirm the payment. The order is created in Medusa automatically upon receiving the Stripe confirmation via webhook. Each step has its own REST endpoint in the Medusa API.
Configuring the Stripe plugin in Medusa
The official Stripe plugin for Medusa is configured in `medusa-config.js` with the Stripe secret key and the webhook secret. Medusa automatically registers the webhook endpoint at `/stripe/hooks` and handles signature verification. There is no need to implement the webhook handler manually.
Once installed, Stripe appears as a payment option in all regions where it is enabled. Regions control which payment providers are available, which currency is used, and which taxes apply. A cart in the Mexico region uses MXN; one in the US region uses USD, and Stripe handles both currencies without changes on the frontend.
Payment sessions: the bridge between Medusa and Stripe
When initializing checkout, the frontend calls `POST /store/carts/:id/payment-sessions`. Medusa creates a payment session with Stripe, which internally creates a PaymentIntent and returns the `client_secret`. That secret is all the frontend needs for Stripe.js to confirm the payment from the browser.
The `client_secret` is never stored in the product database and never logged. It is valid for 24 hours and only serves to confirm that specific payment. If the cart changes — the user adds or removes items — the payment session must be updated so the PaymentIntent amount stays correct.
Initialize payment sessions and confirm payment with Stripe Elements.
// 1. Initialize payment sessions on the cart
const { cart } = await medusaClient.carts.createPaymentSessions(cartId);
const stripeSession = cart.payment_sessions?.find(
(s) => s.provider_id === 'stripe',
);
if (!stripeSession) throw new Error('Stripe session not available');
const clientSecret = stripeSession.data.client_secret as string;
// 2. Select Stripe as the active payment provider
await medusaClient.carts.setPaymentSession(cartId, {
provider_id: 'stripe',
});
// 3. Confirm payment with Stripe.js
const { error } = await stripe.confirmCardPayment(clientSecret, {
payment_method: { card: cardElement },
});
if (error) throw new Error(error.message);
// 4. Complete the order in Medusa
const { type, order } = await medusaClient.carts.complete(cartId);
if (type === 'order') {
router.push(`/orders/${order.id}`);
} Error handling and retries in checkout
The most frequent errors in checkout are: card declined, session expired, and network interruption between the payment step and the order completion step. For a declined card, Stripe returns a typed error in the `confirmCardPayment` response — show it to the user and let them retry with a different card without resetting the cart.
For an expired session, call `createPaymentSessions` again to get a new `client_secret`. For a network interruption, the Stripe webhook guarantees that Medusa receives the confirmation even if the frontend never called `carts.complete`. The order status can be checked using the customer email or the cart ID.
More articles
Back to articlesPayment Platforms in Mexico: Stripe, Conekta, Mercado Pago, and OpenPay
A technical and commercial comparison of the four most-used payment platforms for digital projects in Mexico.
June 3, 2026
7 min read
Shipping Platforms in Mexico: Skydropx, EnviosPerros, Pakke, and Enviame
How to choose between the main shipping aggregators for ecommerce in Mexico based on your volume, operations, and technical needs.
June 3, 2026
7 min read
Headless CMS in 2026: PayloadCMS, Strapi, Sanity, and Directus
Which headless CMS to choose based on project type, the level of technical control you need, and how you plan to model your content.
June 3, 2026
8 min read