Skip to content

Commit

Permalink
- Further implementation of PNR creation
Browse files Browse the repository at this point in the history
- Support for sessions & stateful messages
  • Loading branch information
DerMika committed Jan 29, 2016
1 parent cfb65e4 commit ed2ac72
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 23 deletions.
34 changes: 34 additions & 0 deletions src/Amadeus/Client/RequestOptions/Pnr/Element/FormOfPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,39 @@
*/
class FormOfPayment extends Element
{
const TYPE_CASH = "CA";
const TYPE_CHECK = "CK";
const TYPE_CREDITCARD = "CC";
const TYPE_MISC = "MS";

/**
* self::TYPE_*
*
* @var string
*/
public $type;
/**
* for self::TYPE_CREDITCARD
*
* @var string
*/
public $creditCardType;
/**
* for self::TYPE_CREDITCARD
*
* @var string
*/
public $creditCardNumber;
/**
* for self::TYPE_CREDITCARD
*
* @var string
*/
public $creditCardExpiry;

/**
* Free text for self::TYPE_MISC
* @var string
*/
public $freeText;
}
4 changes: 3 additions & 1 deletion src/Amadeus/Client/RequestOptions/Pnr/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@

namespace Amadeus\Client\RequestOptions\Pnr;

use Amadeus\Client\LoadParamsFromArray;

/**
* Basic PNR Segment
*
* @package Amadeus\Client\RequestOptions\Pnr
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class Segment
class Segment extends LoadParamsFromArray
{
const STATUS_CONFIRMED = "HK";

Expand Down
17 changes: 14 additions & 3 deletions src/Amadeus/Client/Session/Handler/Classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,26 @@
class Classmap
{
/**
* The PHP -> WSDL translation classmap for the Amadeus WS Client
* The PHP -> WSDL translation classmap for Soap Header 4 specific message parts
*
* @var array
*/
public static $map = [
public static $soapheader4map = [
'AMA_SecurityHostedUser' => 'Amadeus\Client\Struct\HeaderV4\SecurityHostedUser',
'UserID' => 'Amadeus\Client\Struct\HeaderV4\UserId',
'Security' => 'Amadeus\Client\Struct\HeaderV4\Security',
'UsernameToken' => 'Amadeus\Client\Struct\HeaderV4\UsernameToken'
'UsernameToken' => 'Amadeus\Client\Struct\HeaderV4\UsernameToken',
'Session' => 'Amadeus\Client\Struct\HeaderV4\Session',
];

/**
* The PHP -> WSDL translation classmap for the Amadeus WS Client
*
* Contains all non-soapheader-specific mapping
*
* @var array
*/
public static $map = [

];
}
44 changes: 32 additions & 12 deletions src/Amadeus/Client/Session/Handler/SoapHeader4.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ protected function handlePostMessage($messageName, $messageOptions, $result)
} else {
$this->isAuthenticated = false;
}


}

/**
Expand All @@ -270,7 +268,9 @@ protected function handlePostMessage($messageName, $messageOptions, $result)
*/
protected function getSessionDataFromHeader($responseHeaders)
{
$this->log(LogLevel::INFO, $responseHeaders);
$this->log(LogLevel::WARNING, __METHOD__ . "() TODO: IMPLEMENT THIS METHOD");
$this->log(LogLevel::INFO, var_export($responseHeaders, true));

}

/**
Expand Down Expand Up @@ -367,11 +367,36 @@ protected function createSoapHeaders($sessionData, $params, $messageName, $messa
)
);*/
} else if ($stateful === true) {
// TODO: We are authenticated and stateful: provide session header

}
//We are authenticated and stateful: provide session header to continue or terminate session

/* // Sample session:
<awsse:Session xmlns:awsse="http://xml.amadeus.com/2010/06/Session_v3"
TransactionStatusCode="InSeries">
<awsse:SessionId>01HFHCODVI</awsse:SessionId>
<awsse:SequenceNumber>2</awsse:SequenceNumber>
<awsse:SecurityToken>1SP31VH87S9T310EWJIH27JLRI</awsse:SecurityToken>
</awsse:Session>
</soapenv:Header>
*/

$statusCode =
(isset($messageOptions['endSession']) && $messageOptions['endSession'] === true) ?
"End" :
"InSeries";

