checkout
Complete flight bookings or preview details before purchase. Use confirm=true only with explicit user approval to finalize transactions.
Instructions
Complete the flight booking. IMPORTANT: Set confirm=true only when you have explicit user confirmation to purchase. Without confirm=true, returns a preview of the booking details.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| confirm | No | Set to true to actually complete the purchase. If false or omitted, returns a preview only. NEVER set to true without explicit user confirmation. |
Implementation Reference
- src/browser.ts:1034-1126 (handler)The checkout tool handler function that executes the booking logic. It supports two modes: preview mode (confirm=false) which returns booking details without purchasing, and confirmation mode (confirm=true) which completes the purchase by clicking the purchase button and extracting the confirmation number.
export async function checkout(params: { confirm: boolean }): Promise< | BookingResult | { requiresConfirmation: true; preview: BookingPreview; } > { const { page } = await initBrowser(); if (!params.confirm) { // Return a preview without actually booking const preview = await page.evaluate(() => { const passengers: string[] = []; const passengerEls = document.querySelectorAll( '[class*="passenger"], [data-testid*="passenger"]' ); passengerEls.forEach((el) => passengers.push(el.textContent?.trim() || "") ); const totalPriceEl = document.querySelector( '[class*="total"], [data-testid*="total-price"], .trip-total' ); const totalPrice = totalPriceEl?.textContent?.trim(); return { passengers: passengers.filter(Boolean), totalPrice, }; }); return { requiresConfirmation: true, preview: { ...preview, flights: cachedFlightResults.slice(0, 2).map((f) => ({ flightNumber: f.flightNumber, route: `${f.origin} → ${f.destination}`, date: f.departureTime, cabin: f.cabinClass || "Main Cabin", })), }, }; } // Attempt to complete booking try { // Look for "Purchase" or "Book" button const purchaseBtn = await page.$( 'button:has-text("Purchase"), button:has-text("Book Now"), button:has-text("Complete Purchase"), [data-testid="purchase-btn"]' ); if (!purchaseBtn) { throw new Error( "Could not find purchase button. You may need to complete all booking steps first." ); } await purchaseBtn.click(); await randomDelay(3000, 6000); // Wait for confirmation page await page .waitForSelector('[class*="confirmation"], [data-testid*="confirmation"]', { timeout: 30000, }) .catch(() => {}); // Extract confirmation number const confirmationNumber = await page.evaluate(() => { const confEl = document.querySelector( '[class*="confirmation-number"], [data-testid*="confirmation"], .booking-ref' ); return confEl?.textContent?.trim(); }); // Save updated cookies after booking const { context } = await initBrowser(); await saveCookies(context); return { success: true, confirmationNumber: confirmationNumber || "See your email for confirmation", message: "Booking completed successfully! Check your email for details.", }; } catch (error) { const msg = error instanceof Error ? error.message : String(error); return { success: false, message: `Booking failed: ${msg}`, }; } } - src/browser.ts:104-125 (schema)Type definitions for the checkout tool's return types. BookingResult defines the success/failure response with confirmation details, and BookingPreview defines the preview information shown before confirming purchase.
export interface BookingResult { confirmationNumber?: string; success: boolean; message: string; totalPrice?: string; requiresConfirmation?: boolean; preview?: BookingPreview; } export interface BookingPreview { passengers?: string[]; flights?: Array<{ flightNumber: string; route: string; date: string; cabin: string; }>; seats?: string[]; bags?: string; extras?: string[]; totalPrice?: string; } - src/index.ts:249-262 (registration)Tool registration defining the checkout tool's name, description, and input schema. The schema specifies a 'confirm' boolean parameter that controls whether to preview or complete the booking.
name: "checkout", description: "Complete the flight booking. IMPORTANT: Set confirm=true only when you have explicit user confirmation to purchase. Without confirm=true, returns a preview of the booking details.", inputSchema: { type: "object", properties: { confirm: { type: "boolean", description: "Set to true to actually complete the purchase. If false or omitted, returns a preview only. NEVER set to true without explicit user confirmation.", }, }, }, }, - src/index.ts:658-690 (handler)The request handler that routes checkout tool calls to the checkout function. It extracts the confirm parameter, calls the handler, and formats the response based on whether confirmation is required.
case "checkout": { const { confirm = false } = (args as { confirm?: boolean }) || {}; const result = await checkout({ confirm }); if ("requiresConfirmation" in result) { return { content: [ { type: "text", text: JSON.stringify( { success: true, requiresConfirmation: result.requiresConfirmation, preview: result.preview, note: "Call checkout with confirm=true to complete the purchase. IMPORTANT: Only do this after getting explicit user confirmation.", }, null, 2 ), }, ], }; } return { content: [ { type: "text", text: JSON.stringify( { success: result.success, confirmationNumber: result.confirmationNumber,