#ebenezer-owusu_webhooks

1 messages ยท Page 1 of 1 (latest)

oblique lanceBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1341832849191469068

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

gritty radish
#

Hi ๐Ÿ‘‹

What is the exact error you receive?

#

What code are you using to handle webhook requests?

oblique lanceBOT
whole escarp
#

Time Out Error.

event = stripe.webhooks.constructEvent(bodyBuffer, sig, process.env.STRIPE_WEBHOOK_SECRET);

Error on this line. The API runs without returning a response.
It returns a 200 response when commented

#

const sig = request.headers['stripe-signature'];

if (!sig) {
  context.log.error('Missing Stripe signature header');
  return { status: 400, body: 'Missing Stripe signature' };
}

let event;

const rawBody = await request.text(); // Read raw body from the request
const bodyBuffer = Buffer.from(rawBody, 'utf8');

try {
  event = stripe.webhooks.constructEvent(bodyBuffer, sig, process.env.STRIPE_WEBHOOK_SECRET);
} catch (err) {
  context.log.error(`Webhook Error: ${err.message}`);
  return {
    status: 400,
    body: `Webhook Error: ${err.message}`,
  };
}
// Process event in the background
processStripeEventAsync(event, context);

// Return 200 response to acknowledge receipt
return {
  status: 200,
  body: 'Webhook received successfully',
  headers: { 'Content-Type': 'application/json' },
};
vivid wigeon
#

Hi, taking over as my teammate needs to step away. Let me catch up

whole escarp
#

okay

vivid wigeon
#

What does 'Error on this line. The API runs without returning a response.
It returns a 200 response when commented' mean?

whole escarp
#

When I comment this - event = stripe.webhooks.constructEvent(bodyBuffer, sig, process.env.STRIPE_WEBHOOK_SECRET);

vivid wigeon
whole escarp
#

Am aware of quickly returning 200. Thats why am saying the stripe.webhooks.constructEvent() is causing the delay in the API

#

When I comment it out then the API returns 200