import { NextResponse } from 'next/server'; import { supabaseAdmin } from '@/lib/supabase'; export async function POST(req:Request){ const body=await req.json(); const sb=supabaseAdmin(); const items=body.notificationItems || []; for(const item of items){ const n=item.NotificationRequestItem; if(n?.eventCode==='AUTHORISATION' && n?.success==='true'){ await sb.from('orders').update({payment_status:'paid',status:'paid'}).eq('id',n.merchantReference); await fetch(`${process.env.NEXT_PUBLIC_SITE_URL}/api/preview/generate`,{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({orderId:n.merchantReference})}); }} return NextResponse.json({notificationResponse:'[accepted]'}); }