feat(billing): configurable plans from the backoffice and MP payment notifications
Plans: - Plan limits and Pro prices per country live in the database (plan_configs, plan_prices, seeded with the previous constants) and are read through PlanCatalog (30 s cache, defaults as fallback). - /admin/plans edits limits (with the count of accounts that would become read-only) and prices, optionally pushing the new price to live subscriptions from their next charge (MP preapproval amount, Stripe item without proration) via the ApplyPriceChanges job, with an email and a notice on /billing. - GET /billing/plans feeds the onboarding and the billing screen. Mercado Pago: - The Pro checkout returns through GET /billing/return on API_PUBLIC_URL, since MP refuses a back_url on localhost. - The OAuth callback bounces from the tunnel to BETTER_AUTH_URL to find the session, requires the session to own the state, and redirects instead of answering JSON on unexpected errors. - Checkout Pro links skip auto_return off public HTTPS and carry a notification_url to POST /payments/webhooks/mp/:paymentId, which confirms the payment with the owner's token (same rule as the polling job, which stays as fallback). The search now prefers the approved attempt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -114,6 +114,25 @@ describe('admin access', () => {
|
||||
expect(db.user.findUnique).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('forbids the plans to anyone outside the allowlist', async () => {
|
||||
const app = makeApp('profe@gmail.com');
|
||||
expect((await app.request('/admin/plans')).status).toBe(403);
|
||||
expect((await app.request('/admin/plans/FREE/impact?maxGroups=1')).status).toBe(403);
|
||||
const json = { 'Content-Type': 'application/json' };
|
||||
const limits = await app.request('/admin/plans/FREE/limits', {
|
||||
method: 'PUT',
|
||||
headers: json,
|
||||
body: JSON.stringify({ maxGroups: 1, maxAttendees: 1, whatsappAutomations: false, mpCharges: false }),
|
||||
});
|
||||
expect(limits.status).toBe(403);
|
||||
const price = await app.request('/admin/plans/prices/AR', {
|
||||
method: 'PUT',
|
||||
headers: json,
|
||||
body: JSON.stringify({ amount: 1, applyToExisting: true }),
|
||||
});
|
||||
expect(price.status).toBe(403);
|
||||
});
|
||||
|
||||
it('asks for a session without a user', async () => {
|
||||
const response = await makeApp(null).request('/admin/accounts');
|
||||
expect(response.status).toBe(401);
|
||||
|
||||
Reference in New Issue
Block a user