Add booking checkout and webhook flow
This commit is contained in:
29
src/app/api/bookings/checkout/route.ts
Normal file
29
src/app/api/bookings/checkout/route.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user