How to Integrate Stripe with Your Headless CMS
Sync product content from your headless CMS to Stripe so pricing, checkout, subscriptions, and product pages stay in step without copy-paste work.
What is Stripe?
Stripe is a payments platform for accepting card payments, wallets, bank transfers, subscriptions, invoices, and marketplace payouts. Commerce teams use Stripe to create Products, Prices, Checkout Sessions, Payment Links, coupons, tax settings, and customer records through APIs and dashboards. It’s widely used by SaaS companies, marketplaces, retailers, and digital product businesses that need payment infrastructure without building it from scratch.
Why integrate Stripe with a headless CMS?
Commerce teams usually split product work across two systems. Stripe handles the money side, like Prices, subscriptions, tax, coupons, and Checkout Sessions. Your headless CMS handles the product story, like names, descriptions, images, comparison tables, feature lists, FAQs, and localized launch copy. When those systems don’t talk, someone ends up copying product names into Stripe, pasting Price IDs into frontend code, and checking two dashboards before every launch.
Architecture overview
A typical Sanity and Stripe integration starts when an editor publishes a product, plan, or bundle in Sanity Studio. The published document is written to the Content Lake as structured JSON. A Sanity webhook fires on the publish mutation, or a Function runs server-side on the same content event. The handler receives the document ID, uses GROQ to fetch only the Stripe-ready fields, such as title, slug, description, image URL, price, currency, billing interval, and any existing Stripe IDs, then calls Stripe’s API with the Stripe Node SDK. For a new product, it calls stripe.products.create() and stripe.prices.create(). For an existing product, it calls stripe.products.update(), and if the amount changed, it creates a new Price because Stripe Prices can’t be edited after creation. The handler writes stripeProductId and stripePriceId back to Sanity so the frontend can query one content source and build product pages, pricing tables, and Checkout links. When the user clicks buy, your frontend creates a Stripe Checkout Session using the stored Stripe Price ID and redirects the user to Stripe-hosted checkout.
Common use cases
Sync product pages to Stripe Products
Publish product names, descriptions, images, and active states from Sanity, then create or update matching Stripe Products.
Launch subscription pricing tables
Model monthly and annual plans in Sanity, sync each plan to Stripe Prices, and render pricing pages with the right Checkout IDs.
Run regional commerce content
Keep localized product copy in Sanity while mapping each region to the correct Stripe currency, Price ID, and Stripe Tax setup.
Publish paid events or digital products
Create event pages, course pages, or download pages in Sanity, then connect each item to Stripe Checkout or Payment Links.
Step-by-step integration
- 1
Set up Stripe
Create a Stripe account, switch to test mode, and copy your secret key from Developers > API keys. Install the Stripe SDK with npm install stripe. If you’re using webhooks from Stripe back into your app, create an endpoint in Developers > Webhooks and save the signing secret.
- 2
Model commerce content in Sanity Studio
Create a product or plan schema with fields like title, slug, description, images, price, currency, billingInterval, active, stripeProductId, and stripePriceId. Keep Stripe IDs read-only for editors so they don’t accidentally break checkout.
- 3
Create the sync trigger
Use a Sanity webhook filtered to published product documents, or use a Function to run server-side logic when a product is created, updated, or deleted. Filter out drafts so Stripe only receives approved content.
- 4
Fetch exactly what Stripe needs
In the handler, use GROQ to fetch the product document and resolve references, such as primary image asset URLs or plan groups. Don’t send whole documents to Stripe. Send the fields Stripe accepts.
- 5
Call Stripe’s API
Use stripe.products.create() or stripe.products.update() for product metadata. Use stripe.prices.create() for amounts, currencies, and recurring intervals. Save the returned Product and Price IDs back to Sanity.
- 6
Test checkout from the frontend
Query Sanity for the product page and stripePriceId, create a Stripe Checkout Session from your backend, and test with Stripe’s test cards, such as 4242 4242 4242 4242. Check update cases too, especially price changes and unpublished products.
How Sanity + Stripe works
Build your Stripe integration on Sanity
Sanity’s AI Content Operating System gives you structured product data, real-time content events, and flexible APIs to connect Stripe with the commerce experiences you’re building.
Start building free →CMS approaches to Stripe
| Capability | Traditional CMS | Sanity |
|---|---|---|
| Product content modeling | Product data is often mixed into pages, which makes it harder to send clean fields to Stripe. | Schema-as-code lets you model products, plans, regions, bundles, and Stripe IDs as versioned TypeScript or JavaScript. |
| Sync timing | Teams often rely on manual updates, scheduled exports, or plugin-specific sync behavior. | Webhooks or Functions can run on publish events and call Stripe without polling or a separate batch worker. |
| Field-level control for Stripe | Handlers may need to parse page data or ignore fields that don’t belong in Stripe. | GROQ can return exactly the fields Stripe needs, including resolved image URLs and referenced pricing data, in one query. |
| Price change handling | Price changes can be hard to track when values live inside page content or plugins. | You can keep old and new Stripe Price IDs on the document, create new Prices on publish, and show editors which Price is active. |
| Multi-channel commerce | The website is usually the primary target, and other channels need separate feeds. | The same structured product data can feed web, mobile, Stripe, support agents through Agent Context, and editorial workflows in Sanity Studio. |
Keep building
Explore related integrations to complete your content stack.
Sanity + Shopify
Use Shopify for cart, catalog, and orders while Sanity structures richer product stories, buying guides, and campaign pages.
Sanity + Medusa
Pair Medusa’s commerce engine with Sanity product content for custom storefronts, subscriptions, and regional catalogs.
Sanity + Commercetools
Connect Commercetools commerce data with Sanity’s structured content for enterprise storefronts across regions, brands, and channels.