Passed
Push — master ( b846fe...52bca8 )
by
unknown
07:07
created

getStringDecimalExpenseVatAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\AfterPay\Business\Payment\Mapper;
9
10
use Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...uthorizeRequestTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Generated\Shared\Transfer\AfterPayCallTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AfterPayCallTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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\AfterPayCancelRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ayCancelRequestTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

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\AfterPayCaptureRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yCaptureRequestTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\Transfer\AfterPayRefundRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ayRefundRequestTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Generated\Shared\Transfer\AfterPayRequestAddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yRequestAddressTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Generated\Shared\Transfer\AfterPayRequestCustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...RequestCustomerTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Generated\Shared\Transfer\AfterPayRequestOrderItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...equestOrderItemTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Generated\Shared\Transfer\AfterPayRequestOrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PayRequestOrderTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Generated\Shared\Transfer\AfterPayRequestPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...yRequestPaymentTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Generated\Shared\Transfer\ExpenseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ExpenseTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use SprykerEco\Shared\AfterPay\AfterPayConfig as AfterPayConfigShared;
24
use SprykerEco\Zed\AfterPay\AfterPayConfig as AfterPayConfigZed;
25
use SprykerEco\Zed\AfterPay\Business\Payment\Transaction\PriceToPayProviderInterface;
26
use SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToMoneyFacadeInterface;
27
use SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToStoreFacadeInterface;
28
29
class OrderToRequestTransfer implements OrderToRequestTransferInterface
30
{
31
    public const NEGATIVE_MULTIPLIER = -1;
32
    public const GIFT_CARD_PROVIDER = 'GiftCard';
33
34
    protected const ZERO_AMOUNT = '0';
35
36
    protected const ORDER_ITEM_QUANTITY = 1;
37
    protected const SHIPPING_FEE_PROVIDER = 'ShippingFee';
38
39
    /**
40
     * @var \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToMoneyFacadeInterface
41
     */
42
    protected $moneyFacade;
43
44
    /**
45
     * @var \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToStoreFacadeInterface
46
     */
47
    protected $storeFacade;
48
49
    /**
50
     * @var array
51
     */
52
    protected static $paymentMethods = [
53
        AfterPayConfigShared::PAYMENT_METHOD_INVOICE => AfterPayConfigShared::PAYMENT_TYPE_INVOICE,
54
    ];
55
56
    /**
57
     * @var \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\PriceToPayProviderInterface
58
     */
59
    protected $priceToPayProvider;
60
61
    /**
62
     * @var \SprykerEco\Zed\AfterPay\AfterPayConfig
63
     */
64
    protected $config;
65
66
    /**
67
     * @param \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToMoneyFacadeInterface $moneyFacade
68
     * @param \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToStoreFacadeInterface $storeFacade
69
     * @param \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\PriceToPayProviderInterface $priceToPayProvider
70
     * @param \SprykerEco\Zed\AfterPay\AfterPayConfig $config
71
     */
72
    public function __construct(
73
        AfterPayToMoneyFacadeInterface $moneyFacade,
74
        AfterPayToStoreFacadeInterface $storeFacade,
75
        PriceToPayProviderInterface $priceToPayProvider,
76
        AfterPayConfigZed $config
77
    ) {
78
        $this->moneyFacade = $moneyFacade;
79
        $this->storeFacade = $storeFacade;
80
        $this->priceToPayProvider = $priceToPayProvider;
81
        $this->config = $config;
82
    }
83
84
    /**
85
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
86
     *
87
     * @return \Generated\Shared\Transfer\AfterPayAuthorizeRequestTransfer
88
     */
89
    public function orderToAuthorizeRequest(AfterPayCallTransfer $afterPayCallTransfer): AfterPayAuthorizeRequestTransfer
90
    {
91
        return (new AfterPayAuthorizeRequestTransfer())
92
            ->setPayment($this->buildPaymentRequestTransfer($afterPayCallTransfer))
93
            ->setCustomer($this->buildCustomerRequestTransfer($afterPayCallTransfer))
94
            ->setOrder($this->buildOrderWithItemsRequestTransfer($afterPayCallTransfer));
95
    }
96
97
    /**
98
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
99
     *
100
     * @return \Generated\Shared\Transfer\AfterPayCaptureRequestTransfer
101
     */
102
    public function orderToBaseCaptureRequest(AfterPayCallTransfer $afterPayCallTransfer): AfterPayCaptureRequestTransfer
103
    {
104
        $orderRequestTransfer = $this->buildOrderRequestTransfer($afterPayCallTransfer)
105
            ->setTotalGrossAmount(static::ZERO_AMOUNT)
106
            ->setTotalNetAmount(static::ZERO_AMOUNT);
107
108
        return (new AfterPayCaptureRequestTransfer())
109
            ->setOrderDetails($orderRequestTransfer);
110
    }
111
112
    /**
113
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
114
     *
115
     * @return \Generated\Shared\Transfer\AfterPayCancelRequestTransfer
116
     */
117
    public function orderToBaseCancelRequest(AfterPayCallTransfer $afterPayCallTransfer): AfterPayCancelRequestTransfer
118
    {
119
        $orderRequestTransfer = $this->buildOrderRequestTransfer($afterPayCallTransfer)
120
            ->setTotalGrossAmount(static::ZERO_AMOUNT)
121
            ->setTotalNetAmount(static::ZERO_AMOUNT);
122
123
        return (new AfterPayCancelRequestTransfer())
124
            ->setCancellationDetails($orderRequestTransfer);
125
    }
126
127
    /**
128
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
129
     *
130
     * @return \Generated\Shared\Transfer\AfterPayRefundRequestTransfer
131
     */
132
    public function orderToBaseRefundRequest(OrderTransfer $orderTransfer): AfterPayRefundRequestTransfer
133
    {
134
        return (new AfterPayRefundRequestTransfer())
135
            ->setIdSalesOrder($orderTransfer->getIdSalesOrder())
136
            ->setOrderNumber($orderTransfer->getOrderReference());
137
    }
138
139
    /**
140
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
141
     *
142
     * @return \Generated\Shared\Transfer\AfterPayRequestOrderItemTransfer
143
     */
144
    public function orderItemToAfterPayItemRequest(ItemTransfer $itemTransfer): AfterPayRequestOrderItemTransfer
145
    {
146
        return $this->buildOrderItemRequestTransfer($itemTransfer);
147
    }
148
149
    /**
150
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
151
     *
152
     * @return \Generated\Shared\Transfer\AfterPayRequestCustomerTransfer
153
     */
154
    protected function buildCustomerRequestTransfer(AfterPayCallTransfer $afterPayCallTransfer): AfterPayRequestCustomerTransfer
155
    {
156
        $billingAddressTransfer = $afterPayCallTransfer->getBillingAddress();
157
158
        return (new AfterPayRequestCustomerTransfer())
159
            ->setFirstName($billingAddressTransfer->getFirstName())
160
            ->setLastName($billingAddressTransfer->getLastName())
161
            ->setConversationalLanguage($this->getStoreCountryIso2())
162
            ->setCustomerCategory(AfterPayConfigShared::API_CUSTOMER_CATEGORY_PERSON)
163
            ->setSalutation($this->config->getSalutation($billingAddressTransfer->getSalutation()))
164
            ->setEmail($afterPayCallTransfer->getEmail())
165
            ->setAddress($this->buildCustomerBillingAddressRequestTransfer($afterPayCallTransfer));
166
    }
167
168
    /**
169
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
170
     *
171
     * @return \Generated\Shared\Transfer\AfterPayRequestOrderTransfer
172
     */
173
    protected function buildOrderWithItemsRequestTransfer(AfterPayCallTransfer $afterPayCallTransfer): AfterPayRequestOrderTransfer
174
    {
175
        $orderRequestTransfer = $this->buildOrderRequestTransfer($afterPayCallTransfer);
176
177
        foreach ($afterPayCallTransfer->getItems() as $itemTransfer) {
178
            $orderRequestTransfer->addItem(
179
                $this->buildOrderItemRequestTransfer($itemTransfer)
180
            );
181
        }
182
183
        $orderRequestTransfer = $this->addExpensesToOrderRequestTransfer($orderRequestTransfer, $afterPayCallTransfer);
184
        $orderRequestTransfer = $this->addGiftcardItems($orderRequestTransfer, $afterPayCallTransfer);
185
186
        return $orderRequestTransfer;
187
    }
188
189
    /**
190
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
191
     *
192
     * @return \Generated\Shared\Transfer\AfterPayRequestOrderTransfer
193
     */
194
    protected function buildOrderRequestTransfer(AfterPayCallTransfer $afterPayCallTransfer): AfterPayRequestOrderTransfer
195
    {
196
        return (new AfterPayRequestOrderTransfer())
197
            ->setNumber($afterPayCallTransfer->getOrderReference())
198
            ->setTotalNetAmount($this->getStringDecimalOrderNetTotal($afterPayCallTransfer))
199
            ->setTotalGrossAmount($this->getStringDecimalOrderGrossTotal($afterPayCallTransfer))
200
            ->setCurrency($afterPayCallTransfer->getCurrency());
201
    }
202
203
    /**
204
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
205
     *
206
     * @return \Generated\Shared\Transfer\AfterPayRequestPaymentTransfer
207
     */
208
    protected function buildPaymentRequestTransfer(AfterPayCallTransfer $afterPayCallTransfer): AfterPayRequestPaymentTransfer
209
    {
210
        return (new AfterPayRequestPaymentTransfer())
211
            ->setType(static::$paymentMethods[$afterPayCallTransfer->getPaymentMethod()] ?? null);
212
    }
213
214
    /**
215
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
216
     *
217
     * @return \Generated\Shared\Transfer\AfterPayRequestOrderItemTransfer
218
     */
219
    protected function buildOrderItemRequestTransfer(ItemTransfer $itemTransfer): AfterPayRequestOrderItemTransfer
220
    {
221
        return (new AfterPayRequestOrderItemTransfer())
222
            ->setProductId($itemTransfer->getSku())
223
            ->setDescription($itemTransfer->getName())
224
            ->setGrossUnitPrice($this->getStringDecimalItemGrossUnitPrice($itemTransfer))
225
            ->setQuantity($itemTransfer->getQuantity())
226
            ->setNetUnitPrice($this->getStringDecimalItemNetUnitPrice($itemTransfer))
227
            ->setVatAmount($this->getStringDecimalItemVatAmountPrice($itemTransfer))
228
            ->setVatPercent($itemTransfer->getTaxRate())
229
            ->setGroupId($itemTransfer->getGroupKey());
230
    }
231
232
    /**
233
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
234
     *
235
     * @return \Generated\Shared\Transfer\AfterPayRequestAddressTransfer
236
     */
237
    protected function buildCustomerBillingAddressRequestTransfer(AfterPayCallTransfer $afterPayCallTransfer): AfterPayRequestAddressTransfer
238
    {
239
        $customerAddressTransfer = $afterPayCallTransfer->getBillingAddress();
240
241
        return (new AfterPayRequestAddressTransfer())
242
            ->setCountryCode($customerAddressTransfer->getIso2Code())
243
            ->setStreet($customerAddressTransfer->getAddress1())
244
            ->setStreetNumber($customerAddressTransfer->getAddress2())
245
            ->setPostalCode($customerAddressTransfer->getZipCode())
246
            ->setPostalPlace($customerAddressTransfer->getCity());
247
    }
248
249
    /**
250
     * @return string
251
     */
252
    protected function getStoreCountryIso2(): string
253
    {
254
        return $this->storeFacade->getCurrentStore()->getName();
255
    }
256
257
    /**
258
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
259
     *
260
     * @return string
261
     */
262
    protected function getStringDecimalOrderGrossTotal(AfterPayCallTransfer $afterPayCallTransfer): string
263
    {
264
        $orderGrossTotal = $afterPayCallTransfer->getTotals()->getGrandTotal();
265
266
        return (string)$this->moneyFacade->convertIntegerToDecimal($orderGrossTotal);
267
    }
268
269
    /**
270
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
271
     *
272
     * @return string
273
     */
274
    protected function getStringDecimalOrderNetTotal(AfterPayCallTransfer $afterPayCallTransfer): string
275
    {
276
        $orderGrossTotal = $afterPayCallTransfer->getTotals()->getGrandTotal();
277
        $orderTaxTotal = $afterPayCallTransfer->getTotals()->getTaxTotal()->getAmount();
278
        $orderNetTotal = $orderGrossTotal - $orderTaxTotal;
279
280
        return (string)$this->moneyFacade->convertIntegerToDecimal($orderNetTotal);
281
    }
282
283
    /**
284
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
285
     *
286
     * @return string
287
     */
288
    protected function getStringDecimalItemGrossUnitPrice(ItemTransfer $itemTransfer): string
289
    {
290
        $itemUnitGrossPrice = $itemTransfer->getUnitPriceToPayAggregation();
291
292
        return (string)$this->moneyFacade->convertIntegerToDecimal($itemUnitGrossPrice);
293
    }
294
295
    /**
296
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
297
     *
298
     * @return string
299
     */
300
    protected function getStringDecimalItemNetUnitPrice(ItemTransfer $itemTransfer): string
301
    {
302
        $itemUnitGrossPriceAmount = $itemTransfer->getUnitPriceToPayAggregation();
303
        $itemUnitTaxAmount = $itemTransfer->getUnitTaxAmountFullAggregation();
304
        $itemUnitNetAmount = $itemUnitGrossPriceAmount - $itemUnitTaxAmount;
305
306
        return (string)$this->moneyFacade->convertIntegerToDecimal($itemUnitNetAmount);
307
    }
308
309
    /**
310
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
311
     *
312
     * @return string
313
     */
314
    protected function getStringDecimalItemVatAmountPrice(ItemTransfer $itemTransfer): string
315
    {
316
        $itemVatAmountPrice = $itemTransfer->getUnitTaxAmountFullAggregation();
317
318
        return (string)$this->moneyFacade->convertIntegerToDecimal($itemVatAmountPrice);
319
    }
320
321
    /**
322
     * @param \Generated\Shared\Transfer\AfterPayRequestOrderTransfer $orderRequestTransfer
323
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
324
     *
325
     * @return \Generated\Shared\Transfer\AfterPayRequestOrderTransfer
326
     */
327
    protected function addGiftcardItems(
328
        AfterPayRequestOrderTransfer $orderRequestTransfer,
329
        AfterPayCallTransfer $afterPayCallTransfer
330
    ): AfterPayRequestOrderTransfer {
331
        foreach ($this->getGiftcards($afterPayCallTransfer) as $index => $paymentTransfer) {
332
            $amount = (string)$this->moneyFacade
333
                ->convertIntegerToDecimal(static::NEGATIVE_MULTIPLIER * $paymentTransfer->getAmount());
334
335
            $orderRequestTransfer->addItem(
336
                (new AfterPayRequestOrderItemTransfer())
337
                    ->setProductId(static::GIFT_CARD_PROVIDER . $index)
338
                    ->setDescription(static::GIFT_CARD_PROVIDER . $index)
339
                    ->setGrossUnitPrice($amount)
340
                    ->setQuantity(static::ORDER_ITEM_QUANTITY)
341
            );
342
        }
343
344
        return $orderRequestTransfer;
345
    }
346
347
    /**
348
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
349
     *
350
     * @return \Generated\Shared\Transfer\PaymentTransfer[]
351
     */
352
    protected function getGiftcards(AfterPayCallTransfer $afterPayCallTransfer): array
353
    {
354
        $giftCardPayments = [];
355
        foreach ($afterPayCallTransfer->getPayments() as $paymentTransfer) {
356
            if ($paymentTransfer->getPaymentMethod() !== static::GIFT_CARD_PROVIDER) {
357
                continue;
358
            }
359
360
            $giftCardPayments[] = $paymentTransfer;
361
        }
362
363
        return $giftCardPayments;
364
    }
365
366
    /**
367
     * @param \Generated\Shared\Transfer\AfterPayRequestOrderTransfer $orderRequestTransfer
368
     * @param \Generated\Shared\Transfer\AfterPayCallTransfer $afterPayCallTransfer
369
     *
370
     * @return \Generated\Shared\Transfer\AfterPayRequestOrderTransfer
371
     */
372
    protected function addExpensesToOrderRequestTransfer(
373
        AfterPayRequestOrderTransfer $orderRequestTransfer,
374
        AfterPayCallTransfer $afterPayCallTransfer
375
    ): AfterPayRequestOrderTransfer {
376
        foreach ($afterPayCallTransfer->getExpenses() as $expenseTransfer) {
377
            if ($expenseTransfer->getSumPriceToPayAggregation() > 0) {
378
                $orderRequestTransfer->addItem(
379
                    $this->buildOrderExpenseRequestTransfer($expenseTransfer)
380
                );
381
            }
382
        }
383
384
        return $orderRequestTransfer;
385
    }
386
387
    /**
388
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expenseTransfer
389
     *
390
     * @return \Generated\Shared\Transfer\AfterPayRequestOrderItemTransfer
391
     */
392
    protected function buildOrderExpenseRequestTransfer(ExpenseTransfer $expenseTransfer): AfterPayRequestOrderItemTransfer
393
    {
394
        $item = (new AfterPayRequestOrderItemTransfer())
395
            ->setProductId($expenseTransfer->getType())
396
            ->setDescription($expenseTransfer->getName())
397
            ->setGrossUnitPrice($this->getStringDecimalExpenseGrossUnitPrice($expenseTransfer))
398
            ->setNetUnitPrice($this->getStringDecimalExpenseNetUnitPrice($expenseTransfer))
399
            ->setVatAmount($this->getStringDecimalExpenseVatAmount($expenseTransfer))
400
            ->setVatPercent($expenseTransfer->getTaxRate())
401
            ->setQuantity($expenseTransfer->getQuantity());
402
403
        return $item;
404
    }
405
406
    /**
407
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expenseTransfer
408
     *
409
     * @return string
410
     */
411
    protected function getStringDecimalExpenseGrossUnitPrice(ExpenseTransfer $expenseTransfer): string
412
    {
413
        $expenseUnitGrossPrice = $expenseTransfer->getUnitPriceToPayAggregation();
414
415
        return (string)$this->moneyFacade->convertIntegerToDecimal($expenseUnitGrossPrice);
416
    }
417
418
    /**
419
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expenseTransfer
420
     *
421
     * @return string
422
     */
423
    protected function getStringDecimalExpenseNetUnitPrice(ExpenseTransfer $expenseTransfer): string
424
    {
425
        $expenseUnitGrossPriceAmount = $expenseTransfer->getUnitPriceToPayAggregation();
426
        $expenseUnitTaxAmount = $expenseTransfer->getUnitTaxAmount();
427
        $expenseUnitNetAmount = $expenseUnitGrossPriceAmount - $expenseUnitTaxAmount;
428
429
        return (string)$this->moneyFacade->convertIntegerToDecimal($expenseUnitNetAmount);
430
    }
431
432
    /**
433
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expenseTransfer
434
     *
435
     * @return string
436
     */
437
    protected function getStringDecimalExpenseVatAmount(ExpenseTransfer $expenseTransfer): string
438
    {
439
        $expenseVatAmount = $expenseTransfer->getSumTaxAmount();
440
441
        return (string)$this->moneyFacade->convertIntegerToDecimal($expenseVatAmount);
442
    }
443
}
444