#kirito

1 messages · Page 1 of 1 (latest)

sinful stagBOT
hybrid lake
#

Hi! Let me help you with this.

#

Please share your webhook endpoint code.

ripe parcel
#

  apiVersion: "2022-11-15",
})

const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET

// Stripe requires the raw body to construct the event.
export const config = {
  api: {
    bodyParser: false,
  },
}

const cors = Cors({
  allowMethods: [ "POST", "HEAD" ],
})```
#
  if (req.method === "POST") {
    const buf = await buffer(req)
    const sig = req.headers["stripe-signature"]!
    let event: Stripe.Event

    try {
      event = stripe.webhooks.constructEvent(buf.toString(), sig, webhookSecret)
    } catch (err) {
      const errorMessage = err instanceof Error ? err.message : "Unknown error"
      // On error, log and return the error message.
      if (err! instanceof Error) {
        console.log(err)
      }
      console.log(`❌ Error message: ${errorMessage}`)
      res.status(400).send(`Webhook Error: ${errorMessage}`)
      return
    }
    // Successfully constructed event.
    console.log("✅ Success:", event.id)

    // Cast event data to Stripe object.
    if (event.type === "invoice.paid") {
      const dataObject = event.data.object as Stripe.Invoice````
#

something like that ?

hybrid lake
#

Not sure what buffer(req) does. You can also pass the Buffer variable to constructEvent(), no need to cast to string.

ripe parcel
#

I don't know the problem is that it was working before but just suddenly it did stop.

hybrid lake
ripe parcel
#

yes

#

maybe an update to the api version :
from "2022-08-01"to "2022-11-15"

#

Also it work locally but not on test server

hybrid lake
#

This might be the reason. Did it happen at the same time?

ripe parcel
#

No

hybrid lake
ripe parcel
#

Emm how is that?

hybrid lake
#

You might have an some kind of API proxy that intercepts the requests.
Where is your test server hosted?

ripe parcel
#

On the cloud but it was working before