title: Stripe Webhooks StripeSignatureVerificationError
body: <p>I'm currently testing the <strong>Stripe</strong> <strong>Webhook</strong> Endpoints for the <strong>Checkout</strong> Process. </p>
  
  <p>I'm confused because Stripe shows two different snippets how to set up the Webhook endpoint in their docs.</p>
  
  <p>In the <a href="https://stripe.com/docs/payments/checkout/accept-a-payment" rel="nofollow noreferrer">Checkout Doc</a> they show this code snippet:</p>
  
  <pre><code>const stripe = require('stripe')('sk_test_...');
  
  // Find your endpoint's secret in your Dashboard's webhook settings
  const endpointSecret = 'whsec_...';
  
  // Using Express
  const app = require('express')();
  
  // Use body-parser to retrieve the raw body as a buffer
  const bodyParser = require('body-parser');
  
  // Match the raw body to content type application/json
  app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) =&gt; {
    const sig = request.headers['stripe-signature'];
  
    let event;
  
    try {
      event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
    } catch (err) {
      return response.status(400).send(`Webhook Error: ${err.message}`);
    }
  
    // Handle the checkout.session.completed event
    if (event.type === 'checkout.session.completed') {
      const session = event.data.object;
  
      // Fulfill the purchase...
      handleCheckoutSession(session);
    }
  
    // Return a response to acknowledge receipt of the event
    response.json({received: true});
  });
  
  app.listen(8000, () =&gt; console.log('Running on port 8000'));
  </code></pre>
  
  <p>And in their <a href="https://stripe.com/docs/webhooks/build" rel="nofollow noreferrer">Webhook Docs</a> they are showing this snippet:</p>
  
  <pre><code>const app = require('express')();
  // Use body-parser to retrieve the raw body as a buffer
  const bodyParser = require('body-parser');
  
  // Match the raw body to content type application/json
  app.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) =&gt; {
    let event;
  
    try {
      event = JSON.parse(request.body);
    } catch (err) {
      response.status(400).send(`Webhook Error: ${err.message}`);
    }
  
    // Handle the event
    switch (event.type) {
      case 'payment_intent.succeeded':
        const paymentIntent = event.data.object;
        // Then define and call a method to handle the successful payment intent.
        // handlePaymentIntentSucceeded(paymentIntent);
        break;
      case 'payment_method.attached':
        const paymentMethod = event.data.object;
        // Then define and call a method to handle the successful attachment of a PaymentMethod.
        // handlePaymentMethodAttached(paymentMethod);
        break;
      // ... handle other event types
      default:
        // Unexpected event type
        return response.status(400).end();
    }
    // Return a response to acknowledge receipt of the event
    response.json({received: true});
  });
  
  app.listen(8000, () =&gt; console.log('Running on port 8000'));
  </code></pre>
  
  <p>I tried both snippets but nothing seems to work for me.</p>
  
  <p>The first one gives me the <strong>StripeSignatureVerificationError</strong> when I try to constructEvent(...) </p>
  
  <p>and the second one is telling me that the Object <strong>event</strong>  is <strong>undefined</strong>.</p>
  
  <p>Does someone know why both of these endpoints are not working for me ?</p>