Explore

Stripe

How to Add Stripe Payments to a Vibe-Coded App (Checkout, Webhooks, Testing)

Add Stripe Checkout to an app built with Claude Code, Codex, Cursor, Lovable or Replit: connect the Stripe MCP server, have your agent build checkout and a verified webhook, test with the Stripe CLI, and go live safely.

Published 2026-06-18.

Score your launch page freeRead the blog

Your app works and people are asking how to pay. Payments have a reputation for being fiddly, and with good reason: most problems only show up when a real card meets a real webhook. The good news is that the integration itself is small, and a coding agent can write most of it if you give it a clear spec and test it properly.

This guide uses Stripe Checkout, the hosted payment page, because it handles cards, wallets, 3D Secure and receipts for you. The examples use Next.js App Router, but the steps are the same in any stack. With a prepared app and Stripe account, the core integration can be done in an afternoon; budget extra time for testing and going live.

Verify the measurement after checkout

A checkout button click, a success-page visit, and a paid order are different receipts. In a test environment, complete the following sequence before treating ad-platform purchases as revenue:

  1. Start a visit with a known test campaign label. Record a non-personal visitor ID and browser session context.
  2. Start checkout and preserve the bounded campaign and visitor fields in server-created metadata. Keep private form text out of analytics.
  3. Verify payment on the server. Carry the same attribution through any background fulfillment job.
  4. Deduplicate the purchase using the checkout session, and keep amount, currency, and test/live mode explicit.
  5. Reload the success page and replay the webhook. The order should stay the same; raw event attempts may differ from unique paid orders.

If the buyer opens a shared report, use the buyer's current identity for checkout. The original scan's campaign remains historical acquisition evidence, not automatic credit for the later sale. Watch the public scan flow, then use the launch audit walkthrough to choose the next public-page check.

Before you start

  • A Stripe account. Test mode works immediately; going live requires activating the account with your business details.
  • Your app running locally, plus a deployed URL for production webhooks.
  • A coding agent (Claude Code, Codex, Cursor or similar) with access to the repository.
  • A decision on what you sell: a one-time payment or a subscription, and the price.

If you sell to customers in many countries and do not want to handle sales tax or VAT yourself, consider a merchant-of-record provider instead. They act as the seller and handle tax, for a higher fee. Stripe also offers tax calculation as a separate product. Check what applies to you with an accountant.

Step 1: Give your agent Stripe context

Stripe publishes an MCP server and agent skills1 so coding agents can search Stripe's docs and work with your account. Stripe's recommended setup installs the CLI and configures the agents it detects:

npm install -g @stripe/cli@latest
stripe agent setup

Or add the MCP server manually:

# Claude Code
claude mcp add --transport http stripe https://mcp.stripe.com/

# Codex
codex mcp add stripe --url https://mcp.stripe.com

Authenticate with OAuth when prompted, and grant access to a sandbox or test environment first. Turn on your client's tool-approval setting so you see each call before it runs. Stripe's MCP server can write data (create products, prices and more), so treat it like giving someone access to your dashboard.

Step 2: Create the product and price

In the Stripe Dashboard, under Products, add a product and a price (monthly, yearly or one-time). Copy the price ID; it starts with price_. Or ask your agent to do it through the MCP server in test mode:

In my Stripe sandbox, create a product "Pro" with a monthly price of
[amount] [currency]. Show me the product and price IDs. Do not touch
live mode.

Step 3: Have the agent build checkout and the webhook

Give the agent a spec, not a wish:

## Feature: Stripe Checkout for the Pro plan

Goal: a signed-in user can pay for Pro and gets Pro access automatically.

Requirements:
1. POST /api/stripe/checkout creates a Checkout Session (mode: subscription,
   price from STRIPE_PRICE_ID) for the signed-in user and returns its URL.
   The client redirects to that URL.
2. Pass the user ID as client_reference_id and in metadata.
3. POST /api/stripe/webhook verifies the Stripe signature using the raw
   request body and STRIPE_WEBHOOK_SECRET.
4. On checkout.session.completed, mark the user as Pro in the database,
   keyed by client_reference_id. The handler must be safe to run twice.
5. Handle customer.subscription.deleted (remove Pro) and
   invoice.payment_failed (flag the account).
6. Success page at /billing/success, cancel returns to /pricing.

Constraints:
- Keys only from environment variables; never in client code.
- Access is granted only by the webhook, never by the success page.

Acceptance:
- [ ] Test card 4242 4242 4242 4242 grants Pro via the webhook
- [ ] Declined card 4000 0000 0000 0002 does not grant Pro
- [ ] Type check, tests and build pass

The server code the agent produces should look roughly like this. Use it to review what the agent wrote:

