Claude Code Stripe Integration

Use Claude Code with Stripe to build checkout and subscriptions, wire signed webhooks, create Payment Intents, and test end to end with the Stripe CLI before going live.

By David Iya - Updated 2026-08-27

You can build a Stripe checkout flow in Claude Code, but the parts that protect real money are easy to get wrong: webhook signatures that must be verified server-side, keeping test and live keys separate, idempotency, and subscription lifecycle events. The Stripe integration closes that gap. Claude scaffolds the checkout or Payment Intent, writes a signed webhook handler, generates the Stripe CLI commands to forward and trigger events locally, and helps you verify everything in test mode before you touch a live key.

Before you start

  • Claude Code available in the development environment where the app lives (desktop app or CLI).
  • An active Stripe account with test-mode and live-mode API keys available in the dashboard.
  • The Stripe CLI installed and authenticated so you can forward and trigger webhook events locally.
  • A server-side environment where the secret key can live safely, never in client code or the repository.
  • A restricted or standard secret key stored as an environment secret, plus the webhook signing secret for signature verification.

What it unlocks

Faster Checkout Integration

Ask Claude Code to scaffold a Stripe Checkout Session or an embedded checkout with the right success and cancel URLs, so a working payment flow is a single instruction instead of a tour of the docs.

Correct Webhook Handling

Generate a server-side webhook endpoint that verifies the Stripe signature before trusting any event, which is the single most common thing developers get wrong when wiring up Stripe.

Subscriptions and Billing Done Right

Set up subscription products, prices, and the lifecycle events that matter, from checkout completed to invoice paid and subscription cancelled, without missing a state.

Payment Intents for Custom Flows

Build Payment Intents when you need full control of the payment UI, including confirmation, capture, and Strong Customer Authentication, with server and client responsibilities kept clearly separated.

Safer Test-to-Live Transitions

Keep test mode and live mode cleanly separated, wire up test cards and events first, and move to live keys only after the whole flow is proven, reducing the chance of a costly mistake in production.

Local Testing With the Stripe CLI

Have Claude Code generate the exact stripe listen and stripe trigger commands so you can forward real events to localhost and fire test events without waiting for a live purchase.

Products and Prices as Code

Create and manage products and prices through the API or CLI so your catalog is reproducible across environments instead of clicked together by hand in the dashboard.

Faster Payment Debugging

Give Claude Code a failing request, a webhook that never arrived, or a signature error and let it trace the cause instead of guessing, then propose the smallest correct fix.

Refunds, Invoices, and the Customer Portal

Wire up refunds, invoicing, and Stripe's hosted customer portal so customers can manage their own billing and you spend less time on manual account changes.

Security Built In by Default

Get an integration that keeps the secret key server-only, verifies every webhook, and never logs card data, so the parts that touch money follow Stripe's own guidance from the first commit.

How to connect Stripe

1

Get your API keys

Open the Stripe dashboard in test mode and copy the publishable and secret keys. The secret key must live on the server only. Store it as an environment secret, never in client code or the repository.

STRIPE_SECRET_KEY=sk_test_... # server-side environment only
2

Install and authenticate the Stripe CLI

Install the Stripe CLI and log in so you can forward and trigger webhook events locally. Ask Claude Code to help install it for your operating system if it is not already present.

stripe login
3

Scaffold a checkout or Payment Intent

Ask Claude Code to create a server route that builds a Checkout Session or a Payment Intent. Keep all key usage on the server and pass only the client secret or session URL to the browser.

# ask Claude Code: create a server route that returns a Checkout Session
4

Add a signed webhook handler

Have Claude Code generate a webhook endpoint that reads the raw request body, verifies the Stripe-Signature header against your webhook signing secret, and only then processes the event. Never trust an unverified event.

STRIPE_WEBHOOK_SECRET=whsec_... # from stripe listen or the dashboard
5

Forward events and test in test mode

Run the CLI to forward events to your local endpoint, then trigger test events and pay with a Stripe test card. Confirm the full flow works in test mode before you introduce any live key.

stripe listen --forward-to localhost:3000/api/webhooks/stripe

