PHP code example of onlinetravelgroup / ean-client

1. Go to this page and download the library: Download onlinetravelgroup/ean-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

onlinetravelgroup / ean-client example snippets



Otg\Ean\HotelClient;

$client = HotelClient::factory([
    'auth' => [
        'cid' => YOUR_CID,
        'apiKey' => YOUR_API_KEY,
        'secret' => YOUR_API_SECRET, // optional, omit if using IP authentication
    ],
    'defaults' => [
        'bookingEndpoint' => 'http://dev.api.ean.com',
        'generalEndpoint' => 'http://dev.api.ean.com',
        'customerIpAddress' => getenv('REMOTE_ADDR'),
        'customerUserAgent' => getenv('HTTP_USER_AGENT'),
    ]
]);

$hotels = $client->getHotelList([
    'destinationString' => 'Montpellier France',
    'arrivalDate' => '2016-06-13',
    'departureDate' => '2016-06-27',
    'RoomGroup' => [
       ['numberOfAdults' => 2]
    ]
]);

$rooms = $client->getRoomAvailability([
    'hotelId' => $hotels['HotelList'][0]['hotelId'],
    'arrivalDate' => '2016-06-13',
    'departureDate' => '2016-06-27',
    'RoomGroup' => [
        ['numberOfAdults' => 2]
    ]
]);

$bedTypes = $rooms['Rooms'][0]['BedTypes'];
$smokingPreferences = explode(',', $rooms['Rooms'][0]['smokingPreferences']);

$reservation = $client->postReservation([
    'RoomGroup' => [[
        'numberOfAdults' => 2,
        'firstName' => 'Test',
        'lastName' => 'Test',
        'bedTypeId' => key($bedTypes),
        'smokingPreference' => $smokingPreferences[0],
    ]],
    'ReservationInfo' => [
        'email' => '[email protected]',
        'firstName' => 'Test',
        'lastName' => 'Test',
        'homePhone' => '0312345678',
        'creditCardType' => 'CA',
        'creditCardNumber' => '5401999999999999',
        'creditCardIdentifier' => '123',
        'creditCardExpirationMonth' => '12',
        'creditCardExpirationYear' => '2099'
    ],
    'AddressInfo' => [
        'address1' => 'travelnow',
        'city' => 'travelnow',
        'stateProvinceCode' => 'VC',
        'countryCode' => 'AU',
        'postalCode' => '3000'
    ],
    'hotelId' => $rooms['hotelId'],
    'arrivalDate' => $rooms['arrivalDate'],
    'departureDate' => $rooms['departureDate'],
    'supplierType' => $rooms['Rooms'][0]['supplierType'],
    'rateKey' => $rooms['Rooms'][0]['RateInfos'][0]['RoomGroup'][0]['rateKey'],
    'roomTypeCode' => isset($rooms['Rooms'][0]['roomTypeCode']) ? $rooms['Rooms'][0]['roomTypeCode'] : $rooms['Rooms'][0]['RoomType']['roomCode'],
    'rateCode' => $rooms['Rooms'][0]['rateCode'],
    'chargeableRate' => $rooms['Rooms'][0]['RateInfos'][0]['ChargeableRateInfo']['total'],
    'currencyCode' => $rooms['Rooms'][0]['RateInfos'][0]['ChargeableRateInfo']['currencyCode']
]);

$result = $client->getRoomCancellation([
    'itineraryId' => $reservation['itineraryId'],
    'email' => '[email protected]',
    'confirmationNumber' => $reservation['confirmationNumbers'][0]
]);

if (isset($result['cancellationNumber'])) {
    printf("Room cancelled: %s", $result['cancellationNumber']);
}