feat(payment): restore ezpay return orders
This commit is contained in:
@@ -20,6 +20,7 @@ import { Checkbox, MobileShell } from "@/app/_components/core";
|
||||
import { AppConstants } from "@/core/app_constants";
|
||||
import type { PaymentPlan } from "@/data/dto/payment";
|
||||
import { VIP_BENEFITS } from "@/data/constants/vip-benefits";
|
||||
import { PendingPaymentOrderStorage } from "@/data/storage";
|
||||
import {
|
||||
usePaymentDispatch,
|
||||
usePaymentState,
|
||||
@@ -122,6 +123,7 @@ export function SubscriptionScreen({
|
||||
const payment = usePaymentState();
|
||||
const paymentDispatch = usePaymentDispatch();
|
||||
const refreshedPaidOrderRef = useRef<string | null>(null);
|
||||
const resumedPendingOrderRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (payment.status === "idle") {
|
||||
@@ -136,6 +138,39 @@ export function SubscriptionScreen({
|
||||
userDispatch({ type: "UserFetch" });
|
||||
}, [payment.currentOrderId, payment.isPaid, userDispatch]);
|
||||
|
||||
useEffect(() => {
|
||||
if (payment.status !== "ready") return;
|
||||
|
||||
let cancelled = false;
|
||||
|
||||
const resumePendingOrder = async () => {
|
||||
const result = await PendingPaymentOrderStorage.getPendingOrderForType(
|
||||
subscriptionType,
|
||||
);
|
||||
if (cancelled || !result.success || result.data === null) return;
|
||||
if (payment.currentOrderId === result.data.orderId) return;
|
||||
if (resumedPendingOrderRef.current === result.data.orderId) return;
|
||||
|
||||
resumedPendingOrderRef.current = result.data.orderId;
|
||||
paymentDispatch({
|
||||
type: "PaymentReturned",
|
||||
orderId: result.data.orderId,
|
||||
});
|
||||
};
|
||||
|
||||
void resumePendingOrder();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [payment.currentOrderId, payment.status, paymentDispatch, subscriptionType]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!payment.currentOrderId) return;
|
||||
if (!payment.isPaid && payment.status !== "failed") return;
|
||||
|
||||
void PendingPaymentOrderStorage.clearPendingOrder();
|
||||
}, [payment.currentOrderId, payment.isPaid, payment.status]);
|
||||
|
||||
const plans = useMemo(
|
||||
() =>
|
||||
payment.plans
|
||||
@@ -274,6 +309,7 @@ export function SubscriptionScreen({
|
||||
) : (
|
||||
<SubscriptionCheckoutButton
|
||||
disabled={!canActivate}
|
||||
subscriptionType={subscriptionType}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user