import { NextResponse } from 'next/server'; import { createSupportInvoice, isAllowedSupportAmount, isNowPaymentsConfigured, } from '@ebook/lib/nowpayments'; export async function POST(req: Request) { if (!isNowPaymentsConfigured()) { return NextResponse.json({ ok: false, error: 'payments not configured' }, { status: 503 }); } try { const body = (await req.json()) as { amount?: number }; const amount = Number(body.amount); if (!isAllowedSupportAmount(amount)) { return NextResponse.json({ ok: false, error: 'invalid amount' }, { status: 400 }); } const invoice = await createSupportInvoice(amount); return NextResponse.json({ ok: true, invoiceUrl: invoice.invoiceUrl }); } catch (error) { const message = error instanceof Error ? error.message : 'invoice failed'; console.error('NOWPayments invoice', message); return NextResponse.json({ ok: false, error: 'invoice failed' }, { status: 502 }); } }