|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* amadeus-ws-client |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright 2015 Amadeus Benelux NV |
|
6
|
|
|
* |
|
7
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
8
|
|
|
* you may not use this file except in compliance with the License. |
|
9
|
|
|
* You may obtain a copy of the License at |
|
10
|
|
|
* |
|
11
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
12
|
|
|
* |
|
13
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
14
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
15
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16
|
|
|
* See the License for the specific language governing permissions and |
|
17
|
|
|
* limitations under the License. |
|
18
|
|
|
* |
|
19
|
|
|
* @package Amadeus |
|
20
|
|
|
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0 |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace Amadeus\Client\Struct\Fare; |
|
24
|
|
|
|
|
25
|
|
|
use Amadeus\Client\RequestCreator\MessageVersionUnsupportedException; |
|
26
|
|
|
use Amadeus\Client\RequestOptions\Fare\PricePnrBcFareBasis; |
|
27
|
|
|
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions; |
|
28
|
|
|
use Amadeus\Client\Struct\BaseWsMessage; |
|
29
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\CarrierInformation; |
|
30
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\CriteriaDetails; |
|
31
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\Currency; |
|
32
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\FirstCurrencyDetails; |
|
33
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\OptionDetail; |
|
34
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\PaxSegTstReference; |
|
35
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionGroup; |
|
36
|
|
|
use Amadeus\Client\Struct\Fare\PricePnr13\PricingOptionKey; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Fare_PricePNRWithBookingClass v 13 and higher structure |
|
40
|
|
|
* |
|
41
|
|
|
* @package Amadeus\Client\Struct\Fare |
|
42
|
|
|
* @author dieter <[email protected]> |
|
43
|
|
|
*/ |
|
44
|
|
|
class PricePNRWithBookingClass13 extends BaseWsMessage |
|
45
|
|
|
{ |
|
46
|
|
|
/** |
|
47
|
|
|
* @var PricePnr13\PricingOptionGroup[] |
|
48
|
|
|
*/ |
|
49
|
|
|
public $pricingOptionGroup = []; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* PricePNRWithBookingClass13 constructor. |
|
53
|
|
|
* |
|
54
|
|
|
* @param FarePricePnrWithBookingClassOptions $options |
|
55
|
|
|
* @throws MessageVersionUnsupportedException |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct(FarePricePnrWithBookingClassOptions $options) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->pricingOptionGroup = $this->loadPricingOptionsFromRequestOptions($options); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Load an array of PricingOptionGroup objects from the Pricing request options. |
|
64
|
|
|
* |
|
65
|
|
|
* Extracted because this method is also used in the InformativePricingWithoutPnr messages. |
|
66
|
|
|
* |
|
67
|
|
|
* @param FarePricePnrWithBookingClassOptions $options |
|
68
|
|
|
* @return PricingOptionGroup[] |
|
69
|
|
|
*/ |
|
70
|
|
|
public static function loadPricingOptionsFromRequestOptions(FarePricePnrWithBookingClassOptions $options) |
|
71
|
|
|
{ |
|
72
|
|
|
$priceOptions = []; |
|
73
|
|
|
|
|
74
|
|
|
if ($options->validatingCarrier !== null) { |
|
75
|
|
|
$priceOptions[] = self::makePricingOptionForValidatingCarrier($options->validatingCarrier); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ($options->currencyOverride !== null) { |
|
79
|
|
|
$priceOptions[] = self::makePricingOptionForCurrencyOverride($options->currencyOverride); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($options->pricingsFareBasis !== null) { |
|
83
|
|
|
foreach ($options->pricingsFareBasis as $pricingFareBasis) { |
|
84
|
|
|
$priceOptions[] = self::makePricingOptionFareBasisOverride($pricingFareBasis); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if (!empty($options->overrideOptions)) { |
|
89
|
|
|
foreach ($options->overrideOptions as $overrideOption) { |
|
90
|
|
|
if (!self::hasPricingGroup($overrideOption, $priceOptions)) { |
|
91
|
|
|
$priceOptions[] = new PricingOptionGroup($overrideOption); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// All options processed, no options found: |
|
97
|
|
|
if (empty($priceOptions)) { |
|
98
|
|
|
$priceOptions[] = new PricingOptionGroup(PricingOptionKey::OPTION_NO_OPTION); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return $priceOptions; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param string $validatingCarrier |
|
106
|
|
|
* @return PricePnr13\PricingOptionGroup |
|
107
|
|
|
*/ |
|
108
|
|
|
protected static function makePricingOptionForValidatingCarrier($validatingCarrier) |
|
109
|
|
|
{ |
|
110
|
|
|
$po = new PricingOptionGroup(PricingOptionKey::OPTION_VALIDATING_CARRIER); |
|
111
|
|
|
|
|
112
|
|
|
$po->carrierInformation = new CarrierInformation($validatingCarrier); |
|
113
|
|
|
|
|
114
|
|
|
return $po; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param string $currency |
|
119
|
|
|
* @return PricePnr13\PricingOptionGroup |
|
120
|
|
|
*/ |
|
121
|
|
|
protected static function makePricingOptionForCurrencyOverride($currency) |
|
122
|
|
|
{ |
|
123
|
|
|
$po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_CURRENCY_OVERRIDE); |
|
124
|
|
|
|
|
125
|
|
|
$po->currency = new Currency($currency, FirstCurrencyDetails::QUAL_CURRENCY_OVERRIDE); |
|
126
|
|
|
|
|
127
|
|
|
return $po; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param PricePnrBcFareBasis $pricingFareBasis |
|
132
|
|
|
* @return PricePnr13\PricingOptionGroup |
|
133
|
|
|
*/ |
|
134
|
|
|
protected static function makePricingOptionFareBasisOverride($pricingFareBasis) |
|
135
|
|
|
{ |
|
136
|
|
|
$po = new PricingOptionGroup(PricingOptionKey::OPTION_FARE_BASIS_SIMPLE_OVERRIDE); |
|
137
|
|
|
|
|
138
|
|
|
$po->optionDetail = new OptionDetail(); |
|
139
|
|
|
$po->optionDetail->criteriaDetails[] = new CriteriaDetails( |
|
140
|
|
|
$pricingFareBasis->fareBasisPrimaryCode . $pricingFareBasis->fareBasisCode |
|
141
|
|
|
); |
|
142
|
|
|
|
|
143
|
|
|
$po->paxSegTstReference = new PaxSegTstReference($pricingFareBasis->segmentReference); |
|
144
|
|
|
|
|
145
|
|
|
return $po; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Avoid double pricing groups when combining an explicitly provided override option with a specific parameter |
|
150
|
|
|
* that uses the same override option. |
|
151
|
|
|
* |
|
152
|
|
|
* Backwards compatibility with PricePnrWithBookingClass12 |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $optionKey |
|
155
|
|
|
* @param PricingOptionGroup[] $priceOptions |
|
156
|
|
|
* @return bool |
|
157
|
|
|
*/ |
|
158
|
|
|
protected static function hasPricingGroup($optionKey, $priceOptions) |
|
159
|
|
|
{ |
|
160
|
|
|
$found = false; |
|
161
|
|
|
|
|
162
|
|
|
foreach ($priceOptions as $pog) { |
|
163
|
|
|
if ($pog->pricingOptionKey->pricingOptionKey === $optionKey) { |
|
164
|
|
|
$found = true; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
return $found; |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|