This SDK is used to connect to the hotelbook and use it methods for a 3-d party API.
composer require tmconsulting/hotelbook-php-sdk
First of all, you will need to have credentials for the hotelbook.
The config with credentials looks like this.
$config = [
'url' => 'https://hotelbook.pro/xml',
'login' => 'YOUR LOGIN',
'password' => 'YOUR PASSSWORD'
];
(if yoy pass anything not valid, it throws an exception while creating the main instance)
After that, include the library and create an basic instance of it.
//Require vendor
require __DIR__ . "/../vendor/autoload.php";
//Use main hotelbook class
use App\Hotelbook\Main;
//Create an instance of main class
$hotelbook = new Main($config);
Now you can use all the methods of the hotelbook sdk. For example:
E.g search for hotels:
use Carbon\Carbon;
$from = Carbon::parse('08-07-2018');
$till = Carbon::parse('09-07-2018');
$result = $hotelbook->search(1, $from, $till, [new SearchPassenger(1, [2])]);
Now the result will be an instance of ResultProceeder with all of the results
If method has an error, it throws an exception that you can handle and than run getErrors the result.
try {
$result = $main->book(...someArguments);
} catch (Exception $e)
{
//Do something with the exception
}
Every method returns an object (if it doesn't throw an exception), that has to methods:
- getItems()
- getErrors()
getItems
method returns all of the items returned from the method.
getErrors
method return all of the errors returned from hotelbook.
So that you can do something like:
//$result is a result of search request
if (!empty($result->getErrors()) {
//Handle error
}
$items = $result->getItems();
//Do something with items.
All static data API $methods are available through $main->{$YOUR_METHOD_NAME}
.
It gives an object with results (items, errors). (Described above.)
To use any of methods, you have to create an instance of HotelBook SDK. Described here
Currently available methods:
- Search (Search for hotels)
- Async Search (Search for hotels in Asynchronous mode )
- Detail (Hotel Details)
- Book Order (Book a Hotel)
- Cancel Order (Cancel booking)
- Confirm Order (Confirm booking )
- Annulate Order (Cancel booking after confirm)
And methods to fetch dictionaries.
- Country - (Fetch all available countries)
- City - (Fetch all available Cities)
- Location - (Fetch all available Locations)
- Resort - (Fetch all available Resorts)
- HotelType - (Fetch all available Hotel Types)
- HotelCategory - (Fetch all available Hotel Categories)
- HotelFacility - (Fetch all available Hotel Facilities)
- HotelList- (Fetch all available Hotel Lists)
- Meal - (Fetch all available Meal Types)
- MealBreakfast - (Fetch all available Meal Breakfast Types)
- RoomSize - (Fetch all available Room Sizes)
- RoomType - (Fetch all available Room Types)
- RoomAmenity - (Fetch all available Room Amenities)
- RoomView - (Fetch all available Room Views)
- CurrencyRate - (Fetch currancy rates)
Fetch countries method is used to fetch all of the countries exist in the hotelbook database. So you can use it as a search parameter, etc...
//You already have an instance of SDK, and it's stored in $main
$countries = $main->country();
//Now, in countries, you have a simple result.
$countiesArray = $countries->getItems();
//Now in $countiesArray you have an array of Countries.
Fetch cities is used to make search more deeper, so you can use it as a search parameter. Also, you can search cities by a country (So you fetch all the cities in a country.)
Fetch all cities exist in the Database.
$cities = $main->city();
$citiesArray = $cities->getItems();
Fetch all cities by country.
//Get first country item from the DB.
$country = current($main->country()->getItems());
//Find all cities there.
$cities = $main->city($country);
//Get all available items.
$citiesArray = $cities->getItems();
If you have any issues or questions regarding the API or the SDK it self, you are welcome to create an issue, or
You can write an Email to shatilo.reymond@gmail.com
or roquie0@gmail.com