#.hendrid

1 messages · Page 1 of 1 (latest)

copper chasmBOT
hybrid quartz
#

Hello, that error can happen 3 ways from the things that you pass in to the construct event function

  1. Using an incorrect webhook secret
  2. Passing an incorrect signature to the
  3. Not passing in the raw webhook body to the function
#

I would recommend double-checking the first two first

sterile flint
#

I think I have a correct webhook secret, but I not sure about other

hybrid quartz
#

You are calling the code right, I would recommend printing out the sig variable to make sure it is populated and your process.env.STRIPE_WEBHOOK_SECRET param to make sure it is populated and has a format of whsec_1234...

sterile flint
#

is correct the format of the sig?

hybrid quartz
#

Yep that signature looks fine

#

Don't send the webhook signature to me here, that is sensitive

sterile flint
#

cool

hybrid quartz
#

But with that, you will want to check that it starts with whsec_ and that it matches the secret for that specific webhook

#

So if you created it via the CLI, double check that it matches your CLI. If you created it via the dashboard, double check the dashboard. Using the secret from another endpoint will cause signature verification to fail.

sterile flint
hybrid quartz
#

I would also print out the webhook secret before calling ConstructEvent just to confirm that the code is reading the env file properly

#

Soundling likely that this is being caused by the last one I mentioned

  1. Not passing in the raw webhook body to the function
sterile flint
hybrid quartz
#

Basically, Stripe needs the exact raw webook body that we sent out. Frameworks will often be helpful and parse the json before passing the body to your handler function, but that throws off our signature validation

#

I'd reccommend looking up "nestjs raw post body" to find how to access the raw body before modifications

sterile flint
#

mmm... and how we can fix that

hybrid quartz
#

Not that familiar with nest myself but this SO looks relevant

sterile flint
#

My nestjs version don't handle raw body directly

#

I use this link for config the middleware but does'nt work 🤷

hybrid quartz
#

Unfortunately I don't have nestjs specific advice, I'd recommend looking further in to how to do this for your specific version

sterile flint
hybrid quartz
#

Nestjs forums or StackOverflow could be helpful here as well

copper chasmBOT