Completed
Push — master ( 83dd31...9c77e3 )
by Dieter
08:50
created

MopDescription::loadPaymentModule()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 25
ccs 21
cts 21
cp 1
rs 8.8571
cc 3
eloc 18
nc 3
nop 1
crap 3
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\Fop;
24
25
use Amadeus\Client\RequestOptions\Fop\MopInfo;
26
use Amadeus\Client\Struct\Fop\CreateFormOfPayment\MopDescription14;
27
use Amadeus\Client\Struct\Fop\CreateFormOfPayment\PaymentModule14;
28
use Amadeus\Client\Struct\WsMessageUtility;
29
30
/**
31
 * MopDescription
32
 *
33
 * @package Amadeus\Client\Struct\Fop
34
 * @author Dieter Devlieghere <[email protected]>
35
 */
36
class MopDescription extends WsMessageUtility
37
{
38
    /**
39
     * @var FopSequenceNumber
40
     */
41
    public $fopSequenceNumber;
42
    /**
43
     * @var FopMasterElementReference
44
     */
45
    public $fopMasterElementReference;
46
    /**
47
     * @var StakeholderPayerReference
48
     */
49
    public $stakeholderPayerReference;
50
    /**
51
     * @var MopDetails
52
     */
53
    public $mopDetails;
54
    /**
55
     * @var PaymentModule
56
     */
57
    public $paymentModule;
58
59
    /**
60
     * MopDescription constructor.
61
     *
62
     * @param MopInfo $options
63
     */
64 68
    public function __construct(MopInfo $options)
65
    {
66 68
        if (!is_null($options->sequenceNr)) {
67 68
            $this->fopSequenceNumber = new FopSequenceNumber($options->sequenceNr);
68 34
        }
69
70 68
        $this->loadMopDetails($options);
71
72 68
        $this->loadPaymentModule($options);
73 68
    }
74
75
    /**
76
     * load Method of Payment Details
77
     *
78
     * @param MopInfo $options
79
     */
80 68
    protected function loadMopDetails(MopInfo $options)
81 2
    {
82 68
        $this->mopDetails = new MopDetails();
83
84 68
        if ($this->checkAnyNotEmpty($options->fopCode, $options->fopStatus)) {
85 68
            $this->mopDetails->fopPNRDetails = new FopPNRDetails(
86 68
                $options->fopCode,
87 68
                $options->fopStatus
88 34
            );
89 34
        }
90
91 68
        if (!empty($options->freeFlowText)) {
92 8
            $this->mopDetails->oldFopFreeflow = new OldFopFreeflow(
93 8
                $options->freeFlowText,
94 8
                $options->freeFlowEncoding
95 4
            );
96 4
        }
97
98 68 View Code Duplication
        if (!empty($options->supplementaryData)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99 8
            $this->mopDetails->pnrSupplementaryData[] = new PnrSupplementaryData(
100 8
                DataAndSwitchMap::TYPE_DATA_INFORMATION,
101 8
                $options->supplementaryData
102 6
            );
103 4
        }
104 68 View Code Duplication
        if (!empty($options->supplementarySwitches)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105 4
            $this->mopDetails->pnrSupplementaryData[] = new PnrSupplementaryData(
106 4
                DataAndSwitchMap::TYPE_SWITCH_INFORMATION,
107 4
                $options->supplementarySwitches
108 2
            );
109 2
        }
110 68
    }
111
112
    /**
113
     * Payment Module information
114
     *
115
     * @param MopInfo $options
116
     */
117 68
    protected function loadPaymentModule(MopInfo $options)
118
    {
119 68
        if ($this->checkAnyNotEmpty(
120 68
            $options->fopType,
121 68
            $options->payMerchant,
122 68
            $options->payments,
123 68
            $options->installmentsInfo,
124 68
            $options->mopPaymentType,
125 68
            $options->creditCardInfo,
126 68
            $options->fraudScreening,
127 68
            $options->payIds,
128 68
            $options->paySupData
129 34
        )) {
130 60
            if ($this instanceof MopDescription14) {
131 8
                $this->paymentModule = new PaymentModule14($options->fopType);
132 4
            } else {
133 52
                $this->paymentModule = new PaymentModule($options->fopType);
134
            }
135 60
            $this->paymentModule->loadPaymentData($options);
136
137 60
            $this->loadMopInformation($options);
138
139 60
            $this->loadPaymentSupplementaryData($options);
140 30
        }
141 68
    }
142
143
    /**
144
     * Load Supplementary data
145
     *
146
     * @param MopInfo $options
147
     */
148 60
    protected function loadPaymentSupplementaryData(MopInfo $options)
149
    {
150 60
        foreach ($options->paySupData as $paySupData) {
151 4
            $this->paymentModule->paymentSupplementaryData[] = new PaymentSupplementaryData(
152 4
                $paySupData->function,
153 4
                $paySupData->data
154 2
            );
155 30
        }
156 60
    }
157
158
    /**
159
     * Load MopInformation
160
     *
161
     * @param MopInfo $options
162
     */
163 60
    protected function loadMopInformation(MopInfo $options)
164
    {
165 60
        if (!empty($options->mopPaymentType)) {
166 48
            $this->checkAndCreateMopInformation();
167 48
            $this->paymentModule->mopInformation->fopInformation = new FopInformation($options->mopPaymentType);
168 24
        }
169
170 60
        if (!empty($options->creditCardInfo)) {
171 44
            $this->checkAndCreateMopInformation();
172 44
            $this->paymentModule->mopInformation->creditCardData = new CreditCardData($options->creditCardInfo);
173 44
            if ($this->checkAnyNotEmpty(
174 44
                $options->creditCardInfo->approvalCode,
175 44
                $options->creditCardInfo->threeDSecure
176 22
            )
177 22
            ) {
178 16
                $this->checkAndCreateMopDetailedData($options->fopType);
179 16
                $this->paymentModule->mopDetailedData->creditCardDetailedData = new CreditCardDetailedData(
180 16
                    $options->creditCardInfo->approvalCode,
181 16
                    $options->creditCardInfo->sourceOfApproval,
182 16
                    $options->creditCardInfo->threeDSecure
183 8
                );
184 8
            }
185 22
        }
186
187 60
        if (!empty($options->invoiceInfo)) {
188 4
            $this->checkAndCreateMopInformation();
189 4
            $this->paymentModule->mopInformation->invoiceDataGroup = new InvoiceDataGroup($options->invoiceInfo);
190 2
        }
191 60
    }
192
193
194
    /**
195
     * Create MopInformation node if needed
196
     */
197 48
    private function checkAndCreateMopInformation()
198
    {
199 48
        if (is_null($this->paymentModule->mopInformation)) {
200 48
            $this->paymentModule->mopInformation = new MopInformation();
201 24
        }
202 48
    }
203
204
    /**
205
     * Create MopDetailedData node if needed
206
     *
207
     * @param string $fopType
208
     */
209 16
    private function checkAndCreateMopDetailedData($fopType)
210
    {
211 16
        if (is_null($this->paymentModule->mopDetailedData)) {
212 16
            $this->paymentModule->mopDetailedData = new MopDetailedData($fopType);
213 8
        }
214 16
    }
215
}
216