HEX
Server: Apache
System: Linux 136-243-153-58.cprapid.com 4.18.0-553.81.1.el8_10.x86_64 #1 SMP Mon Oct 27 11:29:19 EDT 2025 x86_64
User: mytest (1001)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/mytest/.trash/test-bm-api.php.34
<?php
/**
 * Test script to verify Booking Manager API is working correctly
 * This tests that we can get data and prices for all 3 yachts
 */

require_once __DIR__ . '/database/Database.php';
require_once __DIR__ . '/api/services/BookingManagerService.php';

echo "=== Booking Manager API Test ===\n\n";

$bmService = new BookingManagerService();

$dateFrom = date('Y-m-d', strtotime('+7 days')) . 'T00:00:00';
$dateTo = date('Y-m-d', strtotime('+14 days')) . 'T23:59:59';

echo "Testing with dates: $dateFrom to $dateTo\n\n";

echo "Test 1: Get all offers (no filters)\n";
echo "-----------------------------------\n";
$allOffers = $bmService->getOffers([
    'dateFrom' => $dateFrom,
    'dateTo' => $dateTo
]);

if (isset($allOffers['error'])) {
    echo "ERROR: " . $allOffers['error'] . "\n";
    if (isset($allOffers['code'])) {
        echo "HTTP Code: " . $allOffers['code'] . "\n";
    }
    if (isset($allOffers['response'])) {
        echo "Response: " . substr($allOffers['response'], 0, 500) . "\n";
    }
} else {
    echo "Success! Got " . count($allOffers) . " offers\n";
    if (count($allOffers) > 0) {
        $sample = $allOffers[0];
        echo "Sample offer:\n";
        echo "  Yacht ID: " . ($sample['yachtId'] ?? 'N/A') . "\n";
        echo "  Yacht Name: " . ($sample['yacht']['name'] ?? 'N/A') . "\n";
        echo "  Yacht Model: " . ($sample['yacht']['model'] ?? 'N/A') . "\n";
        echo "  Price: " . ($sample['price'] ?? 'N/A') . "\n";
        echo "  Total Price: " . ($sample['totalPrice'] ?? 'N/A') . "\n";
        echo "  Currency: " . ($sample['currency'] ?? 'N/A') . "\n";
    }
}
echo "\n";

echo "Test 2: Get offers for each yacht individually\n";
echo "-----------------------------------------------\n";
$yachtIds = [
    '6362109340000107850' => 'Lemon (Sun Odyssey 469)',
    '7208135200000107850' => 'Aquilo (Bavaria Cruiser 46)',
    '7136018700000107850' => 'Strawberry (Lagoon 440)'
];

foreach ($yachtIds as $yachtId => $yachtName) {
    echo "\nTesting $yachtName (ID: $yachtId):\n";
    
    $yachtDetails = $bmService->getYacht($yachtId);
    if (isset($yachtDetails['error'])) {
        echo "  ERROR getting yacht details: " . $yachtDetails['error'] . "\n";
        if (isset($yachtDetails['code'])) {
            echo "  HTTP Code: " . $yachtDetails['code'] . "\n";
        }
    } else {
        echo "  ✓ Got yacht details\n";
        echo "    Name: " . ($yachtDetails['name'] ?? 'N/A') . "\n";
        echo "    Model: " . ($yachtDetails['model'] ?? 'N/A') . "\n";
        echo "    Cabins: " . ($yachtDetails['cabins'] ?? 'N/A') . "\n";
        echo "    Length: " . ($yachtDetails['LOA'] ?? 'N/A') . "m\n";
    }
    
    $offers = $bmService->getOffers([
        'yachtId' => $yachtId,
        'dateFrom' => $dateFrom,
        'dateTo' => $dateTo
    ]);
    
    if (isset($offers['error'])) {
        echo "  ERROR getting offers: " . $offers['error'] . "\n";
        if (isset($offers['code'])) {
            echo "  HTTP Code: " . $offers['code'] . "\n";
        }
    } else {
        echo "  ✓ Got " . count($offers) . " offers\n";
        if (count($offers) > 0) {
            $offer = $offers[0];
            echo "    Price: " . ($offer['price'] ?? 'N/A') . " " . ($offer['currency'] ?? '') . "\n";
            echo "    Total Price: " . ($offer['totalPrice'] ?? 'N/A') . " " . ($offer['currency'] ?? '') . "\n";
        } else {
            echo "    No offers available for these dates\n";
        }
    }
}

echo "\n=== Test Complete ===\n";
?>