Passed
Pull Request — master (#23)
by
unknown
11:26 queued 06:10
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;
24
use SprykerEco\Zed\AfterPay\Business\Payment\Transaction\PriceToPayProviderInterface;
25
use SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToMoneyFacadeInterface;
26
use SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToStoreFacadeInterface;
27
28
class OrderToRequestTransfer implements OrderToRequestTransferInterface
29
{
30
    public const NEGATIVE_MULTIPLIER = -1;
31
    public const GIFT_CARD_PROVIDER = 'GiftCard';
32
33
    protected const ZERO_AMOUNT = '0';
34
35
    protected const ORDER_ITEM_QUANTITY = 1;
36
    protected const SHIPPING_FEE_PROVIDER = 'ShippingFee';
37
38
    /**
39
     * @var \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToMoneyFacadeInterface
40
     */
41
    protected $moneyFacade;
42
43
    /**
44
     * @var \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToStoreFacadeInterface
45
     */
46
    protected $storeFacade;
47
48
    /**
49
     * @var array
50
     */
51
    protected static $paymentMethods = [
52
        AfterPayConfig::PAYMENT_METHOD_INVOICE => AfterPayConfig::PAYMENT_TYPE_INVOICE,
53
    ];
54
55
    /**
56
     * @var \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\PriceToPayProviderInterface
57
     */
58
    protected $priceToPayProvider;
59
60
    /**
61
     * @var \SprykerEco\Zed\AfterPay\AfterPayConfig
62
     */
63
    protected $config;
64
65
    /**
66
     * @param \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToMoneyFacadeInterface $moneyFacade
67
     * @param \SprykerEco\Zed\AfterPay\Dependency\Facade\AfterPayToStoreFacadeInterface $storeFacade
68
     * @param \SprykerEco\Zed\AfterPay\Business\Payment\Transaction\PriceToPayProviderInterface $priceToPayProvider
69
     */
70
    public function __construct(
71
        AfterPayToMoneyFacadeInterface $moneyFacade,
72
        AfterPayToStoreFacadeInterface $storeFacade,
73
        PriceToPayProviderInterface $priceToPayProvider,
74
        AfterPayConfig $config
75
    ) {
76
        $this->moneyFacade = $moneyFacade;
77
        $this->storeFacade = $storeFacade;
78
        $this->priceToPayProvider = $priceToPayProvider;
79
        $this->config = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config of type SprykerEco\Shared\AfterPay\AfterPayConfig is incompatible with the declared type SprykerEco\Zed\AfterPay\AfterPayConfig of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

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