fix(payment): resume ezpay orders only after return

This commit is contained in:
2026-06-22 18:23:59 +08:00
parent 27021f9328
commit 2cfbaba058
4 changed files with 64 additions and 9 deletions
+30 -4
View File
@@ -113,10 +113,12 @@ function toPlanView(
export interface SubscriptionScreenProps {
subscriptionType?: SubscriptionType;
shouldResumePendingOrder?: boolean;
}
export function SubscriptionScreen({
subscriptionType = "vip",
shouldResumePendingOrder = false,
}: SubscriptionScreenProps) {
const user = useUserState();
const userDispatch = useUserDispatch();
@@ -139,15 +141,31 @@ export function SubscriptionScreen({
}, [payment.currentOrderId, payment.isPaid, userDispatch]);
useEffect(() => {
if (payment.status !== "ready") return;
const canInspectPendingOrder =
payment.status === "ready" ||
(!shouldResumePendingOrder &&
(payment.isPollingOrder || payment.isPaid || payment.status === "failed"));
if (!canInspectPendingOrder) return;
let cancelled = false;
const resumePendingOrder = async () => {
const handlePendingOrder = async () => {
const result = await PendingPaymentOrderStorage.getPendingOrderForType(
subscriptionType,
);
if (cancelled || !result.success || result.data === null) return;
if (!shouldResumePendingOrder) {
await PendingPaymentOrderStorage.clearPendingOrder();
if (
payment.currentOrderId === result.data.orderId &&
(payment.isPollingOrder || payment.isPaid || payment.status === "failed")
) {
paymentDispatch({ type: "PaymentReset" });
}
return;
}
if (payment.currentOrderId === result.data.orderId) return;
if (resumedPendingOrderRef.current === result.data.orderId) return;
@@ -158,11 +176,19 @@ export function SubscriptionScreen({
});
};
void resumePendingOrder();
void handlePendingOrder();
return () => {
cancelled = true;
};
}, [payment.currentOrderId, payment.status, paymentDispatch, subscriptionType]);
}, [
payment.currentOrderId,
payment.isPaid,
payment.isPollingOrder,
payment.status,
paymentDispatch,
shouldResumePendingOrder,
subscriptionType,
]);
useEffect(() => {
if (!payment.currentOrderId) return;