feat: billing complete — plans page, admin billing, credit cost hints

/plans: страница тарифов с карточками, стоимостью операций, FAQ
/system → Биллинг: таблица пользователей с кредитами, ручное начисление
ChannelView: badge стоимости (2кр текст + 5кр картинка) под кнопкой генерации
  Ошибка INSUFFICIENT_CREDITS → понятное сообщение
  После генерации — event credits-updated → обновление badge в header
Header: подписка на credits-updated event
API роуты: /api/billing/plans, /api/billing/admin/users, /api/billing/admin/credit
This commit is contained in:
Ник (Claude)
2026-06-11 18:42:54 +03:00
parent 1cce478f27
commit 9bd38bc645
8 changed files with 380 additions and 10 deletions
+13
View File
@@ -0,0 +1,13 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
import { engine } from '@/lib/engine';
export async function POST(req) {
const user = await requireUser();
if (!user?.isAdmin) return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
try {
const body = await req.json();
const data = await engine.adminCreditUser(body);
return NextResponse.json(data);
} catch (err) { return NextResponse.json({ error: err.message }, { status: 500 }); }
}
+12
View File
@@ -0,0 +1,12 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
import { engine } from '@/lib/engine';
export async function GET() {
const user = await requireUser();
if (!user?.isAdmin) return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
try {
const data = await engine.adminGetBalances();
return NextResponse.json(data);
} catch (err) { return NextResponse.json({ error: err.message }, { status: 500 }); }
}
+17
View File
@@ -0,0 +1,17 @@
import { NextResponse } from 'next/server';
const ENGINE_URL = process.env.ENGINE_URL || 'http://localhost:3030';
const ENGINE_SECRET = process.env.ENGINE_SECRET || '';
export async function GET() {
try {
const res = await fetch(`${ENGINE_URL}/api/billing/plans`, {
headers: { 'x-internal-secret': ENGINE_SECRET },
cache: 'no-store',
});
const data = await res.json();
return NextResponse.json(data);
} catch (err) {
return NextResponse.json({ error: err.message }, { status: 500 });
}
}