feat(payment): restore ezpay return orders
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user