This commit is contained in:
eric
2026-03-13 05:14:28 -05:00
parent f66859c032
commit 8a095f7d45
13 changed files with 820 additions and 132 deletions

View File

@@ -4,13 +4,11 @@ import { useState, useRef, useEffect, type FormEvent, type ChangeEvent } from "r
import { Link } from "@/i18n/navigation";
import {
getPayEnv,
getRecommendedChannel,
mustUseWxPay,
redirectToPay,
getDeviceFromEnv,
} from "@/app/lib/payment";
import { usePayStatusPoll } from "@/app/lib/payment/usePayStatusPoll";
import type { PayChannel, PayEnv } from "@/app/lib/payment";
import type { PayEnv } from "@/app/lib/payment";
import AuthModal from "@/app/components/AuthModal";
const genderOptions = ["男", "女"];
@@ -57,7 +55,6 @@ export default function JoinPage() {
const [error, setError] = useState<string | null>(null);
const [payRedirecting, setPayRedirecting] = useState(false);
const [payEnv, setPayEnv] = useState<PayEnv | null>(null);
const [payChannel, setPayChannel] = useState<PayChannel>("wxpay");
const [authOpen, setAuthOpen] = useState(false);
const [pendingSubmit, setPendingSubmit] = useState(false);
const [isAlreadyRecorded, setIsAlreadyRecorded] = useState(false);
@@ -97,9 +94,7 @@ export default function JoinPage() {
useEffect(() => {
if (typeof window === "undefined") return;
const env = getPayEnv();
setPayEnv(env);
setPayChannel(getRecommendedChannel(env));
setPayEnv(getPayEnv());
}, []);
const set = (key: keyof FormData, value: string) =>
@@ -137,7 +132,7 @@ export default function JoinPage() {
setPayRedirecting(true);
const returnUrl = `${window.location.origin}${window.location.pathname}/paid`;
const env = getPayEnv();
const channel = mustUseWxPay(env) ? "wxpay" : payChannel;
const channel = "wxpay";
const device = getDeviceFromEnv(env);
redirectToPay({
user_id: userId,

View File

@@ -5,6 +5,13 @@ import { Link } from "@/i18n/navigation";
const DEFAULT_PASSWORD = "12345678";
function clearPendingOrder(): void {
try {
localStorage.removeItem("join_pay_order");
} catch {}
document.cookie = "join_pay_order=; path=/; max-age=0";
}
/**
* 支付完成回跳页
* Z-Pay 的 return_url 不支持带查询参数,故使用 /join/paid 作为专用成功页
@@ -60,9 +67,17 @@ export default function JoinPaidPage() {
const run = async () => {
const cookie = document.cookie.split(";").find((c) => c.trim().startsWith("join_pay_order="));
const rawValue = cookie?.split("=")[1]?.trim();
const decoded = rawValue ? decodeURIComponent(rawValue) : "";
const storageValue = (() => {
try {
return localStorage.getItem("join_pay_order") || "";
} catch {
return "";
}
})();
const decoded = rawValue ? decodeURIComponent(rawValue) : storageValue;
const orderId = decoded.split("|")[0]?.trim() || "";
if (!orderId) {
clearPendingOrder();
window.location.replace(`/${window.location.pathname.split("/")[1] || "zh"}/join`);
return;
}
@@ -75,7 +90,7 @@ export default function JoinPaidPage() {
try {
const result = await tryComplete(orderId);
if (result.ok) {
document.cookie = "join_pay_order=; path=/; max-age=0";
clearPendingOrder();
if (!cancelled) setCompleteStatus("success");
return;
}