Prompt

receive Stripe webhooks in Node

Technology / API Platforms1 observationLast seen Oct 5, 2026

Latest observation

Oct 5, 2026OpenAI APIWeb search: off

To receive Stripe webhooks in Node, you need to:

  1. Create a webhook endpoint
  2. Read the raw request body
  3. Verify the Stripe signature
  4. Handle the event

Example with Express

1) Install Stripe

npm install stripe express

2) Set up the webhook route

Important: Stripe requires the raw body, not express.json() for this route.

const express = require('express');
const Stripe = require('stripe');

const app = express();
const stripe = Stripe(process.env.STRIPE_SECRET_KEY);

app.post(
  '/webhook',
  express.raw({ type: 'application/json' }),
  (req, res) => {
    const sig = req.headers['stripe-signature'];
    const endpointSecret = process.env.STRIPE_WEBHOOK_SECRET;

    let event;

    try {
      event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
    } catch (err) {
      console.error('Webhook signature verification failed:', err.message);
      return res.status(400).send(`Webhook Error: ${err.message}`);
    }

    switch (event.type) {
      case 'payment_intent.succeeded':
        console.log('Payment succeeded:', event.data.object);
        break;

      case 'checkout.session.completed':
        console.log('Checkout completed:', event.data.object);
        break;

      default:
        console.log(`Unhandled event type ${event.type}`);
    }

    res.json({ received: true });
  }
);

app.listen(3000, () => console.log('Server running on port 3000'));

3) Add the webhook secret

From Stripe Dashboard:

  • Developers → Webhooks → your endpoint
  • Copy the Signing secret
  • Put it in STRIPE_WEBHOOK_SECRET

4) If you already use express.json()

Make sure the webhook route is defined before express.json() or exclude that route:

app.post('/webhook', express.raw({ type: 'application/json' }), handler);

app.use(express.json());

5) Test locally with Stripe CLI

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

Then trigger a test event:

stripe trigger payment_intent.succeeded

Common gotchas

  • Don’t parse the body before verification
  • Use the correct webhook signing secret
  • Ensure the request uses the exact raw body Stripe sent

If you want, I can also give you:

  • an Express + TypeScript version
  • a Next.js webhook example
  • a Fastify version

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as Circuit. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.