2017 © Pedro Peláez
 

library client-eurolines

eurolines booking client

image

thomaswiener/client-eurolines

eurolines booking client

  • Friday, November 14, 2014
  • by twiener
  • Repository
  • 1 Watchers
  • 1 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Eurolines Client Build Status

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)

Installation

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)

Setup

$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();

Security

Login

$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();
}

Logout

$response = $securityService->logout();

Logged In Check

$response = $securityService->isLoggedIn();
if ($response->getData()->IsLoggedInResult) {
    echo 'error logging out'; exit();
}

Journey

Get Stations

$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';

Get Tariffs


$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);

Ticket

Purchase


//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;

Get Ticket Number

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;
    }
}

Get Sale


$response = $ticketService->getSale($sale->SaleId);

Get Print Data

$response = $ticketService->getPrintData($sale->SaleId);

Confirm Print

//$response = $ticketService->confirmPrint($sale->SaleId);

Cancel Tariffs

$tariffs = [];
foreach ($ticketNumbers as $ticketNumber) {
    $tariffs[$ticket->TicketId]['tariffs'] = $ticketService->cancelTariffs($ticket->TicketId);
    $tariffs[$ticket->TicketId]['ticketNumber'] = $ticketNumber;
}

Cancel Ticket

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);
}

The Versions

14/11 2014

dev-master

9999999-dev

eurolines booking client

  Sources   Download

MIT

The Requires

 

The Development Requires