Skip to content

Commit

Permalink
Fare_PricePNRWithBookingClass add optionDetail to pricingOptionKey (#217
Browse files Browse the repository at this point in the history
)

* Add overrideOptionsWithCriteria for Fare
  • Loading branch information
gabrieleleo authored and DerMika committed Aug 4, 2018
1 parent 0447dcb commit 4c246c5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class FarePricePnrWithBookingClassOptions extends Base
*/
public $overrideOptions = [];


/**
* @var array
*/
public $overrideOptionsWithCriteria = [];

/**
* Specify the validating carrier
*
Expand Down
4 changes: 4 additions & 0 deletions src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass12.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

/**
Expand Down
23 changes: 23 additions & 0 deletions src/Amadeus/Client/Struct/Fare/PricePNRWithBookingClass13.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 4c246c5

Please sign in to comment.