30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import { createBookingCheckout } from '@/lib/payments';
|
|
|
|
export async function POST(request: Request) {
|
|
const body = (await request.json()) as Record<string, unknown>;
|
|
|
|
try {
|
|
const result = await createBookingCheckout({
|
|
propertySlug: String(body.propertySlug || ''),
|
|
arrivalDate: body.arrivalDate ? String(body.arrivalDate) : undefined,
|
|
departureDate: body.departureDate ? String(body.departureDate) : undefined,
|
|
adults: Number(body.adults ?? 2),
|
|
children: Number(body.children ?? 0),
|
|
pets: Number(body.pets ?? 0),
|
|
location: body.location ? String(body.location) : undefined,
|
|
firstName: String(body.firstName || ''),
|
|
lastName: String(body.lastName || ''),
|
|
email: String(body.email || ''),
|
|
phone: body.phone ? String(body.phone) : undefined,
|
|
specialRequests: body.specialRequests ? String(body.specialRequests) : undefined,
|
|
termsAccepted: Boolean(body.termsAccepted),
|
|
});
|
|
|
|
return NextResponse.json({ ok: true, ...result });
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : 'Checkout failed';
|
|
return NextResponse.json({ ok: false, error: message }, { status: 400 });
|
|
}
|
|
}
|