import { NextResponse } from "next/server"; import { requireAdminSession } from "~/lib/admin-auth"; import { PAY_DEFAULTS } from "@nomadro/pay"; /** Aggregate recent orders from payjsapi when available; otherwise return matrix stubs. */ export async function GET() { if (!(await requireAdminSession())) { return NextResponse.json({ ok: false, error: "unauthorized" }, { status: 401 }); } const apiBase = ( process.env.NEXT_PUBLIC_PAYJSAPI_URL || process.env.PAYJSAPI_URL || PAY_DEFAULTS.payjsapiPublic ).replace(/\/$/, ""); const channels = [ { id: "zpay", region: "cn", note: "国内 PC/H5" }, { id: "xorpay", region: "cn", note: "微信内 H5 (xpay)" }, { id: "creem", region: "overseas", note: "海外卡支付" }, { id: "nowpayments", region: "overseas", note: "加密货币" }, { id: "wx_virtual", region: "cn", note: "微信小程序虚拟支付" }, ]; let upstream: { ok: boolean; detail?: string } = { ok: false }; try { const res = await fetch(`${apiBase}/health`, { cache: "no-store" }); upstream = { ok: res.ok, detail: `HTTP ${res.status}` }; } catch (e) { upstream = { ok: false, detail: e instanceof Error ? e.message : String(e) }; } return NextResponse.json({ ok: true, apiBase, upstream, channels, items: [], note: "订单明细来自各垂直 + payjsapi;此处先给渠道矩阵与网关探活。电子书订单见 /book/admin。", }); }