array_push(
$headersToSet,
new \SoapHeader(
'http://xml.amadeus.com/2010/06/Session_v3',
'Session',
new Client\Struct\HeaderV4\Session(
$this->sessionData,
$statusCode
)
)
);

}

array_push(
$headersToSet,
Expand All @@ -386,11 +411,6 @@ protected function createSoapHeaders($sessionData, $params, $messageName, $messa
)
)
);

if ($stateful) {
$statusCode = ($this->isAuthenticated === true) ? "InSeries" : "Start";

}
}

return $headersToSet;
Expand Down Expand Up @@ -588,7 +608,7 @@ protected function initSoapClient()
protected function makeSoapClientOptions()
{
$options = $this->soapClientOptions;
$options['classmap'] = Classmap::$map;
$options['classmap'] = array_merge(Classmap::$soapheader4map, Classmap::$map);

return $options;
}
Expand Down
56 changes: 56 additions & 0 deletions src/Amadeus/Client/Struct/HeaderV4/Session.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Amadeus\Client\Struct\HeaderV4;

/**
* Session Header structure
*
* @package Amadeus\Client\Struct\HeaderV4
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class Session
{
public $TransactionStatusCode;

public $SessionId;

public $SequenceNumber;

public $SecurityToken;

/**
* Session constructor.
*
* @param array $sessionData
* @param string $statusCode
*/
public function __construct($sessionData, $statusCode)
{
$this->SessionId = $sessionData[''];
$this->SequenceNumber = $sessionData[''];
$this->SecurityToken = $sessionData[''];

$this->TransactionStatusCode = $statusCode;
}

}
32 changes: 29 additions & 3 deletions src/Amadeus/Client/Struct/Pnr/AddMultiElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
use Amadeus\Client\Struct\Pnr\AddMultiElements\ElementManagementData;
use Amadeus\Client\Struct\Pnr\AddMultiElements\ElementManagementItinerary;
use Amadeus\Client\Struct\Pnr\AddMultiElements\ElementManagementPassenger;
use Amadeus\Client\Struct\Pnr\AddMultiElements\Fop;
use Amadeus\Client\Struct\Pnr\AddMultiElements\FopExtension;
use Amadeus\Client\Struct\Pnr\AddMultiElements\FormOfPayment;
use Amadeus\Client\Struct\Pnr\AddMultiElements\FreetextData;
use Amadeus\Client\Struct\Pnr\AddMultiElements\FreetextDetail;
use Amadeus\Client\Struct\Pnr\AddMultiElements\ItineraryInfo;
use Amadeus\Client\Struct\Pnr\AddMultiElements\MiscellaneousRemark;
use Amadeus\Client\Struct\Pnr\AddMultiElements\OriginDestinationDetails;
Expand Down Expand Up @@ -149,6 +153,9 @@ protected function createSegment($segment, &$tatooCounter)
$createdSegment = new ItineraryInfo($tatooCounter, ElementManagementItinerary::SEGMENT_MISCELLANEOUS);
$createdSegment->airAuxItinerary = new AirAuxItinerary($segmentType, $segment);
break;
case 'Air':
throw new \RuntimeException('NOT YET IMPLEMENTED');
break;
default:
throw new InvalidArgumentException('Segment type ' . $segmentType . 'is not supported');
break;
Expand Down Expand Up @@ -232,11 +239,27 @@ protected function createElement($element, &$tatooCounter)
switch ($elementType) {
case 'Contact':
/** @var Element\Contact $element */
//TODO
$createdElement = new DataElementsIndiv(ElementManagementData::SEGNAME_CONTACT_ELEMENT, $tatooCounter);
$createdElement->freetextData = new FreetextData(
$element->value,
$element->type
);
break;
case 'FormOfPayment':
/** @var Element\FormOfPayment $element */
//TODO
$createdElement = new DataElementsIndiv(ElementManagementData::SEGNAME_FORM_OF_PAYMENT, $tatooCounter);
$createdElement->formOfPayment = new FormOfPayment($element->type);
if ($element->type === Fop::IDENT_CREDITCARD) {
$createdElement->formOfPayment->fop->creditCardCode = $element->creditCardType;
$createdElement->formOfPayment->fop->accountNumber = $element->creditCardNumber;
$createdElement->formOfPayment->fop->expiryDate = $element->creditCardExpiry;
} elseif ($element->type === Fop::IDENT_MISC && $element->freeText != "NONREF") {
$createdElement->formOfPayment->fop->freetext = $element->freeText;
} elseif ($element->type === Fop::IDENT_MISC && $element->freeText == "NONREF") {
$createdElement->fopExtension = new FopExtension(1);
} elseif ($element->type === Fop::IDENT_CHECK) {
throw new \RuntimeException("FOP CHECK NOT YET IMPLEMENTED");
}
break;
case 'MiscellaneousRemark':
/** @var Element\MiscellaneousRemark $element */
Expand All @@ -250,7 +273,10 @@ protected function createElement($element, &$tatooCounter)
case 'ReceivedFrom':
/** @var Element\ReceivedFrom $element */
$createdElement = new DataElementsIndiv(ElementManagementData::SEGNAME_RECEIVE_FROM, $tatooCounter);
$createdElement->freetextData = new FreetextData($element->receivedFrom);
$createdElement->freetextData = new FreetextData(
$element->receivedFrom,
FreetextDetail::TYPE_RECEIVE_FROM
);
break;
case 'ServiceRequest':
/** @var Element\ServiceRequest $element */
Expand Down
11 changes: 11 additions & 0 deletions src/Amadeus/Client/Struct/Pnr/AddMultiElements/AirAuxItinerary.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public function __construct($segmentType, $segmentContent)
case 'Miscellaneous':
$this->loadMiscellaneous($segmentContent);
break;
case 'Air':
$this->loadAir($segmentContent);
break;
default:
throw new InvalidArgumentException('Segment type ' . $segmentType . 'is not supported');
break;
Expand All @@ -88,4 +91,12 @@ protected function loadMiscellaneous(Segment\Miscellaneous $segment)

$this->freetextItinerary = new FreetextItinerary($segment->freeText);
}

