#planetcreate
1 messages · Page 1 of 1 (latest)
So there are three things that are passed in to that construct event function:
- Your webhook secret
- The signature header
- The raw request body
Have you already checked that your webhook secret is being populated with the specific webhook for your specific endpoint?
And have you checked that the signature header is populated properly?
yes oke i have al tree, like this vent = stripe.webhooks.constructEvent(req.body, sig, WebhookSecret)
i tink it will be handy if you have my full webhook code, '''router.post('/Succespayment', express.raw({type: 'application/json'}), async (req, res) => {
let event = req.body
if (WebhookSecret){
const sig = req.headers['stripe-signature']
if (!sig){
res.status(400).send(no stripe-signature found)
return
}
try {
event = stripe.webhooks.constructEvent(req.body, sig, WebhookSecret)
if (event.type === 'checkout.session.completed') {
const session = event.data.object
if (session.payment_status === 'paid') {
const paidAmount = session.amount_total / 100
res.status(200).send(`${paidAmount}`)
return
}
}
} catch (error) {
res.status(400).send(`Webhook Error: ${error.message} + ${req.body} + ${sig}`)
return
}
}else {
res.status(400).send(no webhook secret, webhooksecret: ${WebhookSecret})
return
}
res.send()
})
i checked if my webhooksecret is being populated with the specific webhook.
Can you print out the value for req.headers['stripe-signature'] and send it here?
oke i use google cloud app engine so this can take a few minutes.
i just looked it was already debugt i just ran the code and the stripe-signature that i got is t=1691760511,v1=e26df31f3497117487c9c3433ed5fd64b76e0b8c0a47f18e204ab0234240b356,v0=996637af7c5f8e1525e8ba48a000cdc37e53fec4e4d39368cd2bb2f2eca42e83
Awesome that does look like the right format.
And you mentioned being directed to things to try to get the raw request body before. Have you tried the solutions that users used from here? https://github.com/stripe/stripe-node/issues/341
oke i will try that.
every ting they do there i have already tryed, here is the req.body debug i get,
Just to go back to a common mixup with the webhook secret. Does your secret start with whsec_? Often I see people pass in the webhook endpoint ID (we_1234...) which can cause this error
the webhooksecret i have past we_1NdUUWJZmvGoBwYCeo75x5O7
i just prest the copy webhook secret key on the stripe dash bord
Ah that would be (at least part of) the problem then. That is the endpoint ID. If you go to your dashboard's page for the endpoint and click "reveal secret" it will give you the secret starting with whsec_ which is what you need to pass in to that constructEvent function
oke i hope this is it thanks in advance.
that worked thank you, i wished i knew this 3 days ago
Sorry that this gave you so much trouble but definitely happy that this is fixed now!