// app/api/stripe/checkout/route.ts
import Stripe from 'stripe';
import { NextResponse } from 'next/server';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST() {
  const user = await requireUser(); // your auth helper

  const session = await stripe.checkout.sessions.create({
    mode: 'subscription',
    line_items: [{ price: process.env.STRIPE_PRICE_ID!, quantity: 1 }],
    client_reference_id: user.id,
    metadata: { userId: user.id },
    success_url: `${process.env.APP_URL}/billing/success?session_id={CHECKOUT_SESSION_ID}`,
    cancel_url: `${process.env.APP_URL}/pricing`,
  });

  return NextResponse.json({ url: session.url });
}
// app/api/stripe/webhook/route.ts
import Stripe from 'stripe';
import { NextResponse } from 'next/server';

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST(request: Request) {
  const payload = await request.text(); // raw body, not request.json()
  const signature = request.headers.get('stripe-signature');
  if (!signature) return NextResponse.json({ error: 'missing signature' }, { status: 400 });

  let event: Stripe.Event;
  try {
    event = stripe.webhooks.constructEvent(payload, signature, process.env.STRIPE_WEBHOOK_SECRET!);
  } catch {
    return NextResponse.json({ error: 'invalid signature' }, { status: 400 });
  }

  if (event.type === 'checkout.session.completed') {
    const session = event.data.object;
    await grantPro(session.client_reference_id!); // must be idempotent
  }
  if (event.type === 'customer.subscription.deleted') {
    await revokeProForCustomer(event.data.object.customer as string);
  }

  return NextResponse.json({ received: true });
}

On the client, the button posts to the checkout route and sends the browser to the returned url. You do not need Stripe.js on the client for a basic Checkout redirect.

Step 4: Set environment variables

# .env.local (never commit this file)
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
STRIPE_PRICE_ID=price_...
APP_URL=http://localhost:3000

Set the same names, with production values, in your host's environment settings. Check .env.local is in .gitignore.

Step 5: Test webhooks locally with the Stripe CLI

The Stripe CLI2 forwards test events to your local server:

stripe login
stripe listen --forward-to localhost:3000/api/stripe/webhook

stripe listen prints a webhook signing secret. Put it in STRIPE_WEBHOOK_SECRET and restart your dev server. Then run through checkout in the browser with Stripe's test cards3:

Card numberBehavior
4242 4242 4242 4242Succeeds
4000 0000 0000 0002Declined
4000 0025 0000 3155Requires authentication (3D Secure)

Use any future expiry date and any three-digit CVC. Watch the stripe listen output and your server logs. Confirm the user actually gets Pro in your database, and that a declined card does not grant it.

You can also fire events directly:

stripe trigger checkout.session.completed

Step 6: Go live

  1. In the Stripe Dashboard, create a webhook endpoint pointing at https://yourdomain.com/api/stripe/webhook, subscribed to the events you handle. Copy its signing secret into production STRIPE_WEBHOOK_SECRET.
  2. Create the live product and price, and set the live STRIPE_PRICE_ID.
  3. Switch production STRIPE_SECRET_KEY to the live key.
  4. Deploy.
  5. Make one real purchase with your own card, confirm access is granted, then refund it from the Dashboard.
  6. Check the webhook endpoint in the Dashboard shows successful deliveries.

Common problems and fixes

  • "No signatures found matching the expected signature." The handler parsed the body before verifying it. Use the raw body (request.text() in the App Router) and check you are using the secret for the right endpoint: the CLI's secret locally, the Dashboard endpoint's secret in production.
  • Works in test, fails in live. Test and live mode have separate keys, prices and webhook endpoints. A test price ID with a live key fails.
  • Paid but no access. The webhook is not reaching your server, or it errors. Check delivery attempts in the Dashboard and your function logs. Never grant access from the success page as a workaround.
  • Users get access twice or emails send twice. Stripe can deliver the same event more than once. Make the handler idempotent, for example by recording processed event IDs.
  • Webhook returns 404 or redirects in production. Middleware or auth is intercepting the route. Exclude the webhook path.

After the first payment

  • Turn on the Stripe customer portal so customers can update cards and cancel without emailing you.
  • Handle invoice.payment_failed with a clear in-app message to update the card.
  • Add your refund policy next to the price, before checkout.
  • Re-run the payment items in the vibe coding security checklist.

If you use a browser builder such as Lovable, Bolt or Replit, the same principles apply: test in test mode, verify webhooks, and grant access only from the webhook. Check the builder's own Stripe integration docs for where to put keys.

Payments are one launch item

A working checkout matters only if people reach it. Once payments work, make sure the page shows the price clearly. In our scan of 238 launch pages, 62% of low-scoring pages had no pricing, against 2% of the top pages. Run the product launch checklist, or paste your URL at launchbuddy.ai/scan for a free score and the one gap to fix first.

Sources and notes

  1. Stripe, Model Context Protocol (MCP) documentation: https://docs.stripe.com/mcp
  2. Stripe CLI: https://docs.stripe.com/stripe-cli
  3. Stripe testing (test card numbers): https://docs.stripe.com/testing

Related LaunchBuddy resources

Vibe Coding Security Checklist: 17 Things to Audit Before Real UsersCodex vs Claude Code (November 2026): Which Coding Agent Should You Build With?Launch Readiness Checklist: A 100-Point Self-Assessment for Solo BuildersProduct Launch Metrics: The Day-Two Dashboard and Daily Checks for an MVP
How to Add Stripe Payments to a Vibe-Coded App (Checkout, Webhooks, Testing)