import { NextResponse } from 'next/server'; import { prisma } from '@/lib/prisma'; export async function POST(request: Request) { try { const { paymentIntentId, imageData } = await request.json(); // Validate paymentIntentId format if (!paymentIntentId || typeof paymentIntentId !== 'string' || !paymentIntentId.startsWith('pi_')) { return NextResponse.json({ error: 'Invalid paymentIntentId' }, { status: 400 }); } if (!imageData || typeof imageData !== 'string') { return NextResponse.json({ error: 'Invalid imageData' }, { status: 400 }); } // Only accept data URLs (JPEG or PNG) if (!imageData.startsWith('data:image/jpeg;base64,') && !imageData.startsWith('data:image/png;base64,')) { return NextResponse.json({ error: 'Invalid image format' }, { status: 400 }); } await prisma.snapshot.upsert({ where: { paymentIntentId }, create: { paymentIntentId, imageData }, update: { imageData }, }); return NextResponse.json({ success: true }); } catch (err) { const message = err instanceof Error ? err.message : 'Internal server error'; return NextResponse.json({ error: message }, { status: 500 }); } }