Free toolGenerate .mcp.json configs for Claude Code, Cursor & Codex →

Based on Stripe's and Anthropic's official docs, checked

How to add Stripe payments with Claude Code

Stripe scores 5/5 on our Claude Code fit scale: it ships an official Anthropic-marketplace plugin with an MCP server and 10 skills. Stripe Checkout hosts the payment page for you, so you never handle card numbers. Your server creates a Checkout Session, the customer pays on Stripe, and a webhook tells your server the payment cleared. This guide builds that loop end to end in test mode, where no real money moves.

  1. 1. Create a Stripe account and stay in test mode

    Create a Stripe account, then keep the Test mode toggle on in the Dashboard while you build. In test mode you use test API keys in every call: the secret key starts with sk_test_ and the publishable key starts with pk_test_. Find both under Developers, then API keys. Test transactions do not move funds, so you can run the full checkout flow as many times as you like without charging anyone.

    STRIPE_SECRET_KEY=sk_test_...
    STRIPE_PUBLISHABLE_KEY=pk_test_...

    Source: https://docs.stripe.com/testing

  2. 2. Install the official Stripe plugin

    Stripe's agent plugins give your AI agent access to Stripe developer tools, live account data, and the latest skills and technical guidance, so it builds your integration from current Stripe patterns instead of outdated ones. For Claude Code, Stripe documents the install command below, run in your project directory. If you prefer the automatic route, install the Stripe CLI first and run stripe agent setup, which detects the agents you use and configures the plugin for you.

    claude plugin install stripe@anthropic-plugin-directory
    stripe agent setup

    Source: https://docs.stripe.com/agents/plugin

  3. 3. Install the Stripe CLI and log in

    The Stripe CLI is what forwards webhook events to your laptop while you develop, and it can trigger test events on demand. Install it with the script for your operating system, open a new terminal so the PATH change takes effect, then log in. Script installations enable automatic updates by default, so the CLI stays current without extra work from you.

    curl -fsSL https://cli.stripe.com/install.sh | sh
    export PATH="$HOME/.stripe/bin:$PATH"
    stripe login

    Source: https://docs.stripe.com/agents/plugin

  4. 4. Create a product and a price

    Before you write code, create what you are selling. In the Dashboard, go to Product Catalog, add a product, and set its price. Pick one-time for a single purchase or recurring for a subscription. Save it and copy the price ID, which starts with price_. Your code passes that price ID when it creates a Checkout Session, never a hard-coded amount, so changing the price later means editing the Dashboard, not your code.

    STRIPE_PRICE_ID=price_...

    Source: https://docs.stripe.com/get-started/use-cases/saas-subscriptions

  5. 5. Install the Node SDK and set your keys

    Install the official Stripe Node library and create one server-side client from your secret key. Keep this file on the server only. The secret key must never reach browser code, and it must never be committed to git. Put your keys in .env.local for local work and in your hosting platform's environment settings for deploys. You will add the webhook signing secret in step 7.

    npm install stripe
    import Stripe from 'stripe';
    
    export const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);

    Source: https://docs.stripe.com/checkout/quickstart

  6. 6. Create a Checkout Session and redirect

    A Checkout Session is a server-side object that defines one payment flow. Your endpoint creates it with the price ID, the mode, and the two URLs Stripe returns the customer to. Use mode payment for a one-time purchase and mode subscription for recurring billing. Stripe answers with a session object that holds a hosted URL, and you redirect the customer there. Stripe renders the payment form and handles cards, wallets, and 3D Secure.

    const session = await stripe.checkout.sessions.create({
      mode: 'payment',
      line_items: [{ price: process.env.STRIPE_PRICE_ID, quantity: 1 }],
      success_url: 'http://localhost:3000/success',
      cancel_url: 'http://localhost:3000/cancel',
    });
    
    res.redirect(303, session.url);

    Source: https://docs.stripe.com/checkout/quickstart

  7. 7. Add the webhook and test the full loop

    The webhook is where your app learns the payment cleared. Start the listener, copy the signing secret it prints into .env.local as STRIPE_WEBHOOK_SECRET, then add an endpoint that verifies every event with that secret and the raw request body. Handle checkout.session.completed to fulfil the order, and return a 200 response fast, before any slow work. Then pay with the test card 4242 4242 4242 4242, any future expiry date, and any 3-digit CVC, and watch the event arrive. You can also fire one without a browser using stripe trigger.

    stripe listen --forward-to localhost:4242/webhook
    const event = stripe.webhooks.constructEvent(
      payload, signature, process.env.STRIPE_WEBHOOK_SECRET
    );
    
    if (event.type === 'checkout.session.completed') {
      // fulfil the order here
    }
    res.status(200).end();
    stripe trigger payment_intent.succeeded

    Source: https://docs.stripe.com/webhooks

Why Checkout instead of your own card form

Checkout is a Stripe-hosted payment page. Your server creates a Session, the browser redirects to Stripe, and Stripe handles the card form, wallets, local payment methods, and 3D Secure. You never see or store card numbers, which keeps the sensitive part of payments with Stripe instead of in your code. For most apps this is the fastest path to taking money, and it is the one Stripe recommends for new integrations.

The plugin's skills cover the rest of the Stripe surface: stripe-pay for payment flows, stripe-docs for looking up current API details, stripe-best-practices for the patterns Stripe itself recommends, and stripe-projects for scaffolding. Ask Claude Code to check the skill before it writes a new Stripe call, so it follows the current docs instead of guessing an API shape.

Fulfil from the webhook, never from the success page

The success page is confirmation UX, not proof of payment. Customers close tabs, hit the back button, or lose connection before the redirect lands. Stripe's webhooks retry delivery for up to three days with exponential backoff in live mode, so the webhook is the reliable signal. Grant access, send the receipt, or ship the order only when your handler processes checkout.session.completed.

Two rules keep the handler safe. First, verify the signature on every event with the raw body, the Stripe-Signature header, and your whsec_ signing secret. If verification fails, reject the request. Second, return a 2xx response before any slow work, and track event IDs so a retried delivery does not fulfil the same order twice. Stripe does not guarantee events arrive in order, so do not depend on receiving them in sequence.

Test cards to know

Stripe's testing docs list cards for every scenario, and three cover most of your testing. Use 4242 4242 4242 4242 for a payment that succeeds, with any future expiry date and any 3-digit CVC. Use 4000 0000 0000 9995 to simulate a decline, and 4000 0025 0000 3155 to test a payment that needs 3D Secure authentication. The 3D Secure card is the one that catches broken redirect flows most often, so do not skip it.

Never use real card details while testing. Stripe's own guidance is explicit: use test API keys in all API calls, and use test cards for interactive testing. When you are ready to go live, swap the test keys for live ones and store them in a secrets vault or environment variables, never in source code.

Going live checklist

Switching to live mode is a short checklist, not a rewrite. Replace the test publishable and secret keys with live ones. Register your webhook endpoint in the Dashboard under Workbench, then Webhooks, with a publicly accessible HTTPS URL, and copy the live signing secret into your hosting environment. The live secret is different from the test one the CLI printed. Then open the Event deliveries tab for the endpoint and confirm events show as delivered before you announce the launch.

Tips

Then just ask

Example prompt (our suggestion, not from vendor docs):

"Help me add Stripe payments in this project. Follow the Stripe skills, keep secrets in environment variables, and show me the plan before changing files."

Next steps

Frequently asked questions

Only for local webhook testing. The Dashboard covers products, prices, and API keys. The CLI earns its place by forwarding live events to your laptop and triggering test events on demand.

Sources