24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getPaymentConfig, getApiUrlFromRequest } from "@/config/services.config";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const orderId = request.nextUrl.searchParams.get("order_id");
|
|
if (!orderId) {
|
|
return NextResponse.json({ ok: false, error: "缺少 order_id" }, { status: 400 });
|
|
}
|
|
const payConfig = getPaymentConfig();
|
|
const hostHeader = request.headers.get("host") || request.headers.get("x-forwarded-host");
|
|
const envApiUrl = process.env.PAYMENT_API_URL || process.env.NEXT_PUBLIC_API_URL;
|
|
const apiUrl = (envApiUrl ? payConfig.apiUrl : getApiUrlFromRequest(hostHeader)).replace(/\/$/, "");
|
|
try {
|
|
const res = await fetch(
|
|
`${apiUrl}/nomadvip/zpay_order_status?out_trade_no=${encodeURIComponent(orderId)}`,
|
|
{ cache: "no-store" }
|
|
);
|
|
const data = await res.json().catch(() => ({}));
|
|
return NextResponse.json({ ok: true, paid: !!data?.paid });
|
|
} catch (e) {
|
|
return NextResponse.json({ ok: false, paid: false, error: String(e) }, { status: 500 });
|
|
}
|
|
}
|