From 4c246c5d98b4854844f43f8ea2ff7e5a1a301186 Mon Sep 17 00:00:00 2001 From: LeoTravel <41335720+LeoTravel@users.noreply.github.com> Date: Sat, 4 Aug 2018 11:53:57 +0200 Subject: [PATCH] Fare_PricePNRWithBookingClass add optionDetail to pricingOptionKey (#217) * Add overrideOptionsWithCriteria for Fare --- .../FarePricePnrWithBookingClassOptions.php | 6 ++++ .../Fare/PricePNRWithBookingClass12.php | 4 +++ .../Fare/PricePNRWithBookingClass13.php | 23 ++++++++++++++ .../Fare/PricePnr13/PricingOptionGroup.php | 6 +++- .../Fare/PricePNRWithBookingClass12Test.php | 19 ++++++++++++ .../Fare/PricePNRWithBookingClass13Test.php | 30 +++++++++++++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/Amadeus/Client/RequestOptions/FarePricePnrWithBookingClassOptions.php b/src/Amadeus/Client/RequestOptions/FarePricePnrWithBookingClassOptions.php index aaa699187..549717c68 100644 --- a/src/Amadeus/Client/RequestOptions/FarePricePnrWithBookingClassOptions.php +++ b/src/Amadeus/Client/RequestOptions/FarePricePnrWithBookingClassOptions.php @@ -123,6 +123,12 @@ class FarePricePnrWithBookingClassOptions extends Base */ public $overrideOptions = []; + + /** + * @var array + */ + public $overrideOptionsWithCriteria = []; + /** * Specify the validating carrier * diff --git a/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12.php b/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12.php index c2845582a..56e43a87b 100644 --- a/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12.php +++ b/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12.php @@ -168,6 +168,10 @@ protected function checkUnsupportedOptions($options) if (!empty($options->pricingLogic)) { throw new OptionNotSupportedException('Pricing Logic option not supported in version 12 or lower'); } + + if (!empty($options->overrideOptionsWithCriteria)) { + throw new OptionNotSupportedException('Override Options With Criteria are not supported in version 12 or lower'); + } } /** diff --git a/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13.php b/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13.php index d534da1d7..aa5812414 100644 --- a/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13.php +++ b/src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13.php @@ -171,6 +171,11 @@ public static function loadPricingOptionsFromRequestOptions($options) self::makeOverrideOptions($options->overrideOptions, $priceOptions) ); + $priceOptions = self::mergeOptions( + $priceOptions, + self::makeOverrideOptionsWithCriteria($options->overrideOptionsWithCriteria, $priceOptions) + ); + // All options processed, no options found: if (empty($priceOptions)) { $priceOptions[] = new PricingOptionGroup(PricingOptionKey::OPTION_NO_OPTION); @@ -197,6 +202,24 @@ protected static function makeOverrideOptions($overrideOptions, $priceOptions) return $opt; } + /** + * @param string[] $overrideOptionsWithCriteria + * @param PricingOptionGroup[] $priceOptions + * @return PricingOptionGroup[] + */ + protected static function makeOverrideOptionsWithCriteria($overrideOptionsWithCriteria, $priceOptions) + { + $opt = []; + + foreach ($overrideOptionsWithCriteria as $overrideOptionWithCriteria) { + if (!self::hasPricingGroup($overrideOptionWithCriteria["key"], $priceOptions)) { + $opt[] = new PricingOptionGroup($overrideOptionWithCriteria["key"], $overrideOptionWithCriteria["optionDetail"]); + } + } + + return $opt; + } + /** * @param string|null $validatingCarrier * @return PricePnr13\PricingOptionGroup[] diff --git a/src/Amadeus/Client/Struct/Fare/PricePnr13/PricingOptionGroup.php b/src/Amadeus/Client/Struct/Fare/PricePnr13/PricingOptionGroup.php index 389a86dcb..89afdc2e2 100644 --- a/src/Amadeus/Client/Struct/Fare/PricePnr13/PricingOptionGroup.php +++ b/src/Amadeus/Client/Struct/Fare/PricePnr13/PricingOptionGroup.php @@ -94,9 +94,13 @@ class PricingOptionGroup * PricingOptionGroup constructor. * * @param string $key + * @param string $optionDetail */ - public function __construct($key) + public function __construct($key, $optionDetail=null) { $this->pricingOptionKey = new PricingOptionKey($key); + if (isset($optionDetail)) { + $this->optionDetail = new OptionDetail($optionDetail); + } } } diff --git a/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12Test.php b/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12Test.php index 4b9f98bfb..416365606 100644 --- a/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12Test.php +++ b/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12Test.php @@ -145,6 +145,25 @@ public function testCanThrowExceptioWhenDoPricePnrCallWithPricingLogic() new PricePNRWithBookingClass12($opt); } + public function testCanThrowExceptioWhenDoPricePnrCallWithOverrideOptionsWithCriteria() + { + $this->setExpectedException( + '\Amadeus\Client\Struct\OptionNotSupportedException', + 'Override Options With Criteria are not supported in version 12 or lower' + ); + + $opt = new FarePricePnrWithBookingClassOptions([ + 'overrideOptionsWithCriteria' => [ + [ + 'key' => 'SBF', + 'optionDetail' => '1' + ] + ] + ]); + + new PricePNRWithBookingClass12($opt); + } + public function testCanDoPricePnrCallWithCorpNegoFare() { $opt = new FarePricePnrWithBookingClassOptions([ diff --git a/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13Test.php b/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13Test.php index b5be8048c..c62b22b24 100644 --- a/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13Test.php +++ b/tests/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13Test.php @@ -135,6 +135,36 @@ public function testCanDoPricePnrCallWithNewFareBasisParams() $this->assertTrue($this->assertArrayContainsSameObject($msg->pricingOptionGroup, $negofarePo)); } + public function testCanDoPricePnrCallWithOverrideOptionWithCriteriaParams() + { + $opt = new FarePricePnrWithBookingClassOptions([ + 'validatingCarrier' => 'BA', + 'currencyOverride' => 'EUR', + 'overrideOptionsWithCriteria' => [ + [ + 'key' => 'SBF', + 'optionDetail' => '1' + ] + ] + ]); + + $msg = new PricePNRWithBookingClass13($opt); + + $validatingCarrierPo = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER); + $validatingCarrierPo->carrierInformation = new CarrierInformation('BA'); + + $this->assertTrue($this->assertArrayContainsSameObject($msg->pricingOptionGroup, $validatingCarrierPo)); + + $currencyOverridePo = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE); + $currencyOverridePo->currency = new Currency('EUR'); + + $this->assertTrue($this->assertArrayContainsSameObject($msg->pricingOptionGroup, $currencyOverridePo)); + + $negofarePo = new PricingOptionGroup('SBF','1'); + + $this->assertTrue($this->assertArrayContainsSameObject($msg->pricingOptionGroup, $negofarePo)); + } + public function testCanDoPricePnrCallWithNoOptions() { $opt = new FarePricePnrWithBookingClassOptions();