API route call from another API route

hoping someone can help me here. Below is my NextJs(v13 app dir) Api route which Stripe forwards webhooks to, when the event.type of "checkout.session.completed" is sent i want to call another API route (add-credits).
import { NextResponse } from 'next/server';
import { buffer } from 'node:stream/consumers';
import { stripe } from '~/lib/stripe';

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_SIGNING_SECRET as string
);
} catch (err) {
console.log(err);
return NextResponse.json(
{
message: 'Webhook signature verification failed',
},
{
status: 400,
}
);
}

switch (event.type) {
case 'checkout.session.completed':
await fetch('http://localhost:3000/api/clerk/add-credits', {
method: 'GET',
});

break;
default:
console.log(`Unhandled event type ${event.type}`);
}

// have to return response promptly, ie without waiting for back-end process or stripe will potentially flag your account
return NextResponse.json(
{ message: 'successfully received' },
{ status: 200 }
);
}
import { NextResponse } from 'next/server';
import { buffer } from 'node:stream/consumers';
import { stripe } from '~/lib/stripe';

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_SIGNING_SECRET as string
);
} catch (err) {
console.log(err);
return NextResponse.json(
{
message: 'Webhook signature verification failed',
},
{
status: 400,
}
);
}

switch (event.type) {
case 'checkout.session.completed':
await fetch('http://localhost:3000/api/clerk/add-credits', {
method: 'GET',
});

break;
default:
console.log(`Unhandled event type ${event.type}`);
}

// have to return response promptly, ie without waiting for back-end process or stripe will potentially flag your account
return NextResponse.json(
{ message: 'successfully received' },
{ status: 200 }
);
}
When the call to add-credits route is made i get status code 200 but it says (MISS) in console
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server