Completed
Push — master ( 8f168b...4b1795 )
by Dieter
09:49
created

ConfirmHotel::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
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\Offer;
24
25
use Amadeus\Client\RequestOptions\OfferConfirmHotelOptions;
26
use Amadeus\Client\RequestOptions\Offer\PaymentDetails as PaymentDetailsOptions;
27
use Amadeus\Client\Struct\BaseWsMessage;
28
use Amadeus\Client\Struct\InvalidArgumentException;
29
use Amadeus\Client\Struct\Offer\ConfirmHotel\BookingSource;
30
use Amadeus\Client\Struct\Offer\ConfirmHotel\GlobalBookingInfo;
31
use Amadeus\Client\Struct\Offer\ConfirmHotel\GroupCreditCardInfo;
32
use Amadeus\Client\Struct\Offer\ConfirmHotel\GuaranteeOrDeposit;
33
use Amadeus\Client\Struct\Offer\ConfirmHotel\PaymentDetails;
34
use Amadeus\Client\Struct\Offer\ConfirmHotel\PaymentInfo;
35
use Amadeus\Client\Struct\Offer\ConfirmHotel\PnrInfo;
36
use Amadeus\Client\Struct\Offer\ConfirmHotel\Reservation;
37
use Amadeus\Client\Struct\Offer\ConfirmHotel\RoomList;
38
use Amadeus\Client\Struct\Offer\ConfirmHotel\RoomStayData;
39
use Amadeus\Client\Struct\Offer\ConfirmHotel\TattooReference;
40
41
/**
42
 * Offer_ConfirmHotelOffer
43
 *
44
 * @package Amadeus\Client\Struct\Offer
45
 * @author Dieter Devlieghere <[email protected]>
46
 */
47
class ConfirmHotel extends BaseWsMessage
48
{
49
    /**
50
     * @var ConfirmHotel\PnrInfo
51
     */
52
    public $pnrInfo;
53
54
    /**
55
     * @var mixed
56
     */
57
    public $groupIndicator;
58
59
    /**
60
     * @var mixed
61
     */
62
    public $travelAgentRef;
63
64
    /**
65
     * @var ConfirmHotel\RoomStayData[]
66
     */
67
    public $roomStayData = [];
68
69
    /**
70
     * @var mixed
71
     */
72
    public $arrivalFlightDetailsGrp;
73
74
    /**
75
     * ConfirmHotel constructor.
76
     *
77
     * @param OfferConfirmHotelOptions $params
78
     */
79 4
    public function __construct(OfferConfirmHotelOptions $params)
80
    {
81 4
        if (!empty($params->recordLocator)) {
82 3
            $this->pnrInfo = new PnrInfo($params->recordLocator, null, Reservation::CONTROLTYPE_PNR_IDENTIFICATION);
83 3
        }
84
85 4
        $this->loadRoomStayData($params);
86 4
        $this->loadPaymentInfo($params);
87 3
    }
88
89
    /**
90
     * Check for existence of RoomStayData and create if needed.
91
     *
92
     * @return void
93
     */
94 3
    protected function makeRoomStayData()
95
    {
96 3
        if (!isset($this->roomStayData[0])) {
97 3
            $this->roomStayData[] = new RoomStayData();
98 3
        }
99 3
    }
100
101
    /**
102
     * @param OfferConfirmHotelOptions $params
103
     */
104 4
    protected function loadPaymentInfo(OfferConfirmHotelOptions $params)
105
    {
106 4
        if ($this->checkAllNotEmpty($params->paymentType, $params->formOfPayment) &&
107 3
            $params->paymentDetails instanceof PaymentDetailsOptions
108 4
        ) {
109 3
            $this->makeRoomStayData();
110 3
            $this->roomStayData[0]->roomList[] = new RoomList();
111
112 3
            $this->roomStayData[0]->roomList[0]->guaranteeOrDeposit = new GuaranteeOrDeposit();
113 3
            $this->roomStayData[0]->roomList[0]->guaranteeOrDeposit->paymentInfo = new PaymentInfo(
114 3
                $params->paymentType,
115 3
                $params->formOfPayment
116 3
            );
117
118 3
            if ($params->formOfPayment === PaymentDetails::FOP_CREDIT_CARD) {
119 2
                $this->roomStayData[0]->roomList[0]->guaranteeOrDeposit->groupCreditCardInfo = new GroupCreditCardInfo(
120 2
                    $params->paymentDetails->ccVendor,
121 2
                    $params->paymentDetails->ccCardHolder,
122 2
                    $params->paymentDetails->ccCardNumber,
123 2
                    $params->paymentDetails->ccExpiry
124 2
                );
125 2
            } else {
126 1
                throw new InvalidArgumentException(
127 2
                    'Hotel Offer Confirm Form of Payment ' . $params->formOfPayment . ' is not yet supported'
128 1
                );
129
            }
130 2
        }
131 3
    }
132
133
    /**
134
     * @param OfferConfirmHotelOptions $params
135
     */
136 4
    protected function loadRoomStayData(OfferConfirmHotelOptions $params)
137
    {
138 4
        if (!empty($params->offerReference)) {
139 3
            $this->makeRoomStayData();
140 3
            $this->roomStayData[0]->tattooReference = new TattooReference($params->offerReference);
141 3
        }
142
143 4
        if (!empty($params->passengers)) {
144 2
            $this->makeRoomStayData();
145 2
            $this->roomStayData[0]->globalBookingInfo = new GlobalBookingInfo($params->passengers);
146 2
        }
147
148 4
        if (!empty($params->originatorId)) {
149 3
            $this->makeRoomStayData();
150 3
            if (!($this->roomStayData[0]->globalBookingInfo instanceof GlobalBookingInfo)) {
151 1
                $this->roomStayData[0]->globalBookingInfo = new GlobalBookingInfo();
152 1
            }
153
154 3
            $this->roomStayData[0]->globalBookingInfo->bookingSource = new BookingSource($params->originatorId);
155 3
        }
156 4
    }
157
}
158