Comprehensive admin + user dashboards (production-ready)
This commit is contained in:
@@ -2,6 +2,7 @@ import { NextRequest } from "next/server";
|
||||
import type Stripe from "stripe";
|
||||
import { stripe } from "@/lib/billing/stripe";
|
||||
import { handleStripeEvent } from "@/lib/billing/webhooks/stripe";
|
||||
import { alreadyProcessed, logWebhook } from "@/lib/billing/webhook-log";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -19,10 +20,15 @@ export async function POST(req: NextRequest) {
|
||||
return new Response("Invalid signature", { status: 400 });
|
||||
}
|
||||
|
||||
// Idempotency: skip events we've already processed (Stripe retries deliveries).
|
||||
if (await alreadyProcessed(event.id)) return new Response("ok (duplicate)");
|
||||
|
||||
try {
|
||||
await handleStripeEvent(event);
|
||||
await logWebhook("stripe", event.id, event.type, "processed");
|
||||
} catch (err) {
|
||||
console.error("[stripe webhook] handler error", err);
|
||||
await logWebhook("stripe", event.id, event.type, "failed", err instanceof Error ? err.message : String(err));
|
||||
return new Response("Handler error", { status: 500 });
|
||||
}
|
||||
return new Response("ok");
|
||||
|
||||
Reference in New Issue
Block a user