#planetcreate

1 messages · Page 1 of 1 (latest)

small ventureBOT
rotund herald
#

So there are three things that are passed in to that construct event function:

  1. Your webhook secret
  2. The signature header
  3. 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?

steep flicker
#

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.

rotund herald
#

Can you print out the value for req.headers['stripe-signature'] and send it here?

steep flicker
#

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

rotund herald
#

Awesome that does look like the right format.

steep flicker
#

oke i will try that.

steep flicker
#

every ting they do there i have already tryed, here is the req.body debug i get,

rotund herald
#

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

steep flicker
#

the webhooksecret i have past we_1NdUUWJZmvGoBwYCeo75x5O7

#

i just prest the copy webhook secret key on the stripe dash bord

rotund herald
#

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

steep flicker
#

oke i hope this is it thanks in advance.

#

that worked thank you, i wished i knew this 3 days ago

rotund herald
#

Sorry that this gave you so much trouble but definitely happy that this is fixed now!