Build and Test a Checkout Flow With Webhooks

  1. Describe the flow

    Tell Claude Code what you are selling and how, such as a one-time product or a monthly subscription, and which framework and server runtime you are using.

  2. Create the checkout route

    Ask Claude Code to scaffold a server route that creates a Checkout Session with your line items and success and cancel URLs, keeping the secret key server-only.

  3. Generate the webhook handler

    Have Claude Code write a webhook endpoint that verifies the signature against the signing secret and handles the relevant events such as checkout session completed.

  4. Forward events locally

    Run stripe listen to forward events to your local endpoint and copy the printed signing secret into your environment so verification passes.

  5. Trigger and pay in test mode

    Use stripe trigger to fire events and complete a checkout with a Stripe test card, then confirm your handler provisions access correctly.

  6. Review before going live

    Have Claude Code audit the flow for signature verification, idempotency, and test-versus-live key usage, then switch to live keys only after it passes.

What people build with it

Stripe Checkout Session

Scaffold a hosted Checkout Session with line items, success and cancel URLs, and a server route that creates the session, so a customer can pay in a few clicks.

Embedded Checkout

Build an embedded or custom checkout when you want the payment form inside your own page instead of a redirect, keeping the secret key on the server.

Subscription Signup Flow

Create a subscription checkout tied to a recurring price, then handle the events that provision access once the first invoice is paid.

Metered and Tiered Billing

Set up usage-based or tiered prices and report usage so customers are billed for what they actually consume across a billing period.

Webhook Endpoint With Signature Verification

Generate a server endpoint that reconstructs the event from the raw body and the signing secret, so only genuine Stripe events are ever trusted.

Payment Intents for Custom UI

Create and confirm Payment Intents when you need control over the card element, capture timing, and Strong Customer Authentication challenges.

Products and Prices Management

Create products and prices in code or with the CLI so the catalog is version-controlled and consistent between test and live environments.

Refund Processing

Issue full or partial refunds against a charge or Payment Intent and reflect the refunded state back in your own application.

Invoicing

Generate one-off or recurring invoices, send them to customers, and react to invoice paid and payment failed events.

Customer Portal

Wire up Stripe's hosted customer portal so customers can update cards, change plans, and cancel without a support ticket.

Automatic Tax

Enable Stripe Tax on checkout and subscriptions so tax is calculated and collected correctly based on the customer's location.

Failed Payment and Dunning Handling

Handle failed card payments, retries, and past-due subscriptions so revenue is recovered and access is revoked at the right moment.

Idempotent Payment Requests

Add idempotency keys to payment-creating requests so a retried call after a network blip never charges a customer twice.

Local Event Testing

Use the Stripe CLI to forward live-looking events to a local endpoint and trigger specific events on demand while building the handler.

Migrating Test Config to Live

Audit a working test-mode integration for anything that must change for live, from keys and webhook endpoints to price IDs, before the switch.

Commands & configuration

Authenticate the Stripe CLI

stripe login

Opens a browser to pair the CLI with your account so it can forward and trigger events.

Forward webhook events to your local endpoint

stripe listen --forward-to localhost:3000/api/webhooks/stripe

Prints a webhook signing secret (whsec_...) to use for local signature verification.

Trigger a specific test event

stripe trigger checkout.session.completed

Fires a realistic test event so you can build and verify the handler without a real purchase.

Create a product from the CLI

stripe products create --name="Pro Plan"

Creates a product in the current mode so your catalog can be reproduced across environments.

Create a recurring price for a product

stripe prices create --product=prod_123 --unit-amount=900 --currency=usd --recurring.interval=month

Amounts are in the smallest currency unit, so 900 is 9.00 USD.

Tail live API request logs

stripe logs tail

Streams API request logs so Claude Code can help diagnose failing calls in real time.

Prompts to steal

Create a Stripe Checkout Session

Create a server route in my framework that builds a Stripe Checkout Session for a one-time purchase. Use the line items I provide, set success and cancel URLs, keep the secret key server-only, and return the session URL to redirect the browser to. Do not put any secret key in client code.

Build an embedded checkout

Set up Stripe embedded checkout so the payment form renders inside my own page instead of a redirect. Create the server route that returns the client secret and the client code that mounts the checkout, keeping all secret key usage on the server.

Set up a subscription flow

Build a subscription signup with Stripe. Create a Checkout Session in subscription mode tied to the recurring price I give you, then write the webhook handling that provisions access when the first invoice is paid and revokes it when the subscription is cancelled.

Write a signed webhook handler

Write a Stripe webhook endpoint for my framework. Read the raw request body, verify the Stripe-Signature header against the webhook signing secret using the Stripe library, and only process the event after verification succeeds. Handle checkout.session.completed and invoice.payment_failed as examples.

