This commit is contained in:
eric
2026-03-10 08:46:58 -05:00
parent 9b4467d4f7
commit 6f6f0fa527
3 changed files with 109 additions and 10 deletions

View File

@@ -121,6 +121,7 @@ export async function POST(request: NextRequest) {
const reqProvider = String(body?.provider || "").trim().toLowerCase() || undefined;
const accept = request.headers.get("accept") || "";
const wantHtml = String(body?.html) === "1" || accept.includes("text/html");
const preferJson = String(body?.prefer_json) === "1";
if (!user_id) {
if (wantHtml) {
@@ -218,10 +219,18 @@ export async function POST(request: NextRequest) {
if (redirectRes.status >= 301 && redirectRes.status <= 308) {
const location = redirectRes.headers.get("location");
if (location) {
const res = NextResponse.redirect(location);
const orderId =
redirectRes.headers.get("x-pay-order-id")?.trim() ||
String(params?.out_trade_no || "").trim();
if (preferJson && orderId) {
return NextResponse.json({
ok: true,
order_id: orderId,
redirect_url: location,
provider: "zpay",
});
}
const res = NextResponse.redirect(location);
if (orderId) setPayOrderCookie(res, orderId);
return res;
}