Skip to content

Commit

Permalink
Implemented Fare_PricePnrWithBookingClass message version 13 and up. …
Browse files Browse the repository at this point in the history
…This is a fix for #6
  • Loading branch information
DerMika committed Jun 14, 2016
1 parent fe20c14 commit 4f85343
Show file tree
Hide file tree
Showing 32 changed files with 3,228 additions and 10 deletions.
40 changes: 40 additions & 0 deletions src/Amadeus/Client/RequestCreator/UnsupportedOptionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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\RequestCreator;

use Amadeus\Client;

/**
* UnsupportedOptionException
*
* Thrown when an option is used which is not supported
* - wrong option?
* - not yet implemented?
*
* @package Amadeus\Client\RequestCreator
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class UnsupportedOptionException extends Client\Exception
{

}
59 changes: 58 additions & 1 deletion src/Amadeus/Client/ResponseHandler/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,59 @@ protected function analyzeQueueListResponse($response)
return $analysisResponse;
}


/**
*
* <Fare_PricePNRWithBookingClassReply xmlns="http://xml.amadeus.com/TPCBRR_13_2_1A">
* <applicationError>
* <errorOrWarningCodeDetails>
* <errorDetails>
* <errorCode>00477</errorCode>
* <errorCategory>EC</errorCategory>
* <errorCodeOwner>1A</errorCodeOwner>
* </errorDetails>
* </errorOrWarningCodeDetails>
* <errorWarningDescription>
* <freeText>INVALID FORMAT</freeText>
* </errorWarningDescription>
* </applicationError>
* </Fare_PricePNRWithBookingClassReply>
*
* @param SendResult $response Fare_PricePNRWithBookingClass result
* @return Result
* @throws Exception
*/
protected function analyzeFarePricePNRWithBookingClassResponse($response)
{
$analyzeResponse = new Result($response);

$domXpath = $this->makeDomXpath($response->responseXml);

$queryErrorCode = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode";
$queryErrorCategory = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory";
$queryErrorMsg = "//m:applicationError/m:errorWarningDescription/m:freeText";

$errorCodeNodeList = $domXpath->query($queryErrorCode);

if ($errorCodeNodeList->length > 0) {
$errorCatNode = $domXpath->query($queryErrorCategory)->item(0);
if ($errorCatNode instanceof \DOMNode) {
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
} else {
$analyzeResponse->status = Result::STATUS_ERROR;
}

$analyzeResponse->messages[] = new Result\NotOk(
$errorCodeNodeList->item(0)->nodeValue,
$this->makeMessageFromMessagesNodeList(
$domXpath->query($queryErrorMsg)
)
);
}

return $analyzeResponse;
}

/**
* @param SendResult $response WebService message Send Result
* @return Result
Expand All @@ -255,7 +308,11 @@ protected function analyzeSimpleResponseErrorCodeAndMessage($response)

if (!is_null($errorCodeNode)) {
$errorCatNode = $domDoc->getElementsByTagName("errorCategory")->item(0);
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
if ($errorCatNode instanceof \DOMNode) {
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue);
} else {
$analyzeResponse->status = Result::STATUS_ERROR;
}

$errorCode = $errorCodeNode->nodeValue;
$errorTextNodeList = $domDoc->getElementsByTagName("freeText");
Expand Down
12 changes: 11 additions & 1 deletion src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

namespace Amadeus\Client\Struct\Fare;

use Amadeus\Client\RequestCreator\UnsupportedOptionException;
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions;
use Amadeus\Client\Struct\BaseWsMessage;
use Amadeus\Client\Struct\Fare\PricePnr12\AttributeDetails;
use Amadeus\Client\Struct\Fare\PricePnr12\CurrencyOverride;
use Amadeus\Client\Struct\Fare\PricePnr12\OverrideInformation;
use Amadeus\Client\Struct\Fare\PricePnr12\PricingFareBase;
use Amadeus\Client\Struct\Fare\PricePnr12\ValidatingCarrier;
Expand Down Expand Up @@ -53,6 +55,9 @@ class PricePNRWithBookingClass12 extends BaseWsMessage

public $cityOverride;

/**
* @var PricePnr12\CurrencyOverride
*/
public $currencyOverride;

public $taxDetails;
Expand Down Expand Up @@ -81,6 +86,7 @@ class PricePNRWithBookingClass12 extends BaseWsMessage
* PricePNRWithBookingClass12 constructor.
*
* @param FarePricePnrWithBookingClassOptions $options
* @throws UnsupportedOptionException
*/
public function __construct(FarePricePnrWithBookingClassOptions $options)
{
Expand All @@ -94,11 +100,15 @@ public function __construct(FarePricePnrWithBookingClassOptions $options)
}
}

if (!empty($options->currencyOverride)) {
$this->currencyOverride = new CurrencyOverride($options->currencyOverride);
}

if (is_string($options->validatingCarrier)) {
$this->validatingCarrier = new ValidatingCarrier($options->validatingCarrier);
}

