Files
0pt/app/api/webhooks/stripe/route.ts
T
adminandClaude Opus 4.8 ba96566c14 feat(infra): payments (Stripe), auth scaffold, engine bridge, embeds, .env.example
Env-guarded so build stays green: /api/payments/[order_id]/deposit+release + /api/webhooks/stripe (lazy Stripe, 50/50 escrow, 501 until keys); /api/auth login|me|logout (HMAC signed-session scaffold, guarded dev login); lib/engine bridges edge->FastAPI (estimates defers to ENGINE_URL when set); components/embed for NocoDB/Metabase signed URLs; .env.example full inventory. tsc 0, build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-24 21:19:29 +02:00

28 lines
1.1 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { getStripe } from "@/lib/stripe";
import { setStatus } from "@/lib/orders-store";
// POST /api/webhooks/stripe (docs/04) — verify signature, advance order status.
export async function POST(req: NextRequest) {
const stripe = getStripe();
const whSecret = process.env.STRIPE_WEBHOOK_SECRET;
const sig = req.headers.get("stripe-signature");
if (!stripe || !whSecret || !sig) {
return NextResponse.json({ received: false, reason: "not_configured" }, { status: 200 });
}
const body = await req.text();
let event;
try {
event = stripe.webhooks.constructEvent(body, sig, whSecret);
} catch {
return NextResponse.json({ error: "bad_signature" }, { status: 400 });
}
if (event.type === "checkout.session.completed") {
const s = event.data.object as { metadata?: { order_id?: string; kind?: string } };
const oid = s.metadata?.order_id;
const kind = s.metadata?.kind;
if (oid) await setStatus(oid, kind === "balance" ? "delivered" : "in_production");
}
return NextResponse.json({ received: true });
}