1 | <?php |
||
2 | |||
3 | /** |
||
4 | * MIT License |
||
5 | * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerEco\Zed\Ratepay\Business\Api\Mapper; |
||
9 | |||
10 | use Generated\Shared\Transfer\OrderTransfer; |
||
0 ignored issues
–
show
|
|||
11 | use Generated\Shared\Transfer\QuoteTransfer; |
||
0 ignored issues
–
show
The type
Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
12 | use Generated\Shared\Transfer\RatepayPaymentInitTransfer; |
||
0 ignored issues
–
show
The type
Generated\Shared\Transfe...epayPaymentInitTransfer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
13 | use Generated\Shared\Transfer\RatepayPaymentRequestTransfer; |
||
0 ignored issues
–
show
The type
Generated\Shared\Transfe...yPaymentRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
14 | use Spryker\Shared\Shipment\ShipmentConstants; |
||
0 ignored issues
–
show
The type
Spryker\Shared\Shipment\ShipmentConstants was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
15 | |||
16 | class QuotePaymentRequestMapper extends BaseMapper |
||
17 | { |
||
18 | /** |
||
19 | * @var \Generated\Shared\Transfer\RatepayPaymentRequestTransfer |
||
20 | */ |
||
21 | protected $ratepayPaymentRequestTransfer; |
||
22 | |||
23 | /** |
||
24 | * @var \Generated\Shared\Transfer\QuoteTransfer |
||
25 | */ |
||
26 | protected $quoteTransfer; |
||
27 | |||
28 | /** |
||
29 | * @var \Generated\Shared\Transfer\OrderTransfer |
||
30 | */ |
||
31 | protected $partialOrderTransfer; |
||
32 | |||
33 | /** |
||
34 | * @var \Generated\Shared\Transfer\RatepayPaymentInitTransfer |
||
35 | */ |
||
36 | protected $ratepayPaymentInitTransfer; |
||
37 | |||
38 | /** |
||
39 | * @var \Generated\Shared\Transfer\RatepayPaymentElvTransfer|\Generated\Shared\Transfer\RatepayPaymentInstallmentTransfer|\Generated\Shared\Transfer\RatepayPaymentInvoiceTransfer|\Generated\Shared\Transfer\RatepayPaymentPrepaymentTransfer |
||
0 ignored issues
–
show
The type
Generated\Shared\Transfe...ymentPrepaymentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
The type
Generated\Shared\Transfe...tepayPaymentElvTransfer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
The type
Generated\Shared\Transfe...yPaymentInvoiceTransfer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
The type
Generated\Shared\Transfe...mentInstallmentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
40 | */ |
||
41 | protected $paymentData; |
||
42 | |||
43 | /** |
||
44 | * @param \Generated\Shared\Transfer\RatepayPaymentRequestTransfer $ratepayPaymentRequestTransfer |
||
45 | * @param \Generated\Shared\Transfer\RatepayPaymentInitTransfer $ratepayPaymentInitTransfer |
||
46 | * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
||
47 | * @param \Generated\Shared\Transfer\OrderTransfer $partialOrderTransfer |
||
48 | * @param \Generated\Shared\Transfer\RatepayPaymentElvTransfer|\Generated\Shared\Transfer\RatepayPaymentInstallmentTransfer|\Generated\Shared\Transfer\RatepayPaymentInvoiceTransfer|\Generated\Shared\Transfer\RatepayPaymentPrepaymentTransfer $paymentData |
||
49 | */ |
||
50 | public function __construct( |
||
51 | RatepayPaymentRequestTransfer $ratepayPaymentRequestTransfer, |
||
52 | RatepayPaymentInitTransfer $ratepayPaymentInitTransfer, |
||
53 | QuoteTransfer $quoteTransfer, |
||
54 | OrderTransfer $partialOrderTransfer, |
||
55 | $paymentData |
||
56 | ) { |
||
57 | $this->ratepayPaymentRequestTransfer = $ratepayPaymentRequestTransfer; |
||
58 | $this->ratepayPaymentInitTransfer = $ratepayPaymentInitTransfer; |
||
59 | $this->quoteTransfer = $quoteTransfer; |
||
60 | $this->partialOrderTransfer = $partialOrderTransfer; |
||
61 | $this->paymentData = $paymentData; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return void |
||
66 | */ |
||
67 | public function map() |
||
68 | { |
||
69 | $this->mapPaymentInfo(); |
||
70 | $this->mapCustomer(); |
||
71 | $this->mapTotals(); |
||
72 | $this->mapExpenses(); |
||
73 | $this->mapAddresses(); |
||
74 | $this->mapBankAccountBic(); |
||
75 | $this->mapBankAccountIban(); |
||
76 | $this->mapDebitPayType(); |
||
77 | $this->mapInstallmentGrandTotalAmount(); |
||
78 | $this->mapInstallmentNumberRates(); |
||
79 | $this->mapInstallmentRate(); |
||
80 | $this->mapInstallmentLastRate(); |
||
81 | $this->mapInstallmentInterestRate(); |
||
82 | $this->mapInstallmentPaymentFirstDay(); |
||
83 | $this->mapBasketItems(); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return void |
||
88 | */ |
||
89 | protected function mapPaymentInfo() |
||
90 | { |
||
91 | $this->ratepayPaymentRequestTransfer |
||
92 | ->setRatepayPaymentInit($this->ratepayPaymentInitTransfer) |
||
93 | ->setPaymentType($this->paymentData->getPaymentType()) |
||
94 | ->setCurrencyIso3($this->paymentData->getCurrencyIso3()); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @return void |
||
99 | */ |
||
100 | protected function mapCustomer() |
||
101 | { |
||
102 | $customerTransfer = $this->quoteTransfer->requireCustomer()->getCustomer(); |
||
103 | $this->ratepayPaymentRequestTransfer |
||
104 | ->setCustomerEmail($customerTransfer->getEmail()) |
||
105 | ->setCustomerPhone($this->paymentData->getPhone()) |
||
106 | ->setCustomerAllowCreditInquiry($this->paymentData->getCustomerAllowCreditInquiry()) |
||
107 | ->setGender($this->paymentData->getGender()) |
||
108 | ->setDateOfBirth($this->paymentData->getDateOfBirth()) |
||
109 | ->setIpAddress($this->paymentData->getIpAddress()); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @return void |
||
114 | */ |
||
115 | protected function mapTotals() |
||
116 | { |
||
117 | $totalsTransfer = $this->quoteTransfer->requireTotals()->getTotals(); |
||
118 | $this->ratepayPaymentRequestTransfer |
||
119 | ->setGrandTotal($totalsTransfer->requireGrandTotal()->getGrandTotal()) |
||
120 | ->setShippingExpenseTotal($this->getShippingExpenseTotal()) |
||
121 | ->setExpenseTotal($totalsTransfer->requireExpenseTotal()->getExpenseTotal()); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * @return int |
||
126 | */ |
||
127 | protected function getShippingExpenseTotal() |
||
128 | { |
||
129 | $shippingExpenses = 0; |
||
130 | foreach ($this->quoteTransfer->getExpenses() as $expenseTransfer) { |
||
131 | if ($expenseTransfer->getType() === ShipmentConstants::SHIPMENT_EXPENSE_TYPE) { |
||
132 | $shippingExpenses += $expenseTransfer->getUnitGrossPrice(); |
||
133 | } |
||
134 | } |
||
135 | |||
136 | return $shippingExpenses; |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * @return void |
||
141 | */ |
||
142 | protected function mapAddresses() |
||
143 | { |
||
144 | $billingAddress = $this->quoteTransfer->getBillingAddress(); |
||
145 | $shippingAddress = $this->quoteTransfer->getShippingAddress(); |
||
146 | |||
147 | $this->ratepayPaymentRequestTransfer |
||
148 | ->setBillingAddress($billingAddress) |
||
149 | ->setShippingAddress($shippingAddress) |
||
150 | ->setBankAccountHolder($billingAddress->getFirstName() . " " . $billingAddress->getLastName()); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * @return void |
||
155 | */ |
||
156 | protected function mapExpenses() |
||
157 | { |
||
158 | $maxTaxRate = 0; |
||
159 | $expenses = $this->quoteTransfer->getExpenses(); |
||
160 | |||
161 | foreach ($expenses as $expense) { |
||
162 | $maxTaxRate = ($expense->getTaxRate() > $maxTaxRate) ? $expense->getTaxRate() : $maxTaxRate; |
||
163 | } |
||
164 | |||
165 | $this->ratepayPaymentRequestTransfer |
||
166 | ->setShippingTaxRate($maxTaxRate); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @return void |
||
171 | */ |
||
172 | protected function mapBankAccountBic() |
||
173 | { |
||
174 | if (method_exists($this->paymentData, 'getBankAccountBic')) { |
||
175 | $this->ratepayPaymentRequestTransfer |
||
176 | ->setBankAccountBic($this->paymentData->getBankAccountBic()); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @return void |
||
182 | */ |
||
183 | protected function mapBankAccountIban() |
||
184 | { |
||
185 | if (method_exists($this->paymentData, 'getBankAccountIban')) { |
||
186 | $this->ratepayPaymentRequestTransfer |
||
187 | ->setBankAccountIban($this->paymentData->getBankAccountIban()); |
||
188 | } |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @return void |
||
193 | */ |
||
194 | protected function mapDebitPayType() |
||
195 | { |
||
196 | if (method_exists($this->paymentData, 'getDebitPayType')) { |
||
197 | $this->ratepayPaymentRequestTransfer |
||
198 | ->setDebitPayType($this->paymentData->getDebitPayType()); |
||
199 | } |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @return void |
||
204 | */ |
||
205 | protected function mapInstallmentNumberRates() |
||
206 | { |
||
207 | if (method_exists($this->paymentData, 'getInstallmentNumberRates')) { |
||
208 | $this->ratepayPaymentRequestTransfer |
||
209 | ->setInstallmentNumberRates($this->paymentData->getInstallmentNumberRates()); |
||
210 | } |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * @return void |
||
215 | */ |
||
216 | protected function mapInstallmentRate() |
||
217 | { |
||
218 | if (method_exists($this->paymentData, 'getInstallmentRate')) { |
||
219 | $this->ratepayPaymentRequestTransfer |
||
220 | ->setInstallmentRate($this->paymentData->getInstallmentRate()); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * @return void |
||
226 | */ |
||
227 | protected function mapInstallmentLastRate() |
||
228 | { |
||
229 | if (method_exists($this->paymentData, 'getInstallmentLastRate')) { |
||
230 | $this->ratepayPaymentRequestTransfer |
||
231 | ->setInstallmentLastRate($this->paymentData->getInstallmentLastRate()); |
||
232 | } |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @return void |
||
237 | */ |
||
238 | protected function mapInstallmentInterestRate() |
||
239 | { |
||
240 | if (method_exists($this->paymentData, 'getInstallmentInterestRate')) { |
||
241 | $this->ratepayPaymentRequestTransfer |
||
242 | ->setInstallmentInterestRate($this->paymentData->getInstallmentInterestRate()); |
||
243 | } |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @return void |
||
248 | */ |
||
249 | protected function mapInstallmentPaymentFirstDay() |
||
250 | { |
||
251 | if (method_exists($this->paymentData, 'getInstallmentPaymentFirstDay')) { |
||
252 | $this->ratepayPaymentRequestTransfer |
||
253 | ->setInstallmentPaymentFirstDay($this->paymentData->getInstallmentPaymentFirstDay()); |
||
254 | } |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * @return void |
||
259 | */ |
||
260 | protected function mapInstallmentGrandTotalAmount() |
||
261 | { |
||
262 | if ($this->quoteTransfer->getPayment()->getRatepayInstallment()) { |
||
263 | $this->ratepayPaymentRequestTransfer |
||
264 | ->setInstallmentGrandTotalAmount( |
||
265 | $this->quoteTransfer |
||
266 | ->getPayment() |
||
267 | ->getRatepayInstallment() |
||
268 | ->getInstallmentGrandTotalAmount() |
||
269 | ); |
||
270 | } |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * @return void |
||
275 | */ |
||
276 | protected function mapBasketItems() |
||
277 | { |
||
278 | $basketItems = $this->quoteTransfer->getItems(); |
||
279 | $grouppedItems = []; |
||
280 | $discountTaxRate = 0; |
||
281 | foreach ($basketItems as $basketItem) { |
||
282 | if (isset($grouppedItems[$basketItem->getGroupKey()])) { |
||
283 | $grouppedItems[$basketItem->getGroupKey()]->setQuantity($grouppedItems[$basketItem->getGroupKey()]->getQuantity() + 1); |
||
284 | } else { |
||
285 | $grouppedItems[$basketItem->getGroupKey()] = clone $basketItem; |
||
286 | } |
||
287 | if ($discountTaxRate < $basketItem->getTaxRate()) { // take max taxRate |
||
288 | $discountTaxRate = $basketItem->getTaxRate(); |
||
289 | } |
||
290 | } |
||
291 | $discountTotal = $this->partialOrderTransfer->getTotals()->getDiscountTotal(); |
||
292 | $this->ratepayPaymentRequestTransfer |
||
293 | ->setDiscountTotal($discountTotal) |
||
294 | ->setDiscountTaxRate($discountTaxRate); |
||
295 | |||
296 | foreach ($grouppedItems as $basketItem) { |
||
297 | $this->ratepayPaymentRequestTransfer->addItem($basketItem); |
||
298 | } |
||
299 | } |
||
300 | } |
||
301 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths