- Módulo billing: suscripción Pro mensual vía /preapproval con credenciales de plataforma por país, webhook firmado y reconciliación por polling. - PlanGuard en los use-cases que crean grupos/alumnos, cobran con MP o activan automatizaciones (402 plan_limit_reached / plan_feature_required / plan_read_only), detrás de BILLING_ENFORCEMENT. - Onboarding: paso Plan obligatorio (POST /onboarding/plan); con Free se saltean Cobros y WhatsApp. - Web: pantalla /billing, aviso de Pro desde el MutationCache. - Migración billing_subscriptions y docs/billing.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
3.4 KiB
TypeScript
77 lines
3.4 KiB
TypeScript
import { z } from 'zod';
|
|
import { planSchema, subscriptionStatusSchema } from './billing.js';
|
|
import { countryCodeSchema, DEFAULT_COUNTRY } from './country.js';
|
|
import { billingTypeSchema, weekdaySchema } from './enums.js';
|
|
import { GroupDtoSchema } from './groups.js';
|
|
|
|
export { countryCodeSchema } from './country.js';
|
|
export type { BillingType, WeekDay } from './enums.js';
|
|
export { billingTypeSchema, weekdaySchema } from './enums.js';
|
|
|
|
// Step 4: create the teacher's first group. Linking Mercado Pago is step 2 and
|
|
// is skippable, so nothing here may require a linked account. The country is
|
|
// stored on the user and drives the currency of the payment links later. It
|
|
// defaults to Argentina because the group form (also used outside onboarding)
|
|
// has no country field: the country lives on the user, not on the group.
|
|
export const CreateFirstGroupSchema = z.strictObject({
|
|
name: z
|
|
.string()
|
|
.trim()
|
|
.min(3, 'El nombre debe tener al menos 3 caracteres')
|
|
.max(60, 'El nombre es demasiado largo (máximo 60 caracteres)'),
|
|
days: z.array(weekdaySchema).min(1, 'Elegí al menos un día de clase'),
|
|
time: z
|
|
.string()
|
|
.regex(/^([01]?\d|2[0-3]):[0-5]\d$/, 'Elegí un horario válido (ej: 09:00)'),
|
|
capacity: z
|
|
.number({ invalid_type_error: 'Ingresá un cupo válido' })
|
|
.int({ message: 'El cupo debe ser un número entero' })
|
|
.min(1, 'El cupo debe ser al menos 1'),
|
|
price: z
|
|
.number({ invalid_type_error: 'Ingresá un precio válido' })
|
|
.min(0, 'El precio no puede ser negativo'),
|
|
billingType: billingTypeSchema,
|
|
dueDay: z
|
|
.number({ invalid_type_error: 'Ingresá un día válido' })
|
|
.int({ message: 'El día debe ser un número entero' })
|
|
.min(1, 'El día de vencimiento debe estar entre 1 y 28')
|
|
.max(28, 'El día de vencimiento debe estar entre 1 y 28'),
|
|
country: countryCodeSchema.default(DEFAULT_COUNTRY),
|
|
});
|
|
export type CreateFirstGroup = z.output<typeof CreateFirstGroupSchema>;
|
|
|
|
export const OnboardingGroupDtoSchema = GroupDtoSchema.extend({
|
|
days: z.array(weekdaySchema).nullable(),
|
|
time: z.string().nullable(),
|
|
capacity: z.number().int().min(1).nullable(),
|
|
price: z.number().min(0).nullable(),
|
|
billingType: billingTypeSchema.nullable(),
|
|
dueDay: z.number().int().min(1).max(28).nullable(),
|
|
});
|
|
export type OnboardingGroupDto = z.output<typeof OnboardingGroupDtoSchema>;
|
|
|
|
export const CreateFirstGroupResultSchema = z.object({
|
|
group: OnboardingGroupDtoSchema,
|
|
onboardingCompleted: z.boolean(),
|
|
});
|
|
export type CreateFirstGroupResult = z.output<typeof CreateFirstGroupResultSchema>;
|
|
|
|
// Onboarding state, to resume the flow if it was interrupted.
|
|
export const onboardingStepSchema = z.enum(['NOT_STARTED', 'PAYMENT_CONNECTED', 'COMPLETED']);
|
|
export type OnboardingStep = z.output<typeof onboardingStepSchema>;
|
|
|
|
export const OnboardingStatusDtoSchema = z.object({
|
|
step: onboardingStepSchema,
|
|
paymentConnected: z.boolean(),
|
|
// WhatsApp is its own skippable step and does not move `step`.
|
|
whatsappConnected: z.boolean(),
|
|
completed: z.boolean(),
|
|
// The "Plan" step is mandatory: these survive the round trip to Mercado Pago
|
|
// and a reload, so the flow resumes where it was.
|
|
planSelected: z.boolean(),
|
|
// PRO as soon as the professor chose it, even while the subscription is PENDING.
|
|
selectedPlan: planSchema.nullable(),
|
|
subscriptionStatus: subscriptionStatusSchema.nullable(),
|
|
country: countryCodeSchema.nullable(),
|
|
});
|
|
export type OnboardingStatusDto = z.output<typeof OnboardingStatusDtoSchema>; |