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:
@@ -16,6 +16,7 @@ import {
|
||||
} from '@/http/problem-builders';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { logger } from '@/logger';
|
||||
import { PlanGuard } from '@/modules/billing/lib/entitlements';
|
||||
import { getMpAccessToken } from '@/modules/mp';
|
||||
import { createCheckoutPreference, getWebOrigin, MpApiError } from '@/modules/mp/lib';
|
||||
|
||||
@@ -24,6 +25,7 @@ type BatchDeps = {
|
||||
createPreference?: typeof createCheckoutPreference;
|
||||
getToken?: typeof getMpAccessToken;
|
||||
webOrigin?: string;
|
||||
planGuard?: Pick<PlanGuard, 'requireFeature'>;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -60,6 +62,14 @@ export class CreatePaymentBatch {
|
||||
return err(noGroupAccessProblem());
|
||||
}
|
||||
|
||||
const allowed = await (this.deps.planGuard ?? new PlanGuard()).requireFeature(
|
||||
group.createdById,
|
||||
'mpCharges',
|
||||
);
|
||||
if (!allowed.ok) {
|
||||
return allowed;
|
||||
}
|
||||
|
||||
if (group.price == null) {
|
||||
return err(groupWithoutPriceProblem());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user