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");
|
||||
|
||||
@@ -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