#conniehunt

1 messages · Page 1 of 1 (latest)

fossil sierraBOT
indigo ginkgo
#

Hi, can you add more details here? What have you tried so far?

elder crown
#
  switch (webhookEvent.type) {
    case 'checkout.session.completed':
      const data = await fetch('http://localhost:3000/api/clerk/add-credits', {
        method: 'GET',
      });
      const json = await data.json();
      console.log(json);
      break;
    default:
      console.log(`Unhandled event type ${webhookEvent.type}`);
  }

this is the logic i am running to detect the desired webhook

#

I have also tried just running a log inside the handleWebhook func with no luck

indigo ginkgo
#

You're not seeing any errors anywhere? Have you looked in your Dashboard?

elder crown
#

No errors anywhere. Ive been checking dashboard and only seeing successful (200) logs

indigo ginkgo
#

Can you share the id of the event please?

#

You're saying that when you use the following Curl in your Terminal, you're not seeing anything?

stripe listen --events checkout.session.completed --forward-to localhost:3000/api/stripe/webhook

elder crown
indigo ginkgo
elder crown
#

what can i do to get around this?

indigo ginkgo
#

I was able to further look and confirm that Stripe CLI is successfully forwarding this event. The issue here is that on your end, your server is responding to us with 307 error, and your local server is redirecting. You'd need to debug this on your end and not redirect.

elder crown
# indigo ginkgo I was able to further look and confirm that Stripe CLI is successfully forwardin...

okay, is there anything in my API route which is deprecated/incompatible with app router etc that may be causing


export async function POST(req: any) {
  const rawBody = await buffer(req.body);

  let event;
  try {
    event = stripe.webhooks.constructEvent(
      rawBody,
      req.headers.get('stripe-signature') as string,
      process.env.STRIPE_WEBHOOK_SECRET_KEY as string
    );
  } catch (err) {
    console.log(err);
    return NextResponse.json(
      {
        message: 'Webhook signature verification failed',
      },
      {
        status: 400,
      }
    );
  }
  console.log(event);
  return NextResponse.json(
    { message: 'successfully received' },
    { status: 200 }
  );
}