Create a Payment Intent

Create a Payment Intent flow where I control the payment UI. Write the server route that creates the Payment Intent and returns the client secret, and the client code that confirms the payment, including handling a required Strong Customer Authentication step.

Create products and prices

Create the products and prices for my catalog using the Stripe API or CLI. Here is the plan structure with names, amounts, currencies, and billing intervals. Give me reproducible commands or code so I can recreate the same catalog in test and live mode.

Add idempotency to payment requests

Review my payment-creating requests and add idempotency keys so a retried request after a network failure cannot charge a customer twice. Explain where the key should come from and how long Stripe honors it.

Forward and trigger events with the CLI

Give me the exact Stripe CLI commands to forward webhook events to my local endpoint and to trigger the specific events my handler cares about. Tell me where to find the printed signing secret and how to put it in my environment.

Debug a webhook signature error

My webhook is returning a signature verification error. Look at my handler and explain the likely cause, such as parsing the body before verification or using the wrong signing secret, then fix it so verification uses the raw request body and the correct secret.

Diagnose a webhook that never arrives

Stripe is not delivering events to my endpoint. Help me diagnose it: check whether the endpoint is registered for the right mode, whether the CLI is forwarding, whether the URL is reachable, and whether my handler is returning a 2xx quickly enough.

Handle failed payments and dunning

Add handling for failed card payments and past-due subscriptions. Wire up the events that fire on payment failure and recovery, and update my application state so access is revoked when a subscription lapses and restored when payment succeeds.

Issue a refund

Add a refund flow that issues a full or partial refund against a charge or Payment Intent from my admin side. Update my own records to reflect the refunded amount and status, and handle the case where a refund fails.

Wire up the customer portal

Set up Stripe's hosted customer portal so customers can update their card, change plans, and cancel on their own. Create the server route that generates a portal session for the signed-in customer and redirect them to it.

Enable automatic tax

Enable Stripe Tax on my checkout and subscriptions so tax is calculated based on the customer's location. Explain what I need to configure in the dashboard and what changes in my checkout code for tax to be collected correctly.

Audit for test versus live key mistakes

Audit my Stripe integration for test and live mode mistakes. Find anywhere I mix a test key with a live price ID or endpoint, confirm the secret key is server-only, and list everything that must change before I switch to live keys.

Fix a currency or amount bug

My charges are off by a factor of 100 or using the wrong currency. Explain how Stripe expects amounts in the smallest currency unit, review my code, and correct the amount and currency handling so customers are charged the right value.

Handle 3D Secure and SCA

Some payments require Strong Customer Authentication and are failing silently. Update my Payment Intent flow to handle the requires_action state, present the 3D Secure challenge, and confirm the payment after the customer completes it.

Resolve a price ID not found error

I am getting a no such price error when creating a checkout or subscription. Help me confirm the price ID exists in the current mode, that it is not a test price used with a live key, and fix my code to reference the correct price.

Move a client-side call to the server

I accidentally called the Stripe secret key from the browser and I am seeing CORS and exposure problems. Move all secret key usage to a server route, keep only the publishable key on the client, and explain why the secret key must never be exposed.

Prepare the integration for launch

Review my Stripe integration before launch as a careful engineer. Check signature verification, idempotency, test-to-live key separation, a pinned Stripe API version so behavior does not drift on upgrades, error handling on payment failures, and that no card data is logged. List blocking issues separately from nice-to-haves.

Recommended MCP servers

  • Stripe MCP Server (remote, OAuth)

    Stripe's official hosted MCP server. Connect over OAuth with no secret key on the developer machine, which is the safer default for money-sensitive work. Exposes tools for customers, products, prices, subscriptions, invoices, refunds, and documentation search.

  • Stripe MCP Server (local via npx)

    Run the official Stripe MCP server locally for development and testing. Point it at a test-mode secret key, never a live key, so Claude Code can call the Stripe API through MCP tools without hardcoding keys into your app.

  • Stripe Agent Toolkit

    Stripe's official toolkit that lets agent frameworks such as the Vercel AI SDK and LangChain call the Stripe API through function calling. Useful when you are building agentic payment features rather than only using MCP tools interactively.

