feat(payment): sync plans and add coins rules
This commit is contained in:
@@ -3,51 +3,18 @@
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
const PaymentPlanWireSchema = z.object({
|
||||
plan_id: z.string(),
|
||||
plan_name: z.string(),
|
||||
order_type: z.string(),
|
||||
amount_cents: z.number(),
|
||||
original_amount_cents: z.number().nullable().default(null),
|
||||
daily_price_cents: z.number().nullable().default(null),
|
||||
export const PaymentPlanSchema = z.object({
|
||||
planId: z.string(),
|
||||
planName: z.string(),
|
||||
orderType: z.string(),
|
||||
vipDays: z.number().nullable(),
|
||||
dolAmount: z.number().nullable(),
|
||||
creditBalance: z.number(),
|
||||
amountCents: z.number(),
|
||||
originalAmountCents: z.number().nullable().default(null),
|
||||
dailyPriceCents: z.number().nullable().default(null),
|
||||
currency: z.string(),
|
||||
pricing_tier: z.string(),
|
||||
vip_days: z.number().nullable(),
|
||||
dol_amount: z.number().nullable(),
|
||||
});
|
||||
|
||||
export const PaymentPlanSchema = z
|
||||
.preprocess((value) => {
|
||||
if (!value || typeof value !== "object") return value;
|
||||
const data = value as Record<string, unknown>;
|
||||
if ("planId" in data) {
|
||||
return {
|
||||
plan_id: data.planId,
|
||||
plan_name: data.planName,
|
||||
order_type: data.orderType,
|
||||
amount_cents: data.amountCents,
|
||||
original_amount_cents: data.originalAmountCents,
|
||||
daily_price_cents: data.dailyPriceCents,
|
||||
currency: data.currency,
|
||||
pricing_tier: data.pricingTier,
|
||||
vip_days: data.vipDays,
|
||||
dol_amount: data.dolAmount,
|
||||
};
|
||||
}
|
||||
return value;
|
||||
}, PaymentPlanWireSchema)
|
||||
.transform((data) => ({
|
||||
planId: data.plan_id,
|
||||
planName: data.plan_name,
|
||||
orderType: data.order_type,
|
||||
amountCents: data.amount_cents,
|
||||
originalAmountCents: data.original_amount_cents,
|
||||
dailyPriceCents: data.daily_price_cents,
|
||||
currency: data.currency,
|
||||
pricingTier: data.pricing_tier,
|
||||
vipDays: data.vip_days,
|
||||
dolAmount: data.dol_amount,
|
||||
}));
|
||||
|
||||
export type PaymentPlanInput = z.input<typeof PaymentPlanSchema>;
|
||||
export type PaymentPlanData = z.output<typeof PaymentPlanSchema>;
|
||||
|
||||
Reference in New Issue
Block a user