I’m integrating Stripe with my SaaS and I’m calculating the quota using the valid payment period, but Stripe always returns the period as being from the 70s, even though I have defined the plan as monthly, it comes with the beginning through the webhook and end on the same day in the 70s
// webhook
import Stripe from "stripe";
import { headers } from "next/headers";
import {
processWebhookInvoiceSuccess,
processWebhookSubscription,
stripe,
} from "@/services/stripe";
export async function POST(req: Request) {
const body = await req.text();
const signature = headers().get("Stripe-Signature") as string;
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(
body,
signature,
process.env.STRIPE_WEBHOOK_SECRET
);
} catch (error: any) {
console.error(`Webhook Error: ${error.message}`);
return new Response(`Webhook Error: ${error.message}`, { status: 400 });
}
switch (event.type) {
case "customer.subscription.created":
case "customer.subscription.updated":
await processWebhookSubscription(event.data.object);
break;
case "invoice.payment_succeeded":
await processWebhookInvoiceSuccess(event.data.object);
default:
console.log(`Unhandled event type ${event.type}`);
}
return Response.json({ ok: true }, { status: 200 });
}