dev-master
9999999-deveurolines booking client
MIT
The Requires
- php >=5.4
- ext-curl *
- guzzlehttp/guzzle ~4.0
The Development Requires
Wallogit.com
2017 © Pedro Peláez
eurolines booking client
This package is a php client implementation for the Eurolines (RO) Webservice (SOAP). It is based on the webservice description found here: http://rezervari.eurolines.ro/emlines_api/APIdoc.htm, (*1)
Endpoint descriptions can be found here: http://rezervari.eurolines.ro/emlines_api/api.asmx?, (*2)
Please read the following description before continuing:, (*3)
http://rezervari.eurolines.ro/emlines_api/APIdoc.htm#_Toc211526756, (*4)
Below you will find example calls for the different endpoints., (*5)
Install via composer., (*6)
Add "thomaswiener/client-eurolines": "dev-master" to your composer.json and update vendors., (*7)
Packagist: https://packagist.org/packages/thomaswiener/client-eurolines, (*8)
Github: https://github.com/thomaswiener/client-eurolines, (*9)
$loader = require_once __DIR__ . "/./vendor/autoload.php";
$config = array(
'wsdl' => 'http://rezervari.eurolines.ro/emlines_api/api.asmx?WSDL',
'username' => 'username',
'password' => 'PA$$W0RD'
);
$originCode = 'BUC'; //Bucuresti
$destinationCode = 'MUN'; //Munich
$client = new \EurolinesClient\Client($config, 'log');
$securityService = new \EurolinesClient\Endpoint\Security($client);
$stationService = new \EurolinesClient\Endpoint\Station($client);
$journeyService = new \EurolinesClient\Endpoint\Journey($client);
$ticketService = new \EurolinesClient\Endpoint\Ticket($client);
session_start();
$user = new \EurolinesClient\Data\User();
$user
->setUsername($config['username'])
->setPassword($config['password'])
->setLanguageCode('en');
$response = $securityService->login($user);
//set session id
$_SESSION['ASP.NET_SessionId'] = $response->getSessionId();
//check if logged in
$response = $securityService->isLoggedIn();
if (!$response->getData()->IsLoggedInResult) {
echo 'not logged in'; exit();
}
$response = $securityService->logout();
$response = $securityService->isLoggedIn();
if ($response->getData()->IsLoggedInResult) {
echo 'error logging out'; exit();
}
$response = $stationService->getAll();
foreach ($response->getData()->busStopCollection->Stop as $stationService) {
if ($stationService->Code == $originCode) {
$busStopFrom = $stationService;
}
if ($stationService->Code == $destinationCode) {
$busStopTo = $stationService;
}
}
$journeySearchData = new \EurolinesClient\Data\JourneySearch(); $journeySearchData ->setJourneyType(EurolinesClient\Data\JourneySearch::TYPE_ONE_WAY) ->setBusStopCodeFrom($busStopFrom->Code) ->setBusStopCodeTo($busStopTo->Code) ->setDepartureDate((new \DateTime())->setDate(2014, 12, 5)) #->setBusStopCodeBackFrom($busStopTo->Code) #->setBusStopCodeBackTo($busStopFrom->Code) #->setDepartureBackDate((new \DateTime())->setDate(2014, 12, 20)) ->setSearchInterval(3); $response = $journeyService->search($journeySearchData); //select first leg (trip) foreach ($response->getData()->journeyCollection->ArrayOfLeg as $leg) { break; } //==================== //get templates of leg //==================== if ($leg->FreePlaces == 0) { echo "bus fully booked"; exit(); } $response = $journeyService->getTemplatesByLineId($leg->LineId); $template = $response->getData()->printTemplateCollection->PrintTemplate[1]; $template = json_decode(json_encode($template), true); #$template['NumberingType'] = 'Sequence';
$journeyData = new \EurolinesClient\Data\Journey(); foreach ($leg as $fieldName => $value) { $method = sprintf('set%s', $fieldName); if ($value instanceof \stdClass) { $value = json_decode(json_encode($value), true); } $journeyData->$method($value); } $response = $journeyService->getTariff($journeyData);
//get regular price for an adult foreach ($response->getData()->priceCollection->Price as $price) { if ($price->TariffCode == 'EURv01') { break; } } //set price object $priceData = new \EurolinesClient\Data\Price(); foreach ($price as $fieldName => $value) { $method = sprintf('set%s', $fieldName); if ($value instanceof \stdClass) { $value = json_decode(json_encode($value), true); } $priceData->$method($value); } //set passenger object $passengerData1 = new \EurolinesClient\Data\Passenger(); $passengerData1->setFirstName('John'); $passengerData1->setLastName('Doe'); $passengerData1->setStreet('Chausseestrasse 123'); $passengerData1->setCity('Berlin'); $passengerData1->setCountry('Germany'); $passengerData1->setPhoneNumber('+491711234567'); $passengerData1->setZipCode('10001'); $passengerData1->setBirthDate('01/01/1990'); $passengerData1->setNote(''); $passengerData1->setPrice(0); $passengerData1->setPassengerId(0); $passengerData1->setEmail('asdf@asdfd.de'); $passengerData1->setTax(0); $passengerData1->setPassport('asdf'); //set ticket object $ticketData = new \EurolinesClient\Data\Ticket(); $ticketData->setTicketType(EurolinesClient\Data\Ticket::TICKET_TYPE_SELL); $ticketData->setJourneyType(EurolinesClient\Data\JourneySearch::TYPE_ONE_WAY); $ticketData->addJourney($journeyData); $ticketData->addPassenger($passengerData1); #$ticketData->addPassenger($passengerData2); $ticketData->addPrice($priceData); #$ticketData->addPrice($priceData); $ticketData->setInvoiceNumber(''); //call purchase $response = $ticketService->purchase($ticketData); $sale = $response->getData()->Sale;
foreach ($sale->Passengers as $passenger) {
foreach ($passenger->Tickets as $ticket) {
$response = $ticketService->saveTicketNumber($ticket->TicketId, $template); //for every passenger and every leg
$ticketNumbers[] = $response->getData()->ticketNumber;
}
}
$response = $ticketService->getSale($sale->SaleId);
$response = $ticketService->getPrintData($sale->SaleId);
//$response = $ticketService->confirmPrint($sale->SaleId);
$tariffs = [];
foreach ($ticketNumbers as $ticketNumber) {
$tariffs[$ticket->TicketId]['tariffs'] = $ticketService->cancelTariffs($ticket->TicketId);
$tariffs[$ticket->TicketId]['ticketNumber'] = $ticketNumber;
}
foreach ($tariffs as $ticketId => $tariffCollection) {
$tariff = $tariffCollection['tariffs']->getData()->priceCollection->Price[0];
$ticketData = new \EurolinesClient\Data\Ticket();
$ticketData->setReferenceNumber($ticketId); #$sale->SaleId);
$ticketData->setTicketNumber($tariffCollection['ticketNumber']);
$ticketData->setTariffId($tariff->TariffId);
$ticketData->setCancelOnlyBackWay(false);
$response = $ticketService->cancel($ticketData);
}
eurolines booking client
MIT