import { NextRequest, NextResponse } from 'next/server'; import { db } from '@/lib/db'; export async function GET( req: NextRequest, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const result = await db.query('SELECT * FROM merchants WHERE id = $1 LIMIT 1', [id]); const data = result.rows[0]; if (!data) { return NextResponse.json({ error: 'Merchant not found' }, { status: 404 }); } return NextResponse.json(data); } catch (err: any) { return NextResponse.json( { error: `Internal Server Error: ${err.message}` }, { status: 500 } ); } } export async function PATCH( req: NextRequest, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; const { name, webhook_url, payment_provider, provider_config, fee_percent } = await req.json(); if (!name) { return NextResponse.json( { error: 'Firma adı zorunludur.' }, { status: 400 } ); } const result = await db.query( 'UPDATE merchants SET name = $1, webhook_url = $2, payment_provider = $3, provider_config = $4, fee_percent = $5 WHERE id = $6 RETURNING *', [name, webhook_url, payment_provider, provider_config, fee_percent || 1.0, id] ); const data = result.rows[0]; if (!data) { return NextResponse.json({ error: 'Update failed or merchant not found' }, { status: 500 }); } return NextResponse.json(data); } catch (err: any) { return NextResponse.json( { error: `Internal Server Error: ${err.message}` }, { status: 500 } ); } } export async function DELETE( req: NextRequest, context: { params: Promise<{ id: string }> } ) { try { const { id } = await context.params; await db.query('DELETE FROM merchants WHERE id = $1', [id]); return NextResponse.json({ success: true }); } catch (err: any) { return NextResponse.json( { error: `Internal Server Error: ${err.message}` }, { status: 500 } ); } }