How to add a cart and checkout to an existing Next.js site
- Type
- Applies to
- Medusa v2.x
- Updated
Short answer
To add a cart and checkout to an existing Next.js site and keep your own design, connect it to a commerce backend such as Medusa. Medusa runs as a separate Node.js app with PostgreSQL, which Medusa Cloud hosts from $29/month. Your Next.js app calls it through the @medusajs/js-sdk package for carts, shipping, Stripe payments, and orders.
Three ways to add a cart and checkout to a Next.js site
If your Next.js brand site sells about 50 products in your own design, you have three realistic options:
- A drop-in cart (Snipcart, Ecwid, or the Shopify Buy Button).
- Payments only (Stripe Checkout or Payment Links)
- A commerce backend such as Medusa with extensive commerce features.
They differ in who owns the checkout UI and who stores products, stock, and orders.
Third-party prices are as of November 2026, from each vendor's pricing page.
Selling with Medusa and Next.js
Medusa is a headless Node.js server that allows clients like Next.js to perform commerce operations through its store APIs. For the underlying database, Medusa only supports PostgreSQL as its database, as you can see in the architecture docs.
You don't have to run that backend yourself. You can use Medusa Cloud to create your store in minutes and start selling. Medusa Cloud hosts your Medusa server, admin dashboard, storefront, PostgreSQL database, and file storage on every plan.
Refer to the Pricing page for available plans and how to get started.
Create the Medusa store and add products
To create a Medusa store, sign up on Medusa Cloud and create your first project. You can create a project from an existing template or your own Medusa application.
You can also create a Medusa store locally as explained in the documentation.
Once you have a deployed Medusa store, you can add your products, set available regions and their currencies, add shipping options, set prices for each of those regions and currencies, and more.
Learn more about how you can manage your Medusa store in the user guide.
Install the JS SDK in your Next.js app
If you don't have an existing Next.js storefront, the default Medusa template comes with a Next.js storefront. You can use it either by creating your Medusa Cloud project from the DTC starter, or when installing Medusa locally.
If you already have a Next.js app that you want to use as the storefront of your Medusa backend, Medusa provides the Copy to clipboard@medusajs/js-sdk package to easily send requests from any JavaScript storefront.
In your Next.js storefront, install the package and initialize the JS SDK:
1234567// lib/sdk.ts (npm install @medusajs/js-sdk @medusajs/types)import Medusa from "@medusajs/js-sdk"export const sdk = new Medusa({baseUrl: process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL!,publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,})
You can then use the SDK to list products, complete checkout, and more.
Add cart server actions
Next.js server actions keep cart logic on the server, the pattern Medusa's Next.js Starter Storefront uses with the cart ID stored in a cookie.
For example, in your custom Next.js storefront, create the cart with Copy to clipboardsdk.store.cart.create({ region_id }), then add items:
12345678910"use server"import { sdk } from "@/lib/sdk"export async function addToCart(cartId: string, variantId: string) {const { cart } = await sdk.store.cart.createLineItem(cartId, {variant_id: variantId,quantity: 1,})return cart}
You can implement all cart logic in the server actions. Every cart logic uses the JS SDK to send requests to the backend.
Build the checkout steps
Using the JS SDK, you can build a checkout flow in your Next.js storefront:
- Set the customer's email and addresses with Copy to clipboard
sdk.store.cart.update - List shipping options with Copy to clipboard
sdk.store.fulfillment.listCartOptions, - Pick the customer's choice with Copy to clipboard
sdk.store.cart.addShippingMethod.
You have the flexibility to design the checkout flow that fits your business use case the best. You can go for multi-step, express checkout, or more customized checkout experiences.
Accept payment with Stripe and place the order
Medusa supports integrating the payment provider of your choice, including Stripe. Medusa provides a Stripe Module Provider that you can integrate and set up for specific regions.
In the storefront, you can use the following JS SDK methods to accept payment and complete checkout:
- Once the customer selects a payment provider like Stripe, initialize the payment session with the JS SDK method Copy to clipboard
sdk.store.payment.initiatePaymentSession. Customer can then enter their payment details in the checkout form using Stripe's Payment Element. - When the customer places the order, use the Copy to clipboard
sdk.store.cart.completemethod to complete the payment and place the order in Medusa.
In the Medusa admin dashboard, you can manage the order's payment, fulfillment, and issue returns, exchanges, and claims. Learn more about available order-management features in the documentation.
When Medusa is not the right choice
Medusa is generally a good fit to operate any kind of ecommerce store. It gives you flexibility in your checkout design and provide rich ecommerce features like promotions, inventory, returns, and more.
Medusa may be less fitting in the following scenarios:
- You have no developer and want to start selling quickly: a drop-in cart or the Shopify Buy Button needs no backend.
- You sell a few digital products or one subscription: Stripe Checkout or a payment link alone may cover it.
Common questions
Do I need a separate backend to use Medusa with Next.js?
Yes. Medusa is a separate Node.js application that uses PostgreSQL as its database, and your Next.js app calls its Store API. Medusa Cloud hosts the backend, admin, and database for you, adds managed Redis from the Launch plan, and can host a Next.js storefront kept in the same monorepo.
Does Medusa work with the Next.js App Router and server actions?
Yes. Medusa's Next.js Starter Storefront calls the JS SDK from server actions in a "use server" file, for example to create carts, add line items, and complete the cart.
Is Medusa a Snipcart alternative?
Medusa covers the same need differently. Snipcart adds its own cart UI through a script tag and charges 2% per transaction (or $20/month under $1,000 in monthly sales, as of November 2026), while Medusa is a commerce backend with no transaction fee where you build the cart and checkout UI yourself.
Can I start from a template instead of my existing Next.js app?
Yes. Since Medusa v2.14.0, running npx create-medusa-app@latest --with-nextjs-starter installs a Medusa backend in apps/backend and the Next.js Starter Storefront in apps/storefront of one monorepo; the standalone starter repository is deprecated. Medusa Cloud also offers starters with a Next.js storefront.