#Spica

1 messages ยท Page 1 of 1 (latest)

pure elmBOT
young monolith
#

Hello ๐Ÿ‘‹
The error usually suggests that the event payload that you are passing to constructEvent has been modified (most likely parsed to json)

Do you have a middleware that parses the incoming requests automatically?

compact tree
#

I am using express.raw({ type: 'application/json' }),

#

I did use body parser too but the same results

#

const sig = req.headers['stripe-signature'];
const endpointSecret = process.env.STRIPE_WEBHOOK_KEY
let event;
try {
event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
console.log('Event ================>' + event)
} catch (err) {
console.log('Error ================>' + err.message)
res.status(400).send(Webhook Error: ${err.message});
return;
}

#

this is my. code

young monolith
#

try express.raw({ type: '*/*' })

compact tree
#

I tried it but still not working

young monolith
#

do you have any other code like app.use(...) OR express.use(...) setting the parser outside the function?

compact tree
#

Yes

#

app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.use(express.raw({ type: '/' }))

young monolith
#

Can you try commenting that out?

compact tree
#

Yes sure

young monolith
#

you can also try adding something like following
app.use( "/webhook",express.raw({ type: "*/*" }))

#

where /webhook would be your route path instead

compact tree
#

I did comment the user(body parser and it worked )

#

thank you very much

#

I will try to figure out how to use it without commenting those lines noz

#

w

young monolith
#

Glad that worked! ๐Ÿ™‚ Happy to help