feat: YuKassa checkout button on /plans + API route

/plans: кнопка Подключить → fetch /api/billing/checkout → redirect to ЮKassa
app/api/billing/checkout/route.js — прокси к engine
This commit is contained in:
Ник (Claude)
2026-06-11 18:45:32 +03:00
parent 9bd38bc645
commit 18613eee77
2 changed files with 26 additions and 1 deletions
+15
View File
@@ -0,0 +1,15 @@
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) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
try {
const { plan_code } = await req.json();
const data = await engine.call('/api/billing/checkout', {
userId: user.id, method: 'POST', body: { plan_code },
});
return NextResponse.json(data);
} catch (err) { return NextResponse.json({ error: err.message }, { status: 500 }); }
}
+11 -1
View File
@@ -96,7 +96,17 @@ export default function PlansPage() {
<Link href="/register" className={`w-full text-center py-2 rounded-lg text-sm ${style.btnClass}`}>Начать бесплатно</Link>
) : (
<button className={`w-full text-center py-2 text-sm ${style.btnClass}`}
onClick={() => alert('ЮKassa — скоро')}>
onClick={async () => {
try {
const res = await fetch('/api/billing/checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ plan_code: plan.code }),
}).then(r => r.json());
if (res.confirmationUrl) window.location.href = res.confirmationUrl;
else alert(res.error || 'Ошибка создания платежа');
} catch { alert('Ошибка соединения'); }
}}>
Подключить
</button>
)}