feat(payment): restore ezpay return orders

This commit is contained in:
2026-06-22 17:29:47 +08:00
parent 890c955712
commit 21b9954351
14 changed files with 1083 additions and 1 deletions
+1
View File
@@ -18,5 +18,6 @@ export * from "./chat/ichat_storage";
export * from "./chat/local_chat_db";
export * from "./chat/local_chat_storage";
export * from "./chat/local_message";
export * from "./payment/pending_payment_order_storage";
export * from "./user/iuser_storage";
export * from "./user/user_storage";
+5
View File
@@ -0,0 +1,5 @@
/**
* @file Payment storage barrel.
*/
export * from "./pending_payment_order_storage";
@@ -0,0 +1,52 @@
"use client";
import { z } from "zod";
import { Result, type Result as ResultT, SpAsyncUtil } from "@/utils";
import { StorageKeys } from "../storage_keys";
const PendingPaymentOrderSchema = z.object({
orderId: z.string().min(1),
payChannel: z.literal("ezpay"),
subscriptionType: z.enum(["vip", "voice"]),
createdAt: z.number(),
});
export type PendingPaymentOrder = z.output<typeof PendingPaymentOrderSchema>;
export class PendingPaymentOrderStorage {
private constructor() {}
static setPendingOrder(
order: PendingPaymentOrder,
): Promise<ResultT<void>> {
return SpAsyncUtil.setJson(
StorageKeys.pendingPaymentOrder,
order,
PendingPaymentOrderSchema,
);
}
static getPendingOrder(): Promise<ResultT<PendingPaymentOrder | null>> {
return SpAsyncUtil.getJson(
StorageKeys.pendingPaymentOrder,
PendingPaymentOrderSchema,
);
}
static async getPendingOrderForType(
subscriptionType: PendingPaymentOrder["subscriptionType"],
): Promise<ResultT<PendingPaymentOrder | null>> {
const result = await PendingPaymentOrderStorage.getPendingOrder();
if (Result.isErr(result)) return result;
if (result.data?.subscriptionType !== subscriptionType) {
return Result.ok(null);
}
return result;
}
static clearPendingOrder(): Promise<ResultT<void>> {
return SpAsyncUtil.remove(StorageKeys.pendingPaymentOrder);
}
}
+3
View File
@@ -29,6 +29,9 @@ export const StorageKeys = {
lastExternalBrowserDialogShown: "last_external_browser_dialog_shown",
lastPwaEventReported: "last_pwa_event_reported",
lastAppInfoReported: "last_app_info_reported",
// payment
pendingPaymentOrder: "pending_payment_order",
} as const;
export type StorageKey = (typeof StorageKeys)[keyof typeof StorageKeys];