#conniehunt
1 messages · Page 1 of 1 (latest)
Hi, can you add more details here? What have you tried so far?
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
You're not seeing any errors anywhere? Have you looked in your Dashboard?
No errors anywhere. Ive been checking dashboard and only seeing successful (200) logs
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
--> checkout.session.completed [evt_1N9bkuAHTGeGabuw8gBPAVLY]
2023-05-20 08:26:37 <-- [307] POST http://localhost:3000/api/stripe/webhook [evt_1N9bkuAHTGeGabuw8gBPAVLY]
It looks like it's returning a 307 error: https://dashboard.stripe.com/test/events/evt_1N9bkuAHTGeGabuw8gBPAVLY. Looking further to see what next steps would be recommended here.
what can i do to get around this?
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.
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 }
);
}