Skills worth having

  • Checkout Integration

    Scaffold hosted or embedded Stripe Checkout with correct success and cancel handling and the secret key kept server-only.

  • Webhook Verification

    Generate a webhook endpoint that verifies the Stripe signature against the signing secret before trusting any event.

  • Subscription Setup

    Wire up recurring prices and the subscription lifecycle events that provision and revoke access at the right moments.

  • Payment Intents

    Build custom payment flows with Payment Intents, including confirmation, capture, and Strong Customer Authentication.

  • Stripe CLI Testing

    Produce the exact stripe listen and stripe trigger commands to forward and fire events for local end-to-end testing.

  • Refunds and Invoicing

    Implement refunds, invoices, and the hosted customer portal so billing changes do not require manual work.

  • Payment Debugging

    Trace signature errors, missing webhooks, and declined test payments to their root cause and propose the smallest fix.

  • Test to Live Migration

    Audit a working test-mode integration for everything that must change before switching to live keys and endpoints.

Troubleshooting

Keep it safe

  • Keep the secret key server-only. Never place the Stripe secret key in client code, a public request, or the browser bundle. Only the publishable key belongs on the client, and the secret key lives in a server environment secret.
  • Verify every webhook signature. Reconstruct each event from the raw request body and the webhook signing secret before trusting it, so a forged request cannot provision access or move money.
  • Use restricted keys where possible. Prefer restricted API keys scoped to only the resources a workflow needs instead of a full-access secret key, and rotate keys on a schedule.
  • Test mode before live mode. Build and verify the entire flow with test keys and test cards first, and switch to live keys only after signature verification, idempotency, and error handling are proven.
  • Never log card data or full secrets. Do not log full card numbers, CVCs, or secret keys. Stripe.js and Payment Intents are designed so sensitive card data does not touch your server, which keeps you out of unnecessary PCI scope.
  • Roll any exposed key immediately. If a secret key or signing secret is ever committed, printed, or shared, roll it in the dashboard right away and treat auto-reload on the account as a reason to move faster, not slower.

Stripe + Claude Code: FAQ

What is the Claude Code Stripe integration?

It is a workflow that lets Claude Code help you build and test Stripe payments. Claude Code can scaffold checkout and Payment Intents, write signed webhook handlers, generate Stripe CLI commands for local testing, and troubleshoot payment errors. It speeds up a correct integration while you keep control of every decision that touches money.

Is it safe to use Claude Code with my Stripe keys?

Yes, if you follow the same rules Stripe recommends. Keep the secret key server-only and never in client code or the repository, build in test mode first, and verify webhook signatures. For MCP, the remote server at mcp.stripe.com uses OAuth so no secret key sits on your machine, which is the safer default.

Can Claude Code set up Stripe Checkout?

Yes. Claude Code can scaffold a hosted or embedded Checkout Session, create the server route that builds it, and wire the success and cancel URLs. It keeps the secret key on the server and returns only the session URL or client secret to the browser.

Can Claude Code write my Stripe webhook handler?

Yes, and this is one of the most valuable things it does. Claude Code generates a webhook endpoint that reads the raw body, verifies the Stripe signature against your signing secret, and only then processes the event, which is the step developers most often get wrong.

How do I test Stripe locally with Claude Code?

Use the Stripe CLI. Claude Code can generate the stripe listen command to forward events to your local endpoint and the stripe trigger command to fire specific test events, so you can build and verify the flow with test cards without waiting for a real purchase.

Which Stripe MCP server should I use?

Stripe offers an official MCP server in two forms. The remote server at mcp.stripe.com connects over OAuth with no secret key on your machine and is the safer default. The local server runs via npx with a test-mode secret key and is convenient for development. Both are official.

Can Claude Code handle subscriptions and billing?

Yes. Claude Code can set up subscription products and recurring prices, build a subscription checkout, and handle the lifecycle events that provision access on payment and revoke it on cancellation, including failed payment and past-due handling.

What are the most common Stripe mistakes Claude Code helps avoid?

The recurring ones are exposing the secret key on the client, skipping or breaking webhook signature verification, mixing test and live keys, missing idempotency so retries double-charge, and passing amounts in the wrong unit. Claude Code can audit for all of these before you go live.

Go deeper

More integrations

Ship Paid Features With Claude Code

Join Claude Code Club to access practical tutorials, prompts, skills, MCP guides, workflows, templates, and real builds designed to help you get more from Claude Code.

Related: what is Claude Code, glossary, and use cases.