-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Labels
Description
Describe the bug
As I was playing with the Stripe webhooks api, it appears that I can't use the constructEvent method because I can't get the raw request body from strapi. A similar issue existed with Express and was resolved by using body-parser middleware but I can't figure out the strapi equivalent.
Steps to reproduce the behavior
- Install the stripe cli
- Create a simple hook in you strapi app
- Start forwarding to your strapi app the events from the stripe-cli (eg:
stripe listen --forward-to localhost:1337/hook) - Launch an event with your stripe cli (e.g.:
stripe trigger payment_intent.created) - See error (
Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing
Expected behavior
I should be able to get a correct constructEvent result by parsing the body of my request.
Code snippets
My hook:
hook: async (ctx) => {
const body = JSON.stringify(ctx.request.body);
const endpointSecret = 'whsec_secret';
const signature = ctx.request.headers['stripe-signature'];
const event = stripe.webhooks.constructEvent(body, signature, endpointSecret);
console.log(event)
}
System
- Node.js version: 11.12.0
- NPM version: 6.7.0
- Strapi version: 3.0.0-beta.17.8
- Database: postgres
- Operating system: MacOS
Ideas
As said before, stripe is giving an example for Express here which solves the issue by using bodyParser.raw({type: 'application/json'}) as a middleware for this route.

