Completed
Push — master ( dcb951...0b0e41 )
by Dieter
07:13
created

PricePNRWithBookingClass12::loadCurrencyOverride()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
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\RequestOptions\Fare\PricePnr\PaxSegRef;
26
use Amadeus\Client\RequestOptions\FarePricePnrWithBookingClassOptions;
27
use Amadeus\Client\RequestOptions\FarePricePnrWithLowerFaresOptions as LowerFareOpt;
28
use Amadeus\Client\RequestOptions\FarePricePnrWithLowestFareOptions as LowestFareOpt;
29
use Amadeus\Client\Struct\BaseWsMessage;
30
use Amadeus\Client\Struct\Fare\PricePnr12\AttributeDetails;
31
use Amadeus\Client\Struct\Fare\PricePnr12\CarrierAgreements;
32
use Amadeus\Client\Struct\Fare\PricePnr12\CityDetail;
33
use Amadeus\Client\Struct\Fare\PricePnr12\CurrencyOverride;
34
use Amadeus\Client\Struct\Fare\PricePnr12\DateOverride;
35
use Amadeus\Client\Struct\Fare\PricePnr12\DiscountInformation;
36
use Amadeus\Client\Struct\Fare\PricePnr12\FrequentFlyerInformation;
37
use Amadeus\Client\Struct\Fare\PricePnr12\OverrideInformation;
38
use Amadeus\Client\Struct\Fare\PricePnr12\PenDisInformation;
39
use Amadeus\Client\Struct\Fare\PricePnr12\PricingFareBase;
40
use Amadeus\Client\Struct\Fare\PricePnr12\TaxDetails;
41
use Amadeus\Client\Struct\Fare\PricePnr12\ValidatingCarrier;
42
use Amadeus\Client\Struct\OptionNotSupportedException;
43
44
/**
45
 * Fare_PricePNRWithBookingClass v 12 and lower structure
46
 *
47
 * @package Amadeus\Client\Struct\Fare
48
 * @author dieter <[email protected]>
49
 */
50
class PricePNRWithBookingClass12 extends BaseWsMessage
51
{
52
    public $pnrLocatorData;
53
54
    /**
55
     * @var PricePnr12\PaxSegReference
56
     */
57
    public $paxSegReference;
58
59
    /**
60
     * @var PricePnr12\OverrideInformation
61
     */
62
    public $overrideInformation;
63
64
    /**
65
     * @var PricePnr12\DateOverride
66
     */
67
    public $dateOverride;
68
69
    /**
70
     * @var PricePnr12\ValidatingCarrier
71
     */
72
    public $validatingCarrier;
73
74
    /**
75
     * @var PricePnr12\CityOverride
76
     */
77
    public $cityOverride;
78
79
    /**
80
     * @var PricePnr12\CurrencyOverride
81
     */
82
    public $currencyOverride;
83
84
    /**
85
     * @var PricePnr12\TaxDetails[]
86
     */
87
    public $taxDetails = [];
88
89
    /**
90
     * @var PricePnr12\DiscountInformation[]
91
     */
92
    public $discountInformation = [];
93
    /**
94
     * @var PricePnr12\PricingFareBase[]
95
     */
96
    public $pricingFareBase = [];
97
98
    public $flightInformation;
99
100
    public $openSegmentsInformation;
101
102
    public $bookingClassSelection;
103
104
    public $fopInformation;
105
106
    /**
107
     * @var CarrierAgreements
108
     */
109
    public $carrierAgreements;
110
111
    /**
112
     * @var FrequentFlyerInformation
113
     */
114
    public $frequentFlyerInformation;
115
116
    public $instantPricingOption;
117
118
    /**
119
     * PricePNRWithBookingClass12 constructor.
120
     *
121
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt|null $options
122
     */
123
    public function __construct($options)
124
    {
125
        $this->overrideInformation = new OverrideInformation();
126
127
        if (!is_null($options)) {
128
            $this->loadPricingOptions($options);
129
        }
130
    }
131
132
    /**
133
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
134
     */
135
    protected function loadPricingOptions($options)
136
    {
137
        $this->checkUnsupportedOptions($options);
138
139
        $this->loadOverrideOptionsAndCorpFares($options);
140
141
        $this->loadCurrencyOverride($options->currencyOverride);
142
143
        $this->loadValidatingCarrier($options);
144
145
        $this->loadFareBasis($options);
146
147
        $this->loadPaxDiscount($options->paxDiscountCodes, $options->paxDiscountCodeRefs);
148
149
        $this->loadOverrideLocations($options);
150
151
        $this->loadTaxOptions($options);
152
153
        $this->loadReferences($options->references);
154
155
        $this->loadPastDate($options->pastDatePricing);
156
    }
157
158
    /**
159
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
160
     * @throws OptionNotSupportedException
161
     */
162
    protected function checkUnsupportedOptions($options)
163
    {
164
        if (!empty($options->obFees)) {
165
            throw new OptionNotSupportedException('OB Fees option not supported in version 12 or lower');
166
        }
167
168
        if (!empty($options->pricingLogic)) {
169
            throw new OptionNotSupportedException('Pricing Logic option not supported in version 12 or lower');
170
        }
171
    }
172
173
    /**
174
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
175
     */
176
    protected function loadOverrideOptionsAndCorpFares($options)
177
    {
178
        foreach ($options->overrideOptions as $overrideOption) {
179
            $this->overrideInformation->attributeDetails[] = new AttributeDetails($overrideOption);
180
        }
181
182
        if (!empty($options->ticketType)) {
183
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
184
                $this->convertTicketType($options->ticketType)
185
            );
186
        }
187
188
        if ($options->corporateNegoFare !== null) {
189
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
190
                AttributeDetails::OVERRIDE_FARETYPE_CORPNR,
191
                $options->corporateNegoFare
192
            );
193
        }
