Skip to content

Commit

Permalink
Merged develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sunspikes committed Aug 9, 2016
2 parents d1594d6 + 2a46221 commit f01dad9
Show file tree
Hide file tree
Showing 19 changed files with 891 additions and 562 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
## PHP Amadeus

[![Latest Stable Version](https://poser.pugx.org/sunspikes/php-amadeus/v/stable)](https://packagist.org/packages/sunspikes/php-amadeus)
[![License](https://poser.pugx.org/sunspikes/php-amadeus/license)](https://packagist.org/packages/sunspikes/php-amadeus)

This is a PHP implementation of the Amadeus Flight Search and Booking API.

See the [example.php](https://github.com/sunspikes/PHP-Amadeus/blob/master/example.php) for usage.
Expand Down
8 changes: 4 additions & 4 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Amadeus Sample client
*/

include 'src/Amadeus/Client.php';
include 'vendor/autoload.php';

use Sunspikes\Amadeus\Client;

// Instantiate the Amadeus class (Debug enabled)
$ws = new Client('AmadeusWebServices.wsdl', true);
$ws = new Client('wsdl/AmadeusWebServices.wsdl', true);

// Authenticate
$ws->securityAuthenticate([YOUR_SOURCE], [YOUR_ORIGIN], [YOUR_PASSWORD], [PASSWORD_LENGTH], [ORGANIZATION_ID]);
Expand Down Expand Up @@ -69,8 +69,8 @@
// Make the booking
$ws->airSellFromRecommendation($from, $to, $segments);
$ws->pnrAddMultiElements($travellers, $address, $phone);
$ws->farePricePNRWithBookingClass($code);
$ws->ticketCreateTSTFromPricing($types);
$ws->farePricePnrWithBookingClass($code);
$ws->ticketCreateTstFromPricing($types);
$ws->pnrAddMultiElementsFinal();

// To Retreive PNR pass the PNR ID returned by the previous booking call.
Expand Down
40 changes: 40 additions & 0 deletions src/Amadeus/AbstractAmadeusCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Sunspikes\Amadeus;

abstract class AbstractAmadeusCommand implements AmadeusCommandInterface
{
/** @var AmadeusSoapClient */
private $amadeusSoapClient;

/**
* @param AmadeusSoapClient $amadeusSoapClient
*/
public function setAmadeusSoapClient(AmadeusSoapClient $amadeusSoapClient)
{
$this->amadeusSoapClient = $amadeusSoapClient;
}

/**
* @return AmadeusSoapClient
*/
public function getAmadeusSoapClient()
{
return $this->amadeusSoapClient;
}

/**
* @throws AmadeusClientException
*/
public function execute()
{
if (null === $this->amadeusSoapClient) {
throw new AmadeusClientException("Error: Set the AmadeusSoapClient");
}

$this->amadeusSoapClient->execute(
$this->getName(),
$this->getParameters()
);
}
}
49 changes: 49 additions & 0 deletions src/Amadeus/AirMultiAvailability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Sunspikes\Amadeus;

/**
* Class AirMultiAvailability
*
* Check airline availability by Flight
*
* @package Sunspikes\Amadeus
*/
class AirMultiAvailability extends AbstractAmadeusCommand
{
private $deprtDate;
private $deprtLoc;
private $arriveLoc;
private $service;
private $airCode;
private $airNum;

public function __construct($deprtDate, $deprtLoc, $arriveLoc, $service, $airCode, $airNum)
{
$this->deprtDate = $deprtDate;
$this->deprtLoc = $deprtLoc;
$this->arriveLoc = $arriveLoc;
$this->service = $service;
$this->airCode = $airCode;
$this->airNum = $airNum;
}

public function getParameters()
{
$params['Air_MultiAvailability']['messageActionDetails']['functionDetails']['actionCode'] = 44;
$params['Air_MultiAvailability']['requestSection']['availabilityProductInfo']['availabilityDetails']['departureDate'] = $this->deprtDate;
$params['Air_MultiAvailability']['requestSection']['availabilityProductInfo']['departureLocationInfo']['cityAirport'] = $this->deprtLoc;
$params['Air_MultiAvailability']['requestSection']['availabilityProductInfo']['arrivalLocationInfo']['cityAirport'] = $this->arriveLoc;
$params['Air_MultiAvailability']['requestSection']['optionClass']['productClassDetails']['serviceClass'] = $this->service;
$params['Air_MultiAvailability']['requestSection']['airlineOrFlightOption']['flightIdentification']['airlineCode'] = $this->airCode;
$params['Air_MultiAvailability']['requestSection']['airlineOrFlightOption']['flightIdentification']['number'] = $this->airNum;
$params['Air_MultiAvailability']['requestSection']['availabilityOptions']['productTypeDetails']['typeOfRequest'] = 'TN';

return $params;
}

public function getName()
{
return 'Air_MultiAvailability';
}
}
77 changes: 77 additions & 0 deletions src/Amadeus/AirSellFromRecommendation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Sunspikes\Amadeus;

/**
* Class AirSellFromRecommendation
*
* Set travel segments
*
* @package Sunspikes\Amadeus
*/
class AirSellFromRecommendation extends AbstractAmadeusCommand
{
private $from;
private $to;
private $segments;

/**
* @param $from
* @param $to
* @param $segments
*/
public function __construct($from, $to, $segments)
{
$this->from = $from;
$this->to = $to;
$this->segments = $segments;
}

/**
* @return array
*/
public function getParameters()
{
$params['Air_SellFromRecommendation']['messageActionDetails']['messageFunctionDetails']['messageFunction']
= 183;
$params['Air_SellFromRecommendation']['messageActionDetails']['messageFunctionDetails']['additionalMessageFunction']
= 'M1';
$params['Air_SellFromRecommendation']['itineraryDetails']['originDestinationDetails']['origin']
= $this->from;
$params['Air_SellFromRecommendation']['itineraryDetails']['originDestinationDetails']['destination']
= $this->to;
$params['Air_SellFromRecommendation']['itineraryDetails']['message']['messageFunctionDetails']['messageFunction']
= 183;

$i = 0;
foreach ($this->segments as $segment) {
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['travelProductInformation']['flightDate']['departureDate']
= $segment['dep_date'];
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['travelProductInformation']['boardPointDetails']['trueLocationId']
= $segment['dep_location'];
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['travelProductInformation']['offpointDetails']['trueLocationId']
= $segment['dest_location'];
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['travelProductInformation']['companyDetails']['marketingCompany']
= $segment['company'];
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['travelProductInformation']['flightIdentification']['flightNumber']
= $segment['flight_no'];
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['travelProductInformation']['flightIdentification']['bookingClass']
= $segment['class'];
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['relatedproductInformation']['quantity']
= $segment['passengers'];
$params['Air_SellFromRecommendation']['itineraryDetails']['segmentInformation'][$i]['relatedproductInformation']['statusCode']
= 'NN';
$i++;
}

return $params;
}

/**
* @return string
*/
public function getName()
{
return 'Air_SellFromRecommendation';
}
}
7 changes: 7 additions & 0 deletions src/Amadeus/AmadeusClientException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Sunspikes\Amadeus;

class AmadeusClientException extends \Exception
{
}
21 changes: 21 additions & 0 deletions src/Amadeus/AmadeusCommandInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Sunspikes\Amadeus;

interface AmadeusCommandInterface
{
/**
* @return void
*/
public function execute();

/**
* @return array
*/
public function getParameters();

/**
* @return string
*/
public function getName();
}
88 changes: 88 additions & 0 deletions src/Amadeus/AmadeusSoapClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Sunspikes\Amadeus;

class AmadeusSoapClient
{
/**
* The main Amadeus WS namespace
*
* @var string
*/
const AMD_HEAD_NAMESPACE = 'http://webservices.amadeus.com/definitions';
/**
* Response data
*/
private $data;
/**
* Response headers
*/
private $headers;
/**
* Hold the client object
*/
private $client;
/**
* Indicates debug mode on/off
*/
private $debug;

/**
* @param $wsdl string Path to the WSDL file
* @param $debug boolean Enable/disable debug mode
*/
public function __construct($wsdl, $debug = false)
{
$this->debug = $debug;
$this->client = new \SoapClient($wsdl, array('trace' => $debug));
}

/**
* @param $method
* @param $params
*/
public function execute($method, $params)
{
$this->data = $this->client->__soapCall(
$method,
$params,
null,
new \SoapHeader(self::AMD_HEAD_NAMESPACE, 'SessionId', $this->headers['SessionId']?:null),
$this->headers
);

if ($this->debug) $this->debugDump($method, $params);
}

/**
* @return array
*/
public function getData()
{
return $this->data;
}

/**
* @return array
*/
public function getHeaders()
{
return $this->headers;
}

/**
* @param $method
* @param $params
*/
private function debugDump($method, $params)
{
/** @noinspection ForgottenDebugOutputInspection */
var_dump([
'method' => $method,
'params' => $params,
'data' => $this->data,
'request' => $this->client->__getLastRequest(),
'response' => $this->client->__getLastResponse(),
]);
}
}

0 comments on commit f01dad9

Please sign in to comment.