I was trying to update the database when each event is trigged.However trying to access the request body in each event fails,can anyone help me in preserve the request body throughout the event handling process
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function POST(request: NextRequest, response: NextResponse) {
const endpointSecret = process.env.NEXT_WEBHOOK_ENDPOINT_SECRET;
let data;
let eventType;
let reponseData;
if (endpointSecret) {
let event;
const payload = await request.text();
const sig = request.headers.get("stripe-signature");
try {
event = stripe.webhooks.constructEvent(payload, sig!, endpointSecret);
eventType = event.type;
data = event.data.object;
switch (event.type) {
case 'customer.subscription.created':
updateAPI(event.data.object,request.body);
break;
case 'customer.subscription.deleted':
updateAPI(event.data.object,request.body);
break;
}
}
}