194
195
        if (!empty($options->corporateUniFares)) {
196
            $this->loadCorporateUniFares($options->corporateUniFares);
197
198
            if (!empty($options->awardPricing)) {
199
                $this->carrierAgreements = new CarrierAgreements($options->awardPricing->carrier);
200
                $this->frequentFlyerInformation = new FrequentFlyerInformation($options->awardPricing->tierLevel);
201
            }
202
        }
203
204
        //No Options?
205
        if (empty($this->overrideInformation->attributeDetails)) {
206
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
207
                AttributeDetails::OVERRIDE_NO_OPTION
208
            );
209
        }
210
    }
211
212
    /**
213
     * @param string|null $currencyOverride
214
     */
215
    protected function loadCurrencyOverride($currencyOverride)
216
    {
217
        if (!empty($currencyOverride)) {
218
            $this->currencyOverride = new CurrencyOverride($currencyOverride);
219
        }
220
    }
221
222
    /**
223
     * Convert new codes (Price PNR version 13+) to old format
224
     *
225
     * @param string $optionsTicketType
226
     * @return string|null
227
     */
228
    protected function convertTicketType($optionsTicketType)
229
    {
230
        $converted = null;
231
232
        $map = [
233
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_ELECTRONIC => AttributeDetails::OVERRIDE_ELECTRONIC_TICKET,
234
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_PAPER => AttributeDetails::OVERRIDE_PAPER_TICKET,
235
            FarePricePnrWithBookingClassOptions::TICKET_TYPE_BOTH => AttributeDetails::OVERRIDE_BOTH_TICKET,
236
        ];
237
238
        if (array_key_exists($optionsTicketType, $map)) {
239
            $converted = $map[$optionsTicketType];
240
        }
241
242
        return $converted;
243
    }
244
245
    /**
246
     * @param string[] $corporateUniFares
247
     */
248
    protected function loadCorporateUniFares($corporateUniFares)
249
    {
250
        foreach ($corporateUniFares as $corporateUniFare) {
251
            $this->overrideInformation->attributeDetails[] = new AttributeDetails(
252
                AttributeDetails::OVERRIDE_FARETYPE_CORPUNI,
253
                $corporateUniFare
254
            );
255
        }
256
    }
257
258
    /**
259
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
260
     */
261
    protected function loadOverrideLocations($options)
262
    {
263
        if (!empty($options->pointOfSaleOverride)) {
264
            $this->cityOverride = new PricePnr12\CityOverride(
265
                $options->pointOfSaleOverride,
266
                CityDetail::QUAL_POINT_OF_SALE
267
            );
268
        }
269
270
        if (!empty($options->pointOfTicketingOverride)) {
271
            if (empty($this->cityOverride)) {
272
                $this->cityOverride = new PricePnr12\CityOverride();
273
            }
274
            $this->cityOverride->cityDetail[] = new PricePnr12\CityDetail(
275
                $options->pointOfTicketingOverride,
276
                CityDetail::QUAL_POINT_OF_TICKETING
277
            );
278
        }
279
    }
280
281
    /**
282
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
283
     */
284
    protected function loadValidatingCarrier($options)
285
    {
286
        if (is_string($options->validatingCarrier)) {
287
            $this->validatingCarrier = new ValidatingCarrier($options->validatingCarrier);
288
        }
289
    }
290
291
    /**
292
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
293
     *
294
     */
295
    protected function loadFareBasis($options)
296
    {
297
        $short = AttributeDetails::OVERRIDE_FAREBASIS; //Short var name because I get complaints from phpcs. No judging.
298
        if (in_array($short, $options->overrideOptions) && !empty($options->pricingsFareBasis)) {
299
            foreach ($options->pricingsFareBasis as $pricingFareBasis) {
300
                $this->pricingFareBase[] = new PricingFareBase($pricingFareBasis);
301
            }
302
        }
303
    }
304
305
    /**
306
     * @param FarePricePnrWithBookingClassOptions|LowerFareOpt|LowestFareOpt $options
307
     */
308
    protected function loadTaxOptions($options)
309
    {
310
        foreach ($options->taxes as $tax) {
311
            $this->taxDetails[] = new TaxDetails($tax);
312
        }
313
314
        foreach ($options->exemptTaxes as $exemptTax) {
315
            $this->taxDetails[] = new TaxDetails($exemptTax);
316
        }
317
    }
318
319
    /**
320
     * @param string[] $paxDiscountCodes
321
     * @param PaxSegRef[] $refs
322
     */
323
    protected function loadPaxDiscount($paxDiscountCodes, $refs)
324
    {
325
        if (!empty($paxDiscountCodes)) {
326
            $this->discountInformation[] = new DiscountInformation(
327
                PenDisInformation::QUAL_DISCOUNT,
328
                $paxDiscountCodes,
329
                $refs
330
            );
331
        }
332
    }
333
334
    /**
335
     * @param PaxSegRef[] $references
336
     */
337
    protected function loadReferences($references)
338
    {
339
        if (!empty($references)) {
340
            $this->paxSegReference = new PricePnr12\PaxSegReference($references);
341
        }
342
    }
343
344
    /**
345
     * @param \DateTime|null $pastDate
346
     */
347
    protected function loadPastDate($pastDate)
348
    {
349
        if ($pastDate instanceof \DateTime) {
350
            $this->dateOverride = new DateOverride(DateOverride::OPT_DATE_OVERRIDE, $pastDate);
351
        }
352
    }
353
}
354