26 lines
1.0 KiB
TypeScript
26 lines
1.0 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { getPaymentConfig } 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 config = getPaymentConfig();
|
|
if (!config.apiUrl) {
|
|
return NextResponse.json({ ok: false, error: "未配置 PAYMENT_API_URL" }, { status: 500 });
|
|
}
|
|
try {
|
|
const controller = new AbortController();
|
|
const timeout = setTimeout(() => controller.abort(), 25000);
|
|
const res = await fetch(
|
|
`${config.apiUrl}/zpay_order_status?out_trade_no=${encodeURIComponent(orderId)}`,
|
|
{ cache: "no-store", signal: controller.signal }
|
|
).finally(() => clearTimeout(timeout));
|
|
const data = await res.json().catch(() => ({}));
|
|
return NextResponse.json({ ok: true, paid: !!data?.paid });
|
|
} catch {
|
|
return NextResponse.json({ ok: true, paid: false });
|
|
}
|
|
}
|