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:
24
apps/backend/src/modules/billing/jobs/schedule.ts
Normal file
24
apps/backend/src/modules/billing/jobs/schedule.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { logger } from '@/logger';
|
||||
import { ReconcileSubscriptions } from './reconcile-subscriptions';
|
||||
|
||||
const RECONCILE_CRON = '*/30 * * * *';
|
||||
|
||||
/**
|
||||
* Registers the billing background jobs. Called once from `server.ts`, with the
|
||||
* same guards as `startPaymentJobs`: a rejected promise inside Bun's cron would
|
||||
* crash the process, and `unref` keeps the job from holding it alive.
|
||||
*/
|
||||
export function startBillingJobs(): void {
|
||||
Bun.cron(
|
||||
RECONCILE_CRON,
|
||||
async () => {
|
||||
try {
|
||||
const totals = await new ReconcileSubscriptions().execute();
|
||||
logger.info(totals, 'Pro subscriptions reconciliation finished');
|
||||
} catch (error) {
|
||||
logger.error({ err: error }, 'Pro subscriptions reconciliation failed');
|
||||
}
|
||||
},
|
||||
{ tz: 'UTC' },
|
||||
).unref();
|
||||
}
|
||||
Reference in New Issue
Block a user