1import { FerryClient } from "@ferryvn/sdk";
2const ferry = new FerryClient({ apiKey: process.env.FERRY_API_KEY });
3
4// Tên bến có dấu hay không dấu đều được
5const [from] = await ferry.locations.find("Rạch Giá");
6const [to] = await ferry.locations.find("phu quoc");
7const { data } = await ferry.voyages.search({
8 date, departureId: from.id, destinationId: to.id,
9});
10
11// Chọn loại vé theo tuổi, khớp giá, kiểm ghế trống trước khi gửi
12const { booking, draft } = await ferry.bookingDrafts.create({
13 customerId, ordererName, contactEmail,
14 depart: { voyageId: data[0].voyage.id, seats: ["A1"], passengers },
15});
16
17// Trừ số dư, đặt vé với hãng; đọc lại trạng thái chuẩn
18await ferry.bookings.confirmToIssue(booking.id);
19const { booking_status } = await ferry.bookings.get(booking.id);