if (in_array(AttributeDetails::OVERRIDE_FAREBASIS, $options->overrideOptions)) {
if (in_array(AttributeDetails::OVERRIDE_FAREBASIS, $options->overrideOptions) && !empty($options->pricingsFareBasis)) {
foreach ($options->pricingsFareBasis as $pricingFareBasis) {
$this->pricingFareBase[] = new PricingFareBase($pricingFareBasis);
}
Expand Down
101 changes: 99 additions & 2 deletions src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@
namespace Amadeus\Client\Struct\Fare;

use Amadeus\Client\RequestCreator\MessageVersionUnsupportedException;
use Amadeus\Client\RequestOptions\Fare\PricePnrBcFareBasis;
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions;
use Amadeus\Client\Struct\BaseWsMessage;
use Amadeus\Client\Struct\Fare\PricePnr13\CarrierInformation;
use Amadeus\Client\Struct\Fare\PricePnr13\CriteriaDetails;
use Amadeus\Client\Struct\Fare\PricePnr13\Currency;
use Amadeus\Client\Struct\Fare\PricePnr13\FirstCurrencyDetails;
use Amadeus\Client\Struct\Fare\PricePnr13\OptionDetail;
use Amadeus\Client\Struct\Fare\PricePnr13\PaxSegTstReference;
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionGroup;
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionKey;

/**
* Fare_PricePNRWithBookingClass v 13 and higher structure
Expand All @@ -48,9 +57,97 @@ class PricePNRWithBookingClass13 extends BaseWsMessage
public function __construct(FarePricePnrWithBookingClassOptions $options)
{

throw new MessageVersionUnsupportedException(
'Fare_PricePNRWithBookingClass message versions 13+ are not yet implemented'
if ($options->validatingCarrier !== null) {
$this->pricingOptionGroup[] = $this->makePricingOptionForValidatingCarrier($options->validatingCarrier);
}

if ($options->currencyOverride !== null) {
$this->pricingOptionGroup[] = $this->makePricingOptionForCurrencyOverride($options->currencyOverride);
}

if ($options->pricingsFareBasis !== null) {
foreach ($options->pricingsFareBasis as $pricingFareBasis) {
$this->pricingOptionGroup[] = $this->makePricingOptionFareBasisOverride($pricingFareBasis);
}
}

if (!empty($options->overrideOptions)) {
foreach ($options->overrideOptions as $overrideOption) {
if (!$this->hasPricingGroup($overrideOption)) {
$this->pricingOptionGroup[] = new PricingOptionGroup($overrideOption);
}
}
}

// All options processed, no options found:
if (empty($this->pricingOptionGroup)) {
$this->pricingOptionGroup[] = new PricingOptionGroup(PricingOptionKey::OPTION_NO_OPTION);
}
}

/**
* @param string $validatingCarrier
* @return PricePnr13\PricingOptionGroup
*/
protected function makePricingOptionForValidatingCarrier($validatingCarrier)
{
$po = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER);

$po->carrierInformation = new CarrierInformation($validatingCarrier);

return $po;
}

/**
* @param string $currency
* @return PricePnr13\PricingOptionGroup
*/
protected function makePricingOptionForCurrencyOverride($currency)
{
$po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE);

$po->currency = new Currency($currency, FirstCurrencyDetails::QUAL_CURRENCY_OVERRIDE);

return $po;
}

/**
* @param PricePnrBcFareBasis $pricingFareBasis
* @return PricePnr13\PricingOptionGroup
*/
protected function makePricingOptionFareBasisOverride($pricingFareBasis)
{
$po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE);

$po->optionDetail = new OptionDetail();
$po->optionDetail->criteriaDetails[] = new CriteriaDetails(
$pricingFareBasis->fareBasisPrimaryCode . $pricingFareBasis->fareBasisCode
);

$po->paxSegTstReference = new PaxSegTstReference($pricingFareBasis->segmentReference);

return $po;
}

/**
* Avoid double pricing groups when combining an explicitly provided override option with a specific parameter
* that uses the same override option.
*
* Backwards compatibility with PricePnrWithBookingClass12
*
* @param string $optionKey
* @return bool
*/
protected function hasPricingGroup($optionKey)
{
$found = false;

foreach ($this->pricingOptionGroup as $pog) {
if ($pog->pricingOptionKey->pricingOptionKey === $optionKey) {
$found = true;
}
}

return $found;
}
}
43 changes: 43 additions & 0 deletions src/Amadeus/Client/Struct/Fare/PricePnr12/CurrencyOverride.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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\Fare\PricePnr12;

/**
* CurrencyOverride
*
* @package Amadeus\Client\Struct\Fare\PricePnr12
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class CurrencyOverride
{
public $firstRateDetail;

/**
* CurrencyOverride constructor.
* @param string $currency
*/
public function __construct($currency)
{
$this->firstRateDetail = new FirstRateDetail($currency);
}
}
47 changes: 47 additions & 0 deletions src/Amadeus/Client/Struct/Fare/PricePnr12/FirstRateDetail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?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\Fare\PricePnr12;

/**
* FirstRateDetail
*
* @package Amadeus\Client\Struct\Fare\PricePnr12
* @author Dieter Devlieghere <dieter.devlieghere@benelux.amadeus.com>
*/
class FirstRateDetail
{
/**
* @var string
*/
public $currencyCode;

/**
* FirstRateDetail constructor.
*
* @param string $currency
*/
public function __construct($currency)
{
$this->currencyCode = $currency;
}
}
Loading

0 comments on commit 4f85343

Please sign in to comment.