feat(subscription): load vip and credit plans from api

This commit is contained in:
2026-06-26 15:09:27 +08:00
parent abf6d5ae88
commit 49b67064f7
15 changed files with 748 additions and 50 deletions
@@ -10,6 +10,7 @@ import {
CreatePaymentOrderResponse,
PayChannel,
PaymentOrderStatusResponse,
PaymentPlan,
PaymentPlansResponse,
PaymentVipStatusResponse,
} from "@/data/dto/payment";
@@ -25,6 +26,22 @@ export class PaymentRepository implements IPaymentRepository {
return Result.wrap(() => this.api.getPlans());
}
/** 获取会员套餐列表。 */
async getVipPlans(): Promise<Result<PaymentPlan[]>> {
return Result.wrap(async () => {
const response = await this.api.getPlans();
return response.plans.filter(isVipPaymentPlan);
});
}
/** 获取积分套餐列表。 */
async getCreditPlans(): Promise<Result<PaymentPlan[]>> {
return Result.wrap(async () => {
const response = await this.api.getPlans();
return response.plans.filter(isCreditPaymentPlan);
});
}
/** 创建支付订单。 */
async createOrder(
planId: string,
@@ -54,3 +71,23 @@ export class PaymentRepository implements IPaymentRepository {
/** 全局单例。 */
export const paymentRepository = new PaymentRepository(paymentApi);
export function isVipPaymentPlan(plan: PaymentPlan): boolean {
const orderType = plan.orderType.toLowerCase();
const planId = plan.planId.toLowerCase();
return orderType.startsWith("vip_") || planId.startsWith("vip_");
}
export function isCreditPaymentPlan(plan: PaymentPlan): boolean {
const orderType = plan.orderType.toLowerCase();
const planId = plan.planId.toLowerCase();
return (
plan.dolAmount !== null ||
orderType.startsWith("dol_") ||
orderType.startsWith("credit_") ||
planId.startsWith("dol_") ||
planId.startsWith("credit_") ||
orderType.includes("credit") ||
planId.includes("credit")
);
}