Comprehensive admin + user dashboards (production-ready)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextRequest } from "next/server";
|
||||
import { verifyPaypalWebhook } from "@/lib/billing/paypal";
|
||||
import { handlePaypalEvent } from "@/lib/billing/webhooks/paypal";
|
||||
import { alreadyProcessed, logWebhook } from "@/lib/billing/webhook-log";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -23,10 +24,16 @@ export async function POST(req: NextRequest) {
|
||||
return new Response("Invalid signature", { status: 400 });
|
||||
}
|
||||
|
||||
const event = JSON.parse(body) as { id?: string; event_type?: string };
|
||||
const eventId = event.id ?? `paypal_${Date.now()}`;
|
||||
if (event.id && (await alreadyProcessed(eventId))) return new Response("ok (duplicate)");
|
||||
|
||||
try {
|
||||
await handlePaypalEvent(JSON.parse(body));
|
||||
await handlePaypalEvent(event as Parameters<typeof handlePaypalEvent>[0]);
|
||||
await logWebhook("paypal", eventId, event.event_type ?? "unknown", "processed");
|
||||
} catch (err) {
|
||||
console.error("[paypal webhook] handler error", err);
|
||||
await logWebhook("paypal", eventId, event.event_type ?? "unknown", "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