2026-05-18 11:12:10 +05:30
|
|
|
import { z } from 'zod';
|
|
|
|
|
|
2026-06-19 16:42:56 +05:30
|
|
|
export const BillingPlanCategorySchema = z.enum(['free', 'starter', 'pro']);
|
|
|
|
|
export type BillingPlanCategory = z.infer<typeof BillingPlanCategorySchema>;
|
|
|
|
|
|
|
|
|
|
export const BillingPlanIdSchema = z.string().min(1);
|
|
|
|
|
export type BillingPlanId = z.infer<typeof BillingPlanIdSchema>;
|
|
|
|
|
|
|
|
|
|
export const BillingCatalogPlanSchema = z.object({
|
|
|
|
|
id: BillingPlanIdSchema,
|
|
|
|
|
category: BillingPlanCategorySchema,
|
|
|
|
|
displayName: z.string(),
|
|
|
|
|
monthlyCredits: z.number(),
|
|
|
|
|
dailyCredits: z.number(),
|
|
|
|
|
monthlyPriceCents: z.number().nullable(),
|
|
|
|
|
archived: z.boolean().optional(),
|
|
|
|
|
});
|
|
|
|
|
export type BillingCatalogPlan = z.infer<typeof BillingCatalogPlanSchema>;
|
|
|
|
|
|
|
|
|
|
export const BillingCatalogSchema = z.object({
|
|
|
|
|
plans: z.array(BillingCatalogPlanSchema),
|
|
|
|
|
});
|
|
|
|
|
export type BillingCatalog = z.infer<typeof BillingCatalogSchema>;
|
2026-05-18 11:12:10 +05:30
|
|
|
|
2026-05-24 12:46:54 +05:30
|
|
|
export const BillingUsageBucketSchema = z.object({
|
|
|
|
|
sanctionedCredits: z.number(),
|
|
|
|
|
usedCredits: z.number(),
|
|
|
|
|
availableCredits: z.number(),
|
|
|
|
|
});
|
|
|
|
|
export type BillingUsageBucket = z.infer<typeof BillingUsageBucketSchema>;
|
|
|
|
|
|
2026-05-18 11:12:10 +05:30
|
|
|
export const BillingInfoSchema = z.object({
|
|
|
|
|
userEmail: z.string().nullable(),
|
|
|
|
|
userId: z.string().nullable(),
|
2026-06-19 16:42:56 +05:30
|
|
|
subscriptionPlanId: BillingPlanIdSchema.nullable(),
|
2026-05-18 11:12:10 +05:30
|
|
|
subscriptionStatus: z.string().nullable(),
|
|
|
|
|
trialExpiresAt: z.string().nullable(),
|
2026-06-19 16:42:56 +05:30
|
|
|
catalog: BillingCatalogSchema,
|
2026-05-24 12:46:54 +05:30
|
|
|
monthly: BillingUsageBucketSchema,
|
|
|
|
|
daily: BillingUsageBucketSchema.extend({
|
|
|
|
|
usageDay: z.string(),
|
|
|
|
|
}),
|
2026-05-18 11:12:10 +05:30
|
|
|
});
|
|
|
|
|
export type BillingInfo = z.infer<typeof BillingInfoSchema>;
|
2026-06-19 16:42:56 +05:30
|
|
|
|
|
|
|
|
export function getBillingPlanData(
|
|
|
|
|
catalog: BillingCatalog,
|
|
|
|
|
planId: string | null | undefined,
|
|
|
|
|
): BillingCatalogPlan | null {
|
|
|
|
|
if (!planId) return null;
|
|
|
|
|
return catalog.plans.find((plan) => plan.id === planId) ?? null;
|
|
|
|
|
}
|