#.hendrid
1 messages · Page 1 of 1 (latest)
Hello, that error can happen 3 ways from the things that you pass in to the construct event function
- Using an incorrect webhook secret
- Passing an incorrect signature to the
- Not passing in the raw webhook body to the function
I would recommend double-checking the first two first
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...
is correct the format of the sig?
Yep that signature looks fine
Don't send the webhook signature to me here, that is sensitive
cool
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.
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
- Not passing in the raw webhook body to the function
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
mmm... and how we can fix that
Not that familiar with nest myself but this SO looks relevant
My nestjs version don't handle raw body directly
I use this link for config the middleware but does'nt work 🤷
Unfortunately I don't have nestjs specific advice, I'd recommend looking further in to how to do this for your specific version
Nestjs forums or StackOverflow could be helpful here as well