Muhammad Affan Ashraf
Muhammad Affan Ashraf

Reputation: 21

StripeSignatureVerificationError: No signatures found matching the expected signature for payload

router.post(
  "/",
  bodyParser.raw({ type: "application/json" }),
  async (req, res) => {
    // Retrieve the event by verifying the signature using the raw body and secret.
    let event;
    const signature = req.headers["stripe-signature"]
    const endPointSecret = "whsec_***"
    console.log(signature)
    console.log(req.body)
    try {
      event = stripe.webhooks.constructEvent(
        req.body,
        signature,
        endPointSecret
      );
    } catch (err) {
      console.log(err);
      return res.sendStatus(400);
    }
    // Extract the object from the event.
    const dataObject = event.data.object;
    console.log(dataObject)
    res.sendStatus(200)
  }
);
I am testing Webhook on localhost by listening and forwarding event from 

Stripe CLI

to localhost. And I am using endpoint secret (from stripe cli provided after "stripe listen" command).

Still having signature verification error!!

enter image description here

Upvotes: 1

Views: 968

Answers (1)

Philippe Simo
Philippe Simo

Reputation: 1459

Make sure you are using the right webhook secret key.

You may have defined that key just for the online webhook endpoint, and not for local usage. Set it up in your local env vars as instance.

Upvotes: 0

Related Questions