import { NextResponse, type NextRequest } from "next/server"; import { callMobileApi } from "@/app/lib/server/mobileApi"; import { getToken } from "@/app/lib/server/session"; import { errorResponse, unauthorized } from "@/app/lib/server/apiRoute"; import type { PaymentMethodView } from "@/app/lib/types"; // GET/POST -> /api/admin/payment-methods (add-payment-method-config, 2a). Forwards the admin JWT // from the bb_admin session cookie. GET is a pure read — side-effect-free so a Next.js prefetch can // never mutate anything (CLAUDE.md rule). POST forwards the body as-is; the BFF sets the location // and acting user server-side and surfaces a validation 422 / 403 verbatim so the page can show the // reason inline and keep the dialog open — never a phantom success. export async function GET(_req: NextRequest) { const token = await getToken(); if (!token) return unauthorized(); const result = await callMobileApi("/api/admin/payment-methods", { token }); if (!result.ok) return errorResponse(result); return NextResponse.json(result.data); } export async function POST(req: NextRequest) { const token = await getToken(); if (!token) return unauthorized(); const body = await req.json().catch(() => ({})); const result = await callMobileApi("/api/admin/payment-methods", { method: "POST", body, token, }); if (!result.ok) return errorResponse(result); return NextResponse.json(result.data); }