#Vinicius Martins-webhook-body-validation

1 messages · Page 1 of 1 (latest)

quiet lark
#

Hello 👋
In order for constructEvent to work correctly it actually needs raw body that Stripe sends.
Do you have a middleware running?

#

I'd also make sure that you're using the correct webhook secret

minor cave
#

Yeap, had some middleware, but now I'm trying use all the stripe cli return in get evt_...

#

webhook secret is the same that I'm was using in cli

quiet lark
#

but now I'm trying use all the stripe cli return in get evt_...
I'm not sure I follow here
can you give me an example?

minor cave
#

Yeap

#

I'm use the payment checkout to trigger local events into stripe cli

#

so, I see the event id, like evt.... and using cli I can get all de event data

#

stripe get evt_3KlCBSLEzMxoThho1SDxSNKP

quiet lark
#

so, what are you doing with the event data then?

I'm not sure if it can be copy pasted into your code and then validate it

minor cave
#

I tryed by the fastfy and copy and paste to validade

quiet lark
#

fastfy is similar to express correct?

minor cave
#

yeap

#

I'll make some tests here using a direct call to test (without middlewares)

#

maybe fastify is modifying the body at some point

#

I tryed to change enconding from json to just raw and not work

quiet lark
#

yeah that is highly likely.
if it is similar to express, you may want to check if you can write a definition for a route specifically like

app.use('/webhook', express.raw({type: "*/*"}))

The above code allows my sample app to pass raw body to /webhook route but pass JSON for other routes.

However, the example that I gave is for express. You'd want to find something similar in fastify

minor cave
#

Makes sense, after my tests I give a feedback on what I got, working or not, maybe it will help others