"use client"; /** * 订阅成功回跳页 * * 流程: * 1. 用户在支付服务托管页完成结账 * 2. 支付服务重定向到 `/subscription/success` * 3. 这个页面显示 "购买成功" + 调 VIP 状态接口确认权益 * 4. 点 "返回订阅页" 跳回 `/subscription` * * 注意:权益发放由后端支付服务链路异步完成。 * 此页面轮询几次 VIP 状态接口等待权益完成更新。 */ import { useEffect, useRef, useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { MobileShell } from "@/app/_components/core/mobile-shell"; import { getPaymentRepository } from "@/data/repositories/payment_repository"; import { ROUTES } from "@/router/routes"; export default function SubscriptionSuccessPage() { const router = useRouter(); const [status, setStatus] = useState<"polling" | "ok" | "error">("polling"); const [errorMessage, setErrorMessage] = useState(null); const hasRefreshed = useRef(false); // 轮询 VIP 状态接口等待后端权益发放完成 useEffect(() => { if (hasRefreshed.current) return; hasRefreshed.current = true; let cancelled = false; const tryRefresh = async (attemptsLeft: number) => { if (cancelled) return; const r = await getPaymentRepository().getVipStatus(); if (cancelled) return; if (r.success) { if (r.data.isVip) { setStatus("ok"); return; } } else { setErrorMessage(r.error?.message ?? "Unknown error"); } if (attemptsLeft > 0) { setTimeout(() => void tryRefresh(attemptsLeft - 1), 2000); } else { setStatus("error"); } }; void tryRefresh(5); return () => { cancelled = true; }; }, []); return (
{status === "polling" ? ( <>

Processing your subscription…

Your payment was received. We are confirming the details with our server.

) : status === "ok" ? ( <>

🎉 Subscription activated!

Welcome to VIP. Enjoy unlimited chat and more premium benefits.

Back to subscription ) : ( <>

Subscription status unclear

We received your payment but could not confirm your VIP status. {errorMessage ?? "Please refresh in a few seconds."}

Back to subscription )}
); }