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