Php Reference

DynpaX Book 3 - PHP Reference

Qenner provides a PHP Reference implementation for the Book service. The reference implementation provides a full api to all public functionality of the services.

Contents

Interfaces

The reference library provides a object-oriented PHP library. See the BookInterface.php document for the public interface.

All objects are available within the \QennerBook namespace or a sub-namespace thereof. (e.g. use QennerBook\Book;).

Example calls

Below are some simple example of using API objects and functions.

Creating a Book client

It is important to set the x_test flag while testing / developing, to prevent accidental real bookings.

$engine_url = 'https://book.qenner.com';
$api_key = 'Y0UR-API-KEY-000';
$x_test = true;
$log_calls = false;
$locale = 'nl-NL';

$client = new \GuzzleHttp\Client();
$book = new Book($client, $engine_url, $api_key, $x_test, $log_calls, $locale);

Creating a Book Request object

$start_date = '20190814';
$night_count = 7;
$count_adults = 2;
$count_children = 0;
$count_babies = 0;
$accommodation_id = 12344322;
$transport_type = 'Flight';
$board_type = 'LG';
$departure_airport = 'AMS';
$arrival_airport = 'BCN';
$preferred_transport_code = 'KC3828181';
$action_codes = null

$book_request = new BookRequest($start_date, $night_count, $count_adults,
                                $count_children, $count_babies, $accommodation_id,
                                $transport_type, $board_type, $departure_airport,
                                $arrival_airport, $preferred_transport_code, $action_codes);

Creating unit occupation

$accommodation_id = 12344322;
$sequence = 0;
$count_adults = 2;
$count_children = 0;
$count_babies = 0;
$unit_type = null;

$unit_occupation = new UnitOccupation($accommodation_id, $sequence, $count_adults,
                                      $count_children, $count_babies, $unit_type);
$unit_occupations = [$unit_occupation];

Request all bookable units

$session_id = null; //we are starting a new session.
$response = $book->getBookableUnits($book_request, $unit_occupations, $session_id);

$bookable_unit_occupations = $response->getBookableUnitOccupations();

Retrieve a session Id

After your first call you can retrieve a session ID from its response. It is important to reuse the same session ID on subsequent for the same booking.

$session_id = $response->getSessionId();

Retrieve all bookable Transports

$response = $book->getBookableTransports($book_request, $session_id);
$bookable_transports = $response->getBookableTransports();
$package_price_indication = $response->getPackagePriceIndication();
Shorter calls

Note that nullable parameters at the end can be omitted in a function call or a constructor. So a shorter book-request object and bookable units call could also be valid:

//Note by omiting board type and $preferred_transport_code the service will make some choices for, often based on price.
$book_request = new BookRequest($start_date, $night_count, $count_adults,
                                $count_children, $count_babies, $accommodation_id,
                                $transport_type);

//As a session id is initially unknown, so you could do:
$book->getBookableUnits($book_request, $unit_occupations);

PHP Dependencies

The library's only external dependency is GuzzeleHttp, which it expects to be available at the \GuzzeleHttp namespace.

PHP notes

Source version

This reference implementation requires php 8.0, this is currently (November '22) the lowest supported version of php. The source provides strict php type hinting syntax, where possible.

Autoload

An autoload file is provided. If for instance the QennerBook library is placed in a 'vendor' sub-directory of your php document, u can include the following line at the beginning of your file.

require_once __DIR__ . '/vendor/QennerBook/autoload.php';

Drupal

Place the above line at the top of your drupal .module file and everything is set up.

Download

Use the following link to download the QennerBook_011 PHP reference implementation. Checkout the Changes & Updates for the latest changes.