import { NextResponse } from 'next/server'; import { createCheckoutSession } from '@/app/lib/stripe'; export async function POST(req: Request) { try { console.log('Creating checkout session...'); // For now, we'll skip authentication check until Firebase Admin is set up // TODO: Add proper authentication check with Firebase Admin const { boxId, boxName, amount, currency } = await req.json(); console.log('Checkout session request:', { boxId, boxName, amount, currency }); if (!amount || amount <= 0) { console.error('Invalid amount:', amount); return NextResponse.json( { error: 'Invalid amount' }, { status: 400 } ); } if (!boxId || !boxName) { console.error('Missing box information:', { boxId, boxName }); return NextResponse.json( { error: 'Missing box information' }, { status: 400 } ); } console.log('Calling createCheckoutSession with:', { boxId, boxName, amount, currency }); const session = await createCheckoutSession( boxId, boxName, amount, currency, req ); console.log('Checkout session created successfully:', { sessionId: session.id }); return NextResponse.json({ sessionId: session.id, }); } catch (error) { console.error('Error creating checkout session:', error); return NextResponse.json( { error: error instanceof Error ? error.message : 'Error creating checkout session' }, { status: 500 } ); } }