/**
* @param Segment\Air $segment
*/
protected function loadAir(Segment\Air $segment)
{
throw new \RuntimeException('NOT YET IMPLEMENTED');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ class ElementManagementData
*/
const SEGNAME_TICKETING_ELEMENT = "TK";

/**
* AP and related elements
* @var string
*/
const SEGNAME_CONTACT_ELEMENT = "AP";

/**
* OSI - Other Service Information
*
* @var string
*/
const SEGNAME_OTHER_SERVICE_INFORMATION = "OS";

/**
* AI - Accounting Information
*
* @var string
*/
const SEGNAME_ACCOUNTING_INFORMATION = "AI";

/**
* SSR - Special Service Request
*
* @var string
*/
const SEGNAME_SPECIAL_SERVICE_REQUEST = "SSR";

/**
* @var Reference
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Amadeus/Client/Struct/Pnr/AddMultiElements/Fop.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Fop
*/
public function __construct($identification = null)
{
if (!is_null($identification) && strlen($identification) == 2) {
if (!is_null($identification) && strlen($identification) == 2 && self::isValidFopType($identification)) {
$this->identification = $identification;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ class FreetextData
/**
* @param string $freeText
*/
public function __construct($freeText = null)
public function __construct($freeText = null, $type = null)
{
$this->longFreetext = $freeText;
$this->freetextDetail = new FreetextDetail();
$this->freetextDetail = new FreetextDetail($type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ class FreetextDetail
*/
const TYPE_RECEIVE_FROM = "P22";

const TYPE_PHONE_GENERAL = "5";

const TYPE_PHONE_HOME = "4";

const TYPE_PHONE_BUSINESS = "3";

const TYPE_PHONE_MOBILE = "7";

const TYPE_FAX = "P01";

const TYPE_EMAIL = "P02";

const TYPE_INTERNETADDRESS = "P03";

const TYPE_OTHER_SERVICE_INFO_OSI = "28";

/**
* @var string
*/
Expand Down Expand Up @@ -114,7 +130,7 @@ class FreetextDetail
* @param string $type
* @param string $subQual
*/
public function __construct($type = self::TYPE_RECEIVE_FROM, $subQual = self::QUALIFIER_LITERALTEXT)
public function __construct($type, $subQual = self::QUALIFIER_LITERALTEXT)
{
$this->type = $type;
$this->subjectQualifier = $subQual;
Expand Down

0 comments on commit ed2ac72

Please sign in to comment.