nomadro/app/book/api/pay/invoice/route.ts
eric 9928c5185b Mount nav/book/community as native App Router routes in one Next process.
Replace reverse-proxy/iframe approach with @ebook/@community/@navmini imports under /nav /book /community so localhost:3000 serves all three products directly.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-28 03:49:16 -05:00

28 lines
966 B
TypeScript

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 });
}
}