feat(billing): planes Free/Pro con Suscripciones de Mercado Pago
- 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>
This commit is contained in:
27
apps/backend/src/modules/billing/lib/helpers.ts
Normal file
27
apps/backend/src/modules/billing/lib/helpers.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { BillingCharge, BillingSubscription } from '@generated/prisma/client';
|
||||
import type { BillingChargeDto, BillingReturnTo, CountryCode } from '@gruperly/shared';
|
||||
import { countryCodeSchema, DEFAULT_COUNTRY } from '@gruperly/shared';
|
||||
|
||||
export function toBillingChargeDto(charge: BillingCharge): BillingChargeDto {
|
||||
return {
|
||||
id: charge.id,
|
||||
amount: Number(charge.amount.toString()),
|
||||
currency: charge.currency,
|
||||
status: charge.status,
|
||||
paidAt: charge.paidAt?.toISOString() ?? null,
|
||||
createdAt: charge.createdAt.toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
/** The professor's country as stored on the user; Argentina until they pick one. */
|
||||
export function countryOf(user: { country: string | null } | null): CountryCode {
|
||||
const parsed = countryCodeSchema.safeParse(user?.country);
|
||||
return parsed.success ? parsed.data : DEFAULT_COUNTRY;
|
||||
}
|
||||
|
||||
/** Where Mercado Pago sends the professor after authorizing (or abandoning). */
|
||||
export function buildSubscriptionBackUrl(webOrigin: string, returnTo: BillingReturnTo): string {
|
||||
return `${webOrigin}/${returnTo === 'onboarding' ? 'onboarding' : 'billing'}?sub=return`;
|
||||
}
|
||||
|
||||
export type SubscriptionRecord = BillingSubscription;
|
||||
Reference in New Issue
Block a user