fix(payment): fail order polling after timeout
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user