fix(payment): fail order polling after timeout

This commit is contained in:
2026-06-30 10:37:44 +08:00
parent c94c13d863
commit 01a17fbdc9
6 changed files with 142 additions and 7 deletions
@@ -2,10 +2,22 @@ import type { PaymentPlan } from "@/data/dto/payment";
import type { PaymentState } from "./payment-state";
export const MAX_ORDER_POLLING_MS = 5 * 60 * 1000;
export const PAYMENT_TIMEOUT_ERROR_MESSAGE =
"Payment timed out. Please try again.";
export function toPaymentErrorMessage(error: unknown): string {
return error instanceof Error ? error.message : String(error);
}
export function hasOrderPollingTimedOut(
startedAt: number | null,
now = Date.now(),
maxDurationMs = MAX_ORDER_POLLING_MS,
): boolean {
return startedAt !== null && now - startedAt >= maxDurationMs;
}
export function defaultAutoRenewForPlan(
planId: string,
plans: readonly PaymentPlan[] = [],
@@ -34,6 +46,7 @@ export function resetOrderState(): Partial<PaymentState> {
currentOrderId: null,
payParams: null,
orderStatus: null,
orderPollingStartedAt: null,
errorMessage: null,
};
}