thomaswiener/client-eurolines

eurolines booking client

dev-master 2014-11-14 07:48 UTC

This package is not auto-updated.

Last update: 2024-05-07 02:07:39 UTC


README

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

Endpoint descriptions can be found here: http://rezervari.eurolines.ro/emlines_api/api.asmx?

Please read the following description before continuing:

http://rezervari.eurolines.ro/emlines_api/APIdoc.htm#_Toc211526756

Below you will find example calls for the different endpoints.

Installation

Install via composer.

Add "thomaswiener/client-eurolines": "dev-master" to your composer.json and update vendors.

Packagist: https://packagist.org/packages/thomaswiener/client-eurolines

Github: https://github.com/thomaswiener/client-eurolines

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

Search

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