Passed
Pull Request — master (#51)
by Aleksey
12:12
created

PaymentManager   F

Complexity

Total Complexity 103

Size/Duplication

Total Lines 1491
Duplicated Lines 0 %

Importance

Changes 15
Bugs 1 Features 1
Metric Value
eloc 635
c 15
b 1
f 1
dl 0
loc 1491
rs 1.965
wmc 103

59 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegisteredPaymentMethodMapper() 0 10 2
A authorizePayment() 0 14 1
A creditCardCheck() 0 15 1
A getPartialCaptureStatus() 0 7 2
A getPayment() 0 13 1
A getFile() 0 26 2
A findPaymentByFileReferenceAndCustomerId() 0 3 1
A __construct() 0 20 1
A debitPayment() 0 20 1
A prepareOrderDiscount() 0 26 1
A getPostSaveHookRequestContainer() 0 16 2
A prepareOrderHandling() 0 31 3
A updatePaymentPayoneOrderItemsWithStatus() 0 13 2
A initPaypalExpressCheckout() 0 14 1
A performGenericRequest() 0 26 1
A getPartialRefundStatus() 0 7 2
A updatePaymentAfterAuthorization() 0 4 1
A preparePartialCaptureOrderItems() 0 35 3
A executeCheckoutPostSaveHook() 0 31 4
A capturePayment() 0 35 4
A postSaveHook() 0 25 4
A findPaymentByTransactionId() 0 3 1
A manageMandate() 0 20 1
A preparePartialRefundExpenses() 0 36 3
A preAuthorizePayment() 0 11 1
A isRefundPossible() 0 11 3
A getSecurityInvoice() 0 27 2
A getCreditCardCheckRequestData() 0 9 1
A getDeliveryCosts() 0 9 3
A registerPaymentMethodMapper() 0 6 1
A findPaymentByInvoiceTitleAndCustomerId() 0 3 1
A updateApiLogAfterAuthorization() 0 13 1
A initializeApiLog() 0 16 4
A setAccessDeniedError() 0 5 1
A getInvoiceTitle() 0 6 1
A calculatePartialCaptureItemsAmount() 0 10 3
A getInvoice() 0 25 2
A prepareOrderItems() 0 29 2
A isPaymentDataRequired() 0 17 2
A prepareOrderShipment() 0 26 1
A bankAccountCheck() 0 16 1
A setStandardParameter() 0 12 1
A refundPayment() 0 25 1
A getPaypalExpressCheckoutDetails() 0 17 1
A updatePaymentDetailAfterAuthorization() 0 22 3
A updateApiLogAfterCapture() 0 10 1
A performAuthorizationRequest() 0 12 1
A findPaymentMethodMapperByName() 0 7 2
A calculateExpensesCost() 0 11 3
A executePartialRefund() 0 24 1
A getPaymentDetail() 0 8 1
A updatePaymentDetail() 0 8 1
A getPaymentEntity() 0 3 1
A executePartialCapture() 0 37 1
A preparePartialRefundOrderItems() 0 35 3
A updateApiLogAfterDebit() 0 10 1
A updateApiLogAfterRefund() 0 10 1
A getPaymentLogs() 0 33 4
A getPaymentMethodMapper() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like PaymentManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use PaymentManager, and based on these observations, apply Extract Interface, too.

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\Payone\Business\Payment;
9
10
use Generated\Shared\Transfer\CaptureResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CaptureResponseTransfer 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\CheckoutErrorTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutErrorTransfer 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\CheckoutResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutResponseTransfer 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\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...
14
use Generated\Shared\Transfer\PaymentDetailTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentDetailTransfer 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\PayoneBankAccountCheckTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ankAccountCheckTransfer 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\PayoneCaptureTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneCaptureTransfer 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\PayoneCreditCardCheckRequestDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...heckRequestDataTransfer 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\PayoneCreditCardTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneCreditCardTransfer 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\PayoneGetFileTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneGetFileTransfer 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\PayoneGetInvoiceTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneGetInvoiceTransfer 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\PayoneGetSecurityInvoiceTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...SecurityInvoiceTransfer 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\PayoneInitPaypalExpressCheckoutRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...CheckoutRequestTransfer 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 Generated\Shared\Transfer\PayoneManageMandateTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...neManageMandateTransfer 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...
24
use Generated\Shared\Transfer\PayoneOrderItemFilterTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...OrderItemFilterTransfer 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...
25
use Generated\Shared\Transfer\PayonePartialOperationRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...perationRequestTransfer 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...
26
use Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ntLogCollectionTransfer 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...
27
use Generated\Shared\Transfer\PayonePaymentLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentLogTransfer 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...
28
use Generated\Shared\Transfer\PayonePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentTransfer 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...
29
use Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PaymentResponseTransfer 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...
30
use Generated\Shared\Transfer\PayoneRefundTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneRefundTransfer 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...
31
use Generated\Shared\Transfer\PayoneStandardParameterTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...andardParameterTransfer 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...
32
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
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. 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...
33
use Generated\Shared\Transfer\RefundResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RefundResponseTransfer 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...
34
use Generated\Shared\Transfer\TotalsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\TotalsTransfer 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...
35
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayone 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...
36
use Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog 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...
37
use Spryker\Shared\Shipment\ShipmentConfig;
38
use Spryker\Shared\Shipment\ShipmentConstants;
39
use SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface;
40
use SprykerEco\Shared\Payone\PayoneApiConstants;
41
use SprykerEco\Shared\Payone\PayoneTransactionStatusConstants;
42
use SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface;
43
use SprykerEco\Zed\Payone\Business\Api\Call\CreditCardCheck;
44
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
45
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface;
46
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Capture\BusinessContainer;
47
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
48
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
49
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer;
50
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
51
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer;
52
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer;
53
use SprykerEco\Zed\Payone\Business\Api\Response\Container\BankAccountCheckResponseContainer;
54
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer;
55
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CreditCardCheckResponseContainer;
56
use SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer;
57
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GenericPaymentResponseContainer;
58
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetFileResponseContainer;
59
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer;
60
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetSecurityInvoiceResponseContainer;
61
use SprykerEco\Zed\Payone\Business\Api\Response\Container\ManageMandateResponseContainer;
62
use SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer;
63
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\AuthorizationResponseMapper;
64
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CaptureResponseMapper;
65
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CreditCardCheckResponseMapper;
66
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\DebitResponseMapper;
67
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\RefundResponseMapper;
68
use SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException;
69
use SprykerEco\Zed\Payone\Business\Key\HashGenerator;
70
use SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface;
71
use SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface;
72
use SprykerEco\Zed\Payone\PayoneConfig;
73
use SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface;
74
use SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface;
75
use SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface;
76
77
class PaymentManager implements PaymentManagerInterface
78
{
79
    public const LOG_TYPE_API_LOG = 'SpyPaymentPayoneApiLog';
80
    public const LOG_TYPE_TRANSACTION_STATUS_LOG = 'SpyPaymentPayoneTransactionStatusLog';
81
    public const ERROR_ACCESS_DENIED_MESSAGE = 'Access denied';
82
83
    protected const PARAMETER_KEY_CAPTURE_MODE = 'capturemode';
84
    protected const PARAMETER_VALUE_CAPTURE_COMPLETED = 'completed';
85
86
    /**
87
     * @see \Spryker\Shared\Shipment\ShipmentConstants::SHIPMENT_EXPENSE_TYPE
88
     * @see \Spryker\Shared\Shipment\ShipmentConfig::SHIPMENT_EXPENSE_TYPE
89
     *
90
     * @deprecated Necessary in order to save compatibility with  spryker/shipping version less than "^8.0.0".
91
     * use \Spryker\Shared\Shipment\ShipmentConfig::SHIPMENT_EXPENSE_TYPE instead if shipping version is higher
92
     *
93
     */
94
    protected const SHIPMENT_EXPENSE_TYPE = 'SHIPMENT_EXPENSE_TYPE';
95
96
    /**
97
     * @var \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
98
     */
99
    protected $executionAdapter;
100
101
    /**
102
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface
103
     */
104
    protected $queryContainer;
105
106
    /**
107
     * @var \Generated\Shared\Transfer\PayoneStandardParameterTransfer
108
     */
109
    protected $standardParameter;
110
111
    /**
112
     * @var \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface
113
     */
114
    protected $sequenceNumberProvider;
115
116
    /**
117
     * @var \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface
118
     */
119
    protected $modeDetector;
120
121
    /**
122
     * @var \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface
123
     */
124
    protected $hashGenerator;
125
126
    /**
127
     * @var \SprykerEco\Zed\Payone\Business\Key\UrlHmacGenerator
128
     */
129
    protected $urlHmacGenerator;
130
131
    /**
132
     * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface[]
133
     */
134
    protected $registeredMethodMappers;
135
136
    /**
137
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface
138
     */
139
    protected $payoneRepository;
140
141
    /**
142
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface
143
     */
144
    protected $payoneEntityManager;
145
146
    /**
147
     * @param \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface $executionAdapter
148
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer
149
     * @param \Generated\Shared\Transfer\PayoneStandardParameterTransfer $standardParameter
150
     * @param \SprykerEco\Zed\Payone\Business\Key\HashGenerator $hashGenerator
151
     * @param \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface $sequenceNumberProvider
152
     * @param \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface $modeDetector
153
     * @param \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface $urlHmacGenerator
154
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface $payoneRepository
155
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface $payoneEntityManager
156
     */
157
    public function __construct(
158
        AdapterInterface $executionAdapter,
159
        PayoneQueryContainerInterface $queryContainer,
160
        PayoneStandardParameterTransfer $standardParameter,
161
        HashGenerator $hashGenerator,
162
        SequenceNumberProviderInterface $sequenceNumberProvider,
163
        ModeDetectorInterface $modeDetector,
164
        HmacGeneratorInterface $urlHmacGenerator,
165
        PayoneRepositoryInterface $payoneRepository,
166
        PayoneEntityManagerInterface $payoneEntityManager
167
    ) {
168
        $this->executionAdapter = $executionAdapter;
169
        $this->queryContainer = $queryContainer;
170
        $this->standardParameter = $standardParameter;
171
        $this->hashGenerator = $hashGenerator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $hashGenerator of type SprykerEco\Zed\Payone\Business\Key\HashGenerator is incompatible with the declared type SprykerEco\Zed\Payone\Bu...\HmacGeneratorInterface of property $hashGenerator.

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...
172
        $this->sequenceNumberProvider = $sequenceNumberProvider;
173
        $this->modeDetector = $modeDetector;
174
        $this->urlHmacGenerator = $urlHmacGenerator;
0 ignored issues
show
Documentation Bug introduced by
$urlHmacGenerator is of type SprykerEco\Zed\Payone\Bu...\HmacGeneratorInterface, but the property $urlHmacGenerator was declared to be of type SprykerEco\Zed\Payone\Bu...ss\Key\UrlHmacGenerator. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
175
        $this->payoneRepository = $payoneRepository;
176
        $this->payoneEntityManager = $payoneEntityManager;
177
    }
178
179
    /**
180
     * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface $paymentMethodMapper
181
     *
182
     * @return void
183
     */
184
    public function registerPaymentMethodMapper(PaymentMethodMapperInterface $paymentMethodMapper)
185
    {
186
        $paymentMethodMapper->setStandardParameter($this->standardParameter);
187
        $paymentMethodMapper->setSequenceNumberProvider($this->sequenceNumberProvider);
188
        $paymentMethodMapper->setUrlHmacGenerator($this->urlHmacGenerator);
189
        $this->registeredMethodMappers[$paymentMethodMapper->getName()] = $paymentMethodMapper;
190
    }
191
192
    /**
193
     * @param string $name
194
     *
195
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface|null
196
     */
197
    protected function findPaymentMethodMapperByName($name)
198
    {
199
        if (array_key_exists($name, $this->registeredMethodMappers)) {
200
            return $this->registeredMethodMappers[$name];
201
        }
202
203
        return null;
204
    }
205
206
    /**
207
     * @param string $paymentMethodName
208
     *
209
     * @throws \SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException
210
     *
211
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
212
     */
213
    protected function getRegisteredPaymentMethodMapper($paymentMethodName)
214
    {
215
        $paymentMethodMapper = $this->findPaymentMethodMapperByName($paymentMethodName);
216
        if ($paymentMethodMapper === null) {
217
            throw new InvalidPaymentMethodException(
218
                sprintf('No registered payment method mapper found for given method name %s', $paymentMethodName)
219
            );
220
        }
221
222
        return $paymentMethodMapper;
223
    }
224
225
    /**
226
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
227
     *
228
     * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...izationResponseTransfer 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...
229
     */
230
    public function authorizePayment(OrderTransfer $orderTransfer)
231
    {
232
        $paymentEntity = $this->getPaymentEntity($orderTransfer->getIdSalesOrder());
233
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
234
        $requestContainer = $paymentMethodMapper->mapPaymentToAuthorization($paymentEntity, $orderTransfer);
235
        $requestContainer = $this->prepareOrderItems($orderTransfer, $requestContainer);
236
        $requestContainer = $this->prepareOrderShipment($orderTransfer, $requestContainer);
237
        $requestContainer = $this->prepareOrderDiscount($orderTransfer, $requestContainer);
238
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
239
240
        $responseMapper = new AuthorizationResponseMapper();
241
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
242
243
        return $responseTransfer;
244
    }
245
246
    /**
247
     * @param int $idSalesOrder
248
     *
249
     * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer
250
     */
251
    public function preAuthorizePayment($idSalesOrder)
252
    {
253
        $paymentEntity = $this->getPaymentEntity($idSalesOrder);
254
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
255
        $requestContainer = $paymentMethodMapper->mapPaymentToPreAuthorization($paymentEntity);
256
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
257
258
        $responseMapper = new AuthorizationResponseMapper();
259
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
260
261
        return $responseTransfer;
262
    }
263
264
    /**
265
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
266
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface $requestContainer
267
     *
268
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer
269
     */
270
    protected function performAuthorizationRequest(SpyPaymentPayone $paymentEntity, AuthorizationContainerInterface $requestContainer)
271
    {
272
        $this->setStandardParameter($requestContainer);
273
274
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
275
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
276
        $responseContainer = new AuthorizationResponseContainer($rawResponse);
277
        $this->updatePaymentAfterAuthorization($paymentEntity, $responseContainer);
278
        $this->updateApiLogAfterAuthorization($apiLogEntity, $responseContainer);
279
        $this->updatePaymentDetailAfterAuthorization($paymentEntity, $responseContainer);
280
281
        return $responseContainer;
282
    }
283
284
    /**
285
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
286
     *
287
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
288
     */
289
    protected function getPaymentMethodMapper(SpyPaymentPayone $paymentEntity)
290
    {
291
        return $this->getRegisteredPaymentMethodMapper($paymentEntity->getPaymentMethod());
292
    }
293
294
    /**
295
     * @param int $orderId
296
     *
297
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
298
     */
299
    protected function getPaymentEntity($orderId)
300
    {
301
        return $this->queryContainer->createPaymentById($orderId)->findOne();
302
    }
303
304
    /**
305
     * @param \Generated\Shared\Transfer\PayoneCaptureTransfer $captureTransfer
306
     *
307
     * @return \Generated\Shared\Transfer\CaptureResponseTransfer
308
     */
309
    public function capturePayment(PayoneCaptureTransfer $captureTransfer): CaptureResponseTransfer
310
    {
311
        $paymentEntity = $this->getPaymentEntity($captureTransfer->getPayment()->getFkSalesOrder());
312
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
313
314
        $requestContainer = $paymentMethodMapper->mapPaymentToCapture($paymentEntity);
315
316
        if ($captureTransfer->getAmount()) {
317
            $requestContainer = $this->prepareOrderItems($captureTransfer->getOrder(), $requestContainer);
318
            $requestContainer = $this->prepareOrderShipment($captureTransfer->getOrder(), $requestContainer);
319
            $requestContainer = $this->prepareOrderDiscount($captureTransfer->getOrder(), $requestContainer);
320
            $requestContainer = $this->prepareOrderHandling($captureTransfer->getOrder(), $requestContainer);
321
        }
322
323
        if (!empty($captureTransfer->getSettleaccount())) {
324
            $businnessContainer = new BusinessContainer();
325
            $businnessContainer->setSettleAccount($captureTransfer->getSettleaccount());
326
            $requestContainer->setBusiness($businnessContainer);
327
        }
328
329
        if ($captureTransfer->getAmount() !== null) {
330
            $requestContainer->setAmount($captureTransfer->getAmount());
331
        }
332
333
        $this->setStandardParameter($requestContainer);
334
335
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
336
337
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
338
        $responseContainer = new CaptureResponseContainer($rawResponse);
339
        $this->updateApiLogAfterCapture($apiLogEntity, $responseContainer);
340
341
        $responseMapper = new CaptureResponseMapper();
342
343
        return $responseMapper->getCaptureResponseTransfer($responseContainer);
344
    }
345
346
    /**
347
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
348
     *
349
     * @return \Generated\Shared\Transfer\CaptureResponseTransfer
350
     */
351
    public function executePartialCapture(
352
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
353
    ): CaptureResponseTransfer {
354
        $paymentEntity = $this->getPaymentEntity($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder());
355
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
356
357
        $requestContainer = $paymentMethodMapper->mapPaymentToCapture($paymentEntity);
358
        $requestContainer = $this->preparePartialCaptureOrderItems($payonePartialOperationRequestTransfer, $requestContainer);
359
        $captureAmount = $this->calculatePartialCaptureItemsAmount($payonePartialOperationRequestTransfer);
360
361
        $captureAmount += $this->getDeliveryCosts($payonePartialOperationRequestTransfer->getOrder());
362
        $requestContainer = $this->prepareOrderShipment($payonePartialOperationRequestTransfer->getOrder(), $requestContainer);
363
364
        $captureAmount += $this->calculateExpensesCost($payonePartialOperationRequestTransfer->getOrder());
365
        $requestContainer = $this->prepareOrderHandling($payonePartialOperationRequestTransfer->getOrder(), $requestContainer);
366
367
        $businessContainer = new BusinessContainer();
368
        $businessContainer->setSettleAccount(PayoneApiConstants::SETTLE_ACCOUNT_YES);
369
        $requestContainer->setBusiness($businessContainer);
370
371
        $requestContainer->setAmount($captureAmount);
372
        $this->setStandardParameter($requestContainer);
373
374
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
375
376
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
377
        $responseContainer = new CaptureResponseContainer($rawResponse);
378
379
        $this->updateApiLogAfterCapture($apiLogEntity, $responseContainer);
380
        $this->updatePaymentPayoneOrderItemsWithStatus(
381
            $payonePartialOperationRequestTransfer,
382
            $this->getPartialCaptureStatus($responseContainer)
383
        );
384
385
        $responseMapper = new CaptureResponseMapper();
386
387
        return $responseMapper->getCaptureResponseTransfer($responseContainer);
388
    }
389
390
    /**
391
     * @param int $idPayment
392
     *
393
     * @return \Generated\Shared\Transfer\DebitResponseTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\DebitResponseTransfer 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...
394
     */
395
    public function debitPayment($idPayment)
396
    {
397
        $paymentEntity = $this->getPaymentEntity($idPayment);
398
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
399
400
        $requestContainer = $paymentMethodMapper->mapPaymentToDebit($paymentEntity);
401
        $this->setStandardParameter($requestContainer);
402
403
        $paymentEntity = $this->findPaymentByTransactionId($paymentEntity->getTransactionId());
404
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
405
406
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
407
        $responseContainer = new DebitResponseContainer($rawResponse);
408
409
        $this->updateApiLogAfterDebit($apiLogEntity, $responseContainer);
410
411
        $responseMapper = new DebitResponseMapper();
412
        $responseTransfer = $responseMapper->getDebitResponseTransfer($responseContainer);
413
414
        return $responseTransfer;
415
    }
416
417
    /**
418
     * @param \Generated\Shared\Transfer\PayoneCreditCardTransfer $creditCardData
419
     *
420
     * @return \Generated\Shared\Transfer\CreditCardCheckResponseTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rdCheckResponseTransfer 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...
421
     */
422
    public function creditCardCheck(PayoneCreditCardTransfer $creditCardData)
423
    {
424
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo $paymentMethodMapper */
425
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper($creditCardData->getPayment()->getPaymentMethod());
426
        $requestContainer = $paymentMethodMapper->mapCreditCardCheck($creditCardData);
427
428
        $this->setStandardParameter($requestContainer);
429
430
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
431
        $responseContainer = new CreditCardCheckResponseContainer($rawResponse);
432
433
        $responseMapper = new CreditCardCheckResponseMapper();
434
        $responseTransfer = $responseMapper->getCreditCardCheckResponseTransfer($responseContainer);
435
436
        return $responseTransfer;
437
    }
438
439
    /**
440
     * @param \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer $bankAccountCheckTransfer
441
     *
442
     * @return \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer
443
     */
444
    public function bankAccountCheck(PayoneBankAccountCheckTransfer $bankAccountCheckTransfer)
445
    {
446
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
447
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER);
448
        $requestContainer = $paymentMethodMapper->mapBankAccountCheck($bankAccountCheckTransfer);
449
        $this->setStandardParameter($requestContainer);
450
451
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
452
        $responseContainer = new BankAccountCheckResponseContainer($rawResponse);
453
454
        $bankAccountCheckTransfer->setErrorCode($responseContainer->getErrorcode());
455
        $bankAccountCheckTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
456
        $bankAccountCheckTransfer->setStatus($responseContainer->getStatus());
457
        $bankAccountCheckTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
458
459
        return $bankAccountCheckTransfer;
460
    }
461
462
    /**
463
     * @param \Generated\Shared\Transfer\PayoneManageMandateTransfer $manageMandateTransfer
464
     *
465
     * @return \Generated\Shared\Transfer\PayoneManageMandateTransfer
466
     */
467
    public function manageMandate(PayoneManageMandateTransfer $manageMandateTransfer)
468
    {
469
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
470
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
471
        $requestContainer = $paymentMethodMapper->mapManageMandate($manageMandateTransfer);
472
        $this->setStandardParameter($requestContainer);
473
474
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
475
        $responseContainer = new ManageMandateResponseContainer($rawResponse);
476
477
        $manageMandateTransfer->setErrorCode($responseContainer->getErrorcode());
478
        $manageMandateTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
479
        $manageMandateTransfer->setStatus($responseContainer->getStatus());
480
        $manageMandateTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
481
        $manageMandateTransfer->setMandateIdentification($responseContainer->getMandateIdentification());
482
        $manageMandateTransfer->setMandateText($responseContainer->getMandateText());
483
        $manageMandateTransfer->setIban($responseContainer->getIban());
484
        $manageMandateTransfer->setBic($responseContainer->getBic());
485
486
        return $manageMandateTransfer;
487
    }
488
489
    /**
490
     * @param \Generated\Shared\Transfer\PayoneGetFileTransfer $getFileTransfer
491
     *
492
     * @return \Generated\Shared\Transfer\PayoneGetFileTransfer
493
     */
494
    public function getFile(PayoneGetFileTransfer $getFileTransfer)
495
    {
496
        $responseContainer = new GetFileResponseContainer();
497
        $paymentEntity = $this->findPaymentByFileReferenceAndCustomerId(
498
            $getFileTransfer->getReference(),
499
            $getFileTransfer->getCustomerId()
500
        );
501
502
        if ($paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayone, thus it always evaluated to true.
Loading history...
503
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
504
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
505
            $requestContainer = $paymentMethodMapper->mapGetFile($getFileTransfer);
506
            $this->setStandardParameter($requestContainer);
507
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
508
            $responseContainer->init($rawResponse);
509
        } else {
510
            $this->setAccessDeniedError($responseContainer);
511
        }
512
513
        $getFileTransfer->setRawResponse($responseContainer->getRawResponse());
514
        $getFileTransfer->setStatus($responseContainer->getStatus());
515
        $getFileTransfer->setErrorCode($responseContainer->getErrorcode());
516
        $getFileTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
517
        $getFileTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
518
519
        return $getFileTransfer;
520
    }
521
522
    /**
523
     * @param \Generated\Shared\Transfer\PayoneGetInvoiceTransfer $getInvoiceTransfer
524
     *
525
     * @return \Generated\Shared\Transfer\PayoneGetInvoiceTransfer
526
     */
527
    public function getInvoice(PayoneGetInvoiceTransfer $getInvoiceTransfer)
528
    {
529
        $responseContainer = new GetInvoiceResponseContainer();
530
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
531
            $getInvoiceTransfer->getReference(),
532
            $getInvoiceTransfer->getCustomerId()
533
        );
534
535
        if ($paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayone, thus it always evaluated to true.
Loading history...
536
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice $paymentMethodMapper */
537
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_INVOICE);
538
            $requestContainer = $paymentMethodMapper->mapGetInvoice($getInvoiceTransfer);
539
            $this->setStandardParameter($requestContainer);
540
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
541
            $responseContainer->init($rawResponse);
542
        } else {
543
            $this->setAccessDeniedError($responseContainer);
544
        }
545
546
        $getInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
547
        $getInvoiceTransfer->setStatus($responseContainer->getStatus());
548
        $getInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
549
        $getInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
550
551
        return $getInvoiceTransfer;
552
    }
553
554
    /**
555
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
556
     *
557
     * @return \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer
558
     */
559
    public function getSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer): PayoneGetSecurityInvoiceTransfer
560
    {
561
        $responseContainer = new GetSecurityInvoiceResponseContainer();
562
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
563
            $getSecurityInvoiceTransfer->getReference(),
564
            $getSecurityInvoiceTransfer->getCustomerId()
565
        );
566
567
        if (!$paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayone, thus it always evaluated to true.
Loading history...
568
            $this->setAccessDeniedError($responseContainer);
569
570
            return $getSecurityInvoiceTransfer;
571
        }
572
573
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\SecurityInvoice $paymentMethodMapper */
574
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE);
575
        $requestContainer = $paymentMethodMapper->mapGetSecurityInvoice($getSecurityInvoiceTransfer);
576
        $this->setStandardParameter($requestContainer);
577
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
578
        $responseContainer->init($rawResponse);
579
580
        $getSecurityInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
581
        $getSecurityInvoiceTransfer->setStatus($responseContainer->getStatus());
582
        $getSecurityInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
583
        $getSecurityInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
584
585
        return $getSecurityInvoiceTransfer;
586
    }
587
588
    /**
589
     * @param int $transactionId
590
     *
591
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer
592
     */
593
    public function getInvoiceTitle($transactionId)
594
    {
595
        return implode('-', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return implode('-', arra...CE, $transactionId, 0)) returns the type string which is incompatible with the documented return type SprykerEco\Zed\Payone\Bu...nvoiceResponseContainer.
Loading history...
596
            PayoneApiConstants::INVOICE_TITLE_PREFIX_INVOICE,
597
            $transactionId,
598
            0,
599
        ]);
600
    }
601
602
    /**
603
     * @param \Generated\Shared\Transfer\PayoneRefundTransfer $refundTransfer
604
     *
605
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
606
     */
607
    public function refundPayment(PayoneRefundTransfer $refundTransfer)
608
    {
609
        $payonePaymentTransfer = $refundTransfer->getPayment();
610
611
        $paymentEntity = $this->getPaymentEntity($payonePaymentTransfer->getFkSalesOrder());
612
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
613
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
614
        $requestContainer->setAmount(0 - $paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
615
        $requestContainer = $this->prepareOrderItems($refundTransfer->getOrder(), $requestContainer);
616
        $requestContainer = $this->prepareOrderShipment($refundTransfer->getOrder(), $requestContainer);
617
        $requestContainer = $this->prepareOrderDiscount($refundTransfer->getOrder(), $requestContainer);
618
619
        $this->setStandardParameter($requestContainer);
620
621
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
622
623
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
624
        $responseContainer = new RefundResponseContainer($rawResponse);
625
626
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
627
628
        $responseMapper = new RefundResponseMapper();
629
        $responseTransfer = $responseMapper->getRefundResponseTransfer($responseContainer);
630
631
        return $responseTransfer;
632
    }
633
634
    /**
635
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
636
     *
637
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
638
     */
639
    public function executePartialRefund(PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer): RefundResponseTransfer
640
    {
641
        $paymentEntity = $this->getPaymentEntity($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder());
642
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
643
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
644
645
        $requestContainer->setAmount($payonePartialOperationRequestTransfer->getRefund()->getAmount() * -1);
646
        $requestContainer = $this->preparePartialRefundOrderItems($payonePartialOperationRequestTransfer, $requestContainer);
647
        $requestContainer = $this->preparePartialRefundExpenses($payonePartialOperationRequestTransfer, $requestContainer);
648
        $this->setStandardParameter($requestContainer);
649
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
650
651
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
652
        $responseContainer = new RefundResponseContainer($rawResponse);
653
654
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
655
        $this->updatePaymentPayoneOrderItemsWithStatus(
656
            $payonePartialOperationRequestTransfer,
657
            $this->getPartialRefundStatus($responseContainer)
658
        );
659
660
        $responseMapper = new RefundResponseMapper();
661
662
        return $responseMapper->getRefundResponseTransfer($responseContainer);
663
    }
664
665
    /**
666
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
667
     * @param string $refundStatus
668
     *
669
     * @return void
670
     */
671
    protected function updatePaymentPayoneOrderItemsWithStatus(
672
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
673
        string $refundStatus
674
    ): void {
675
        $payoneOrderItemFilterTransfer = (new PayoneOrderItemFilterTransfer())
676
            ->setIdSalesOrder($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder())
677
            ->setSalesOrderItemIds($payonePartialOperationRequestTransfer->getSalesOrderItemIds());
678
679
        $payoneOrderItemTransfers = $this->payoneRepository->findPaymentPayoneOrderItemByFilter($payoneOrderItemFilterTransfer);
680
681
        foreach ($payoneOrderItemTransfers as $payoneOrderItemTransfer) {
682
            $payoneOrderItemTransfer->setStatus($refundStatus);
683
            $this->payoneEntityManager->updatePaymentPayoneOrderItem($payoneOrderItemTransfer);
684
        }
685
    }
686
687
    /**
688
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer
689
     *
690
     * @return string
691
     */
692
    protected function getPartialRefundStatus(RefundResponseContainer $responseContainer): string
693
    {
694
        if ($responseContainer->getStatus() === PayoneApiConstants::RESPONSE_TYPE_APPROVED) {
695
            return PayoneTransactionStatusConstants::STATUS_REFUND_APPROVED;
696
        }
697
698
        return PayoneTransactionStatusConstants::STATUS_REFUND_FAILED;
699
    }
700
701
    /**
702
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
703
     *
704
     * @return \Generated\Shared\Transfer\PayonePaymentTransfer
705
     */
706
    protected function getPayment(OrderTransfer $orderTransfer)
707
    {
708
        $payment = $this->queryContainer->createPaymentByOrderId($orderTransfer->getIdSalesOrder())->findOne();
709
        $paymentDetail = $payment->getSpyPaymentPayoneDetail();
710
711
        $paymentDetailTransfer = new PaymentDetailTransfer();
712
        $paymentDetailTransfer->fromArray($paymentDetail->toArray(), true);
713
714
        $paymentTransfer = new PayonePaymentTransfer();
715
        $paymentTransfer->fromArray($payment->toArray(), true);
716
        $paymentTransfer->setPaymentDetail($paymentDetailTransfer);
717
718
        return $paymentTransfer;
719
    }
720
721
    /**
722
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
723
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
724
     *
725
     * @return void
726
     */
727
    protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
728
    {
729
        $paymentEntity->setTransactionId($responseContainer->getTxid());
730
        $paymentEntity->save();
731
    }
732
733
    /**
734
     * @param string $transactionId
735
     *
736
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
737
     */
738
    protected function findPaymentByTransactionId($transactionId)
739
    {
740
        return $this->queryContainer->createPaymentByTransactionIdQuery($transactionId)->findOne();
0 ignored issues
show
Bug introduced by
$transactionId of type string is incompatible with the type integer expected by parameter $transactionId of SprykerEco\Zed\Payone\Pe...tByTransactionIdQuery(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

740
        return $this->queryContainer->createPaymentByTransactionIdQuery(/** @scrutinizer ignore-type */ $transactionId)->findOne();
Loading history...
741
    }
742
743
    /**
744
     * @param string $invoiceTitle
745
     * @param int $customerId
746
     *
747
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
748
     */
749
    protected function findPaymentByInvoiceTitleAndCustomerId($invoiceTitle, $customerId)
750
    {
751
        return $this->queryContainer->createPaymentByInvoiceTitleAndCustomerIdQuery($invoiceTitle, $customerId)->findOne();
752
    }
753
754
    /**
755
     * @param string $fileReference
756
     * @param int $customerId
757
     *
758
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
759
     */
760
    protected function findPaymentByFileReferenceAndCustomerId($fileReference, $customerId)
761
    {
762
        return $this->queryContainer->createPaymentByFileReferenceAndCustomerIdQuery($fileReference, $customerId)->findOne();
763
    }
764
765
    /**
766
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
767
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
768
     *
769
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog
770
     */
771
    protected function initializeApiLog(SpyPaymentPayone $paymentEntity, AbstractRequestContainer $container)
772
    {
773
        $entity = new SpyPaymentPayoneApiLog();
774
        $entity->setSpyPaymentPayone($paymentEntity);
775
        $entity->setRequest($container->getRequest());
776
        $entity->setMode($container->getMode());
777
        $entity->setMerchantId($container->getMid());
778
        $entity->setPortalId($container->getPortalid());
779
        if ($container instanceof CaptureContainer || $container instanceof RefundContainer || $container instanceof DebitContainer) {
780
            $entity->setSequenceNumber($container->getSequenceNumber());
781
        }
782
        // Logging request data for debug
783
        $entity->setRawRequest(json_encode($container->toArray()));
784
        $entity->save();
785
786
        return $entity;
787
    }
788
789
    /**
790
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
791
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
792
     *
793
     * @return void
794
     */
795
    protected function updateApiLogAfterAuthorization(SpyPaymentPayoneApiLog $apiLogEntity, AuthorizationResponseContainer $responseContainer)
796
    {
797
        $apiLogEntity->setStatus($responseContainer->getStatus());
798
        $apiLogEntity->setUserId($responseContainer->getUserid());
799
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
800
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
801
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
802
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
803
        $apiLogEntity->setRedirectUrl($responseContainer->getRedirecturl());
804
        $apiLogEntity->setSequenceNumber(0);
805
806
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
807
        $apiLogEntity->save();
808
    }
809
810
    /**
811
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
812
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer $responseContainer
813
     *
814
     * @return void
815
     */
816
    protected function updateApiLogAfterCapture(SpyPaymentPayoneApiLog $apiLogEntity, CaptureResponseContainer $responseContainer)
817
    {
818
        $apiLogEntity->setStatus($responseContainer->getStatus());
819
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
820
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
821
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
822
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
823
824
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
825
        $apiLogEntity->save();
826
    }
827
828
    /**
829
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
830
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer $responseContainer
831
     *
832
     * @return void
833
     */
834
    protected function updateApiLogAfterDebit(SpyPaymentPayoneApiLog $apiLogEntity, DebitResponseContainer $responseContainer)
835
    {
836
        $apiLogEntity->setStatus($responseContainer->getStatus());
837
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
838
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
839
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
840
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
841
842
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
843
        $apiLogEntity->save();
844
    }
845
846
    /**
847
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
848
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer
849
     *
850
     * @return void
851
     */
852
    protected function updateApiLogAfterRefund(SpyPaymentPayoneApiLog $apiLogEntity, RefundResponseContainer $responseContainer)
853
    {
854
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
855
        $apiLogEntity->setStatus($responseContainer->getStatus());
856
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
857
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
858
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
859
860
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
861
        $apiLogEntity->save();
862
    }
863
864
    /**
865
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
866
     *
867
     * @return void
868
     */
869
    protected function setStandardParameter(AbstractRequestContainer $container)
870
    {
871
        $container->setApiVersion(PayoneApiConstants::API_VERSION_3_9);
872
        $container->setEncoding($this->standardParameter->getEncoding());
873
        $container->setKey($this->hashGenerator->hash($this->standardParameter->getKey()));
0 ignored issues
show
Bug introduced by
The call to SprykerEco\Zed\Payone\Bu...eratorInterface::hash() has too few arguments starting with key. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

873
        $container->setKey($this->hashGenerator->/** @scrutinizer ignore-call */ hash($this->standardParameter->getKey()));

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
874
        $container->setMid($this->standardParameter->getMid());
875
        $container->setPortalid($this->standardParameter->getPortalId());
876
        $container->setMode($this->modeDetector->getMode());
877
        $container->setIntegratorName(PayoneApiConstants::INTEGRATOR_NAME_SPRYKER);
878
        $container->setIntegratorVersion(PayoneApiConstants::INTEGRATOR_VERSION_3_0_0);
879
        $container->setSolutionName(PayoneApiConstants::SOLUTION_NAME_SPRYKER);
880
        $container->setSolutionVersion(PayoneApiConstants::SOLUTION_VERSION_3_0_0);
881
    }
882
883
    /**
884
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer $container
885
     *
886
     * @return void
887
     */
888
    protected function setAccessDeniedError(AbstractResponseContainer $container)
889
    {
890
        $container->setStatus(PayoneApiConstants::RESPONSE_TYPE_ERROR);
891
        $container->setErrormessage(static::ERROR_ACCESS_DENIED_MESSAGE);
892
        $container->setCustomermessage(static::ERROR_ACCESS_DENIED_MESSAGE);
893
    }
894
895
    /**
896
     * @param int $idOrder
897
     *
898
     * @return \Generated\Shared\Transfer\PaymentDetailTransfer
899
     */
900
    public function getPaymentDetail($idOrder)
901
    {
902
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
903
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
904
        $paymentDetailTransfer = new PaymentDetailTransfer();
905
        $paymentDetailTransfer->fromArray($paymentDetailEntity->toArray(), true);
906
907
        return $paymentDetailTransfer;
908
    }
909
910
    /**
911
     * Gets payment logs (both api and transaction status) for specific orders in chronological order.
912
     *
913
     * @param \Propel\Runtime\Collection\ObjectCollection|\ArrayObject $orders
914
     *
915
     * @return \Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer
916
     */
917
    public function getPaymentLogs($orders)
918
    {
919
        $apiLogs = $this->queryContainer->createApiLogsByOrderIds($orders)->find()->getData();
0 ignored issues
show
Bug introduced by
It seems like $orders can also be of type ArrayObject; however, parameter $orders of SprykerEco\Zed\Payone\Pe...eateApiLogsByOrderIds() does only seem to accept Propel\Runtime\Collection\ObjectCollection, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

919
        $apiLogs = $this->queryContainer->createApiLogsByOrderIds(/** @scrutinizer ignore-type */ $orders)->find()->getData();
Loading history...
920
921
        $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds($orders)->find()->getData();
0 ignored issues
show
Bug introduced by
It seems like $orders can also be of type ArrayObject; however, parameter $orders of SprykerEco\Zed\Payone\Pe...nStatusLogsByOrderIds() does only seem to accept Propel\Runtime\Collection\ObjectCollection, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

921
        $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds(/** @scrutinizer ignore-type */ $orders)->find()->getData();
Loading history...
922
923
        $logs = [];
924
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLog */
925
        foreach ($apiLogs as $apiLog) {
926
            $key = $apiLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 'a' . $apiLog->getIdPaymentPayoneApiLog();
927
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
928
            $payonePaymentLogTransfer->fromArray($apiLog->toArray(), true);
929
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_API_LOG);
930
            $logs[$key] = $payonePaymentLogTransfer;
931
        }
932
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $transactionStatusLog */
933
        foreach ($transactionStatusLogs as $transactionStatusLog) {
934
            $key = $transactionStatusLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 't' . $transactionStatusLog->getIdPaymentPayoneTransactionStatusLog();
935
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
936
            $payonePaymentLogTransfer->fromArray($transactionStatusLog->toArray(), true);
937
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_TRANSACTION_STATUS_LOG);
938
            $logs[$key] = $payonePaymentLogTransfer;
939
        }
940
941
        ksort($logs);
942
943
        $payonePaymentLogCollectionTransfer = new PayonePaymentLogCollectionTransfer();
944
945
        foreach ($logs as $log) {
946
            $payonePaymentLogCollectionTransfer->addPaymentLog($log);
947
        }
948
949
        return $payonePaymentLogCollectionTransfer;
950
    }
951
952
    /**
953
     * @param \Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer
954
     *
955
     * @return array
956
     */
957
    public function getCreditCardCheckRequestData(PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer)
958
    {
959
        $this->standardParameter->fromArray($creditCardCheckRequestDataTransfer->toArray(), true);
960
961
        $creditCardCheck = new CreditCardCheck($this->standardParameter, $this->hashGenerator, $this->modeDetector);
0 ignored issues
show
Bug introduced by
$this->hashGenerator of type SprykerEco\Zed\Payone\Bu...\HmacGeneratorInterface is incompatible with the type SprykerEco\Zed\Payone\Bu...\HashGeneratorInterface expected by parameter $hashGenerator of SprykerEco\Zed\Payone\Bu...ardCheck::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

961
        $creditCardCheck = new CreditCardCheck($this->standardParameter, /** @scrutinizer ignore-type */ $this->hashGenerator, $this->modeDetector);
Loading history...
962
963
        $data = $creditCardCheck->mapCreditCardCheckData();
964
965
        return $data->toArray();
966
    }
967
968
    /**
969
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
970
     *
971
     * @return bool
972
     */
973
    public function isRefundPossible(OrderTransfer $orderTransfer)
974
    {
975
        $paymentTransfer = $this->getPayment($orderTransfer);
976
977
        if (!$this->isPaymentDataRequired($orderTransfer)) {
978
            return true;
979
        }
980
981
        $paymentDetailTransfer = $paymentTransfer->getPaymentDetail();
982
983
        return $paymentDetailTransfer->getBic() && $paymentDetailTransfer->getIban();
984
    }
985
986
    /**
987
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
988
     *
989
     * @return bool
990
     */
991
    public function isPaymentDataRequired(OrderTransfer $orderTransfer)
992
    {
993
        $paymentTransfer = $this->getPayment($orderTransfer);
994
995
        // Return early if we don't need the iban or bic data
996
        $paymentMethod = $paymentTransfer->getPaymentMethod();
997
        $whiteList = [
998
            PayoneApiConstants::PAYMENT_METHOD_E_WALLET,
999
            PayoneApiConstants::PAYMENT_METHOD_CREDITCARD_PSEUDO,
1000
            PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER,
1001
        ];
1002
1003
        if (in_array($paymentMethod, $whiteList)) {
1004
            return false;
1005
        }
1006
1007
        return true;
1008
    }
1009
1010
    /**
1011
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
1012
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
1013
     *
1014
     * @return \Generated\Shared\Transfer\CheckoutResponseTransfer
1015
     */
1016
    public function postSaveHook(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)
1017
    {
1018
        $apiLogsQuery = $this->queryContainer->createLastApiLogsByOrderId($quoteTransfer->getPayment()->getPayone()->getFkSalesOrder());
1019
        $apiLog = $apiLogsQuery->findOne();
1020
1021
        if ($apiLog) {
1022
            $redirectUrl = $apiLog->getRedirectUrl();
1023
1024
            if ($redirectUrl !== null) {
1025
                $checkoutResponse->setIsExternalRedirect(true);
1026
                $checkoutResponse->setRedirectUrl($redirectUrl);
1027
            }
1028
1029
            $errorCode = $apiLog->getErrorCode();
1030
1031
            if ($errorCode) {
1032
                $error = new CheckoutErrorTransfer();
1033
                $error->setMessage($apiLog->getErrorMessageUser());
1034
                $error->setErrorCode($errorCode);
1035
                $checkoutResponse->addError($error);
1036
                $checkoutResponse->setIsSuccess(false);
1037
            }
1038
        }
1039
1040
        return $checkoutResponse;
1041
    }
1042
1043
    /**
1044
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
1045
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
1046
     *
1047
     * @return \Generated\Shared\Transfer\CheckoutResponseTransfer
1048
     */
1049
    public function executeCheckoutPostSaveHook(
1050
        QuoteTransfer $quoteTransfer,
1051
        CheckoutResponseTransfer $checkoutResponse
1052
    ): CheckoutResponseTransfer {
1053
        if ($quoteTransfer->getPayment()->getPaymentProvider() !== PayoneConfig::PROVIDER_NAME) {
1054
            return $checkoutResponse;
1055
        }
1056
1057
        $paymentEntity = $this->getPaymentEntity($checkoutResponse->getSaveOrder()->getIdSalesOrder());
1058
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
1059
        $requestContainer = $this->getPostSaveHookRequestContainer($paymentMethodMapper, $paymentEntity, $quoteTransfer);
1060
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
1061
1062
        if ($responseContainer->getErrorcode()) {
1063
            $checkoutErrorTransfer = new CheckoutErrorTransfer();
1064
            $checkoutErrorTransfer->setMessage($responseContainer->getCustomermessage());
1065
            $checkoutErrorTransfer->setErrorCode($responseContainer->getErrorcode());
1066
            $checkoutResponse->addError($checkoutErrorTransfer);
1067
            $checkoutResponse->setIsSuccess(false);
1068
1069
            return $checkoutResponse;
1070
        }
1071
1072
        if (!$responseContainer->getRedirecturl()) {
1073
            return $checkoutResponse;
1074
        }
1075
1076
        $checkoutResponse->setIsExternalRedirect(true);
1077
        $checkoutResponse->setRedirectUrl($responseContainer->getRedirecturl());
1078
1079
        return $checkoutResponse;
1080
    }
1081
1082
    /**
1083
     * @param \Generated\Shared\Transfer\PaymentDetailTransfer $paymentDataTransfer
1084
     * @param int $idOrder
1085
     *
1086
     * @return void
1087
     */
1088
    public function updatePaymentDetail(PaymentDetailTransfer $paymentDataTransfer, $idOrder)
1089
    {
1090
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
1091
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
1092
1093
        $paymentDetailEntity->fromArray($paymentDataTransfer->toArray());
1094
1095
        $paymentDetailEntity->save();
1096
    }
1097
1098
    /**
1099
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
1100
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
1101
     *
1102
     * @return void
1103
     */
1104
    protected function updatePaymentDetailAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
1105
    {
1106
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
1107
1108
        $paymentDetailEntity->setClearingBankAccountHolder($responseContainer->getClearingBankaccountholder());
1109
        $paymentDetailEntity->setClearingBankCountry($responseContainer->getClearingBankcountry());
1110
        $paymentDetailEntity->setClearingBankAccount($responseContainer->getClearingBankaccount());
1111
        $paymentDetailEntity->setClearingBankCode($responseContainer->getClearingBankcode());
1112
        $paymentDetailEntity->setClearingBankIban($responseContainer->getClearingBankiban());
1113
        $paymentDetailEntity->setClearingBankBic($responseContainer->getClearingBankbic());
1114
        $paymentDetailEntity->setClearingBankCity($responseContainer->getClearingBankcity());
1115
        $paymentDetailEntity->setClearingBankName($responseContainer->getClearingBankname());
1116
1117
        if ($responseContainer->getMandateIdentification()) {
1118
            $paymentDetailEntity->setMandateIdentification($responseContainer->getMandateIdentification());
1119
        }
1120
1121
        if ($paymentEntity->getPaymentMethod() == PayoneApiConstants::PAYMENT_METHOD_INVOICE) {
1122
            $paymentDetailEntity->setInvoiceTitle($this->getInvoiceTitle($paymentEntity->getTransactionId()));
1123
        }
1124
1125
        $paymentDetailEntity->save();
1126
    }
1127
1128
    /**
1129
     * @param \Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer
1130
     *
1131
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1132
     */
1133
    public function initPaypalExpressCheckout(PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer)
1134
    {
1135
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
1136
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
1137
        );
1138
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
0 ignored issues
show
Bug introduced by
The method createBaseGenericPaymentContainer() does not exist on SprykerEco\Zed\Payone\Bu...ntMethodMapperInterface. It seems like you code against a sub-type of SprykerEco\Zed\Payone\Bu...ntMethodMapperInterface such as SprykerEco\Zed\Payone\Bu...odMapper\GenericPayment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1138
        /** @scrutinizer ignore-call */ 
1139
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
Loading history...
1139
        $baseGenericPaymentContainer->getPaydata()->setAction(PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_SET_ACTION);
1140
        $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(
0 ignored issues
show
Bug introduced by
The method mapRequestTransferToGenericPayment() does not exist on SprykerEco\Zed\Payone\Bu...ntMethodMapperInterface. It seems like you code against a sub-type of SprykerEco\Zed\Payone\Bu...ntMethodMapperInterface such as SprykerEco\Zed\Payone\Bu...odMapper\GenericPayment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1140
        /** @scrutinizer ignore-call */ 
1141
        $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(
Loading history...
1141
            $baseGenericPaymentContainer,
1142
            $requestTransfer
1143
        );
1144
        $responseTransfer = $this->performGenericRequest($requestContainer);
1145
1146
        return $responseTransfer;
1147
    }
1148
1149
    /**
1150
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
1151
     *
1152
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1153
     */
1154
    public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer)
1155
    {
1156
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
1157
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
1158
        );
1159
1160
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
1161
        $baseGenericPaymentContainer->getPaydata()->setAction(
1162
            PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION
1163
        );
1164
        $requestContainer = $paymentMethodMapper->mapQuoteTransferToGenericPayment(
0 ignored issues
show
Bug introduced by
The method mapQuoteTransferToGenericPayment() does not exist on SprykerEco\Zed\Payone\Bu...ntMethodMapperInterface. It seems like you code against a sub-type of SprykerEco\Zed\Payone\Bu...ntMethodMapperInterface such as SprykerEco\Zed\Payone\Bu...odMapper\GenericPayment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1164
        /** @scrutinizer ignore-call */ 
1165
        $requestContainer = $paymentMethodMapper->mapQuoteTransferToGenericPayment(
Loading history...
1165
            $baseGenericPaymentContainer,
1166
            $quoteTransfer
1167
        );
1168
        $responseTransfer = $this->performGenericRequest($requestContainer);
1169
1170
        return $responseTransfer;
1171
    }
1172
1173
    /**
1174
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $requestContainer
1175
     *
1176
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1177
     */
1178
    protected function performGenericRequest(GenericPaymentContainer $requestContainer)
1179
    {
1180
        $this->setStandardParameter($requestContainer);
1181
1182
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
1183
        $responseContainer = new GenericPaymentResponseContainer($rawResponse);
1184
        $responseTransfer = new PayonePaypalExpressCheckoutGenericPaymentResponseTransfer();
1185
        $responseTransfer->setRedirectUrl($responseContainer->getRedirectUrl());
1186
        $responseTransfer->setWorkOrderId($responseContainer->getWorkOrderId());
1187
        $responseTransfer->setRawResponse(json_encode($rawResponse));
1188
        $responseTransfer->setStatus($responseContainer->getStatus());
1189
        $responseTransfer->setCustomerMessage($responseContainer->getCustomermessage());
1190
        $responseTransfer->setErrorMessage($responseContainer->getErrormessage());
1191
        $responseTransfer->setErrorCode($responseContainer->getErrorcode());
1192
        $responseTransfer->setEmail($responseContainer->getEmail());
1193
        $responseTransfer->setShippingFirstName($responseContainer->getShippingFirstname());
1194
        $responseTransfer->setShippingLastName($responseContainer->getShippingLastname());
1195
        $responseTransfer->setShippingCompany($responseContainer->getShippingCompany());
1196
        $responseTransfer->setShippingCountry($responseContainer->getShippingCountry());
1197
        $responseTransfer->setShippingState($responseContainer->getShippingState());
1198
        $responseTransfer->setShippingStreet($responseContainer->getShippingStreet());
1199
        $responseTransfer->setShippingAddressAdition($responseContainer->getShippingAddressaddition());
1200
        $responseTransfer->setShippingCity($responseContainer->getShippingCity());
1201
        $responseTransfer->setShippingZip($responseContainer->getShippingZip());
1202
1203
        return $responseTransfer;
1204
    }
1205
1206
    /**
1207
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1208
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1209
     *
1210
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1211
     */
1212
    protected function prepareOrderItems(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1213
    {
1214
        $arrayIt = [];
1215
        $arrayId = [];
1216
        $arrayPr = [];
1217
        $arrayNo = [];
1218
        $arrayDe = [];
1219
        $arrayVa = [];
1220
1221
        $key = 1;
1222
1223
        foreach ($orderTransfer->getItems() as $itemTransfer) {
1224
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
1225
            $arrayId[$key] = $itemTransfer->getSku();
1226
            $arrayPr[$key] = $itemTransfer->getUnitGrossPrice();
1227
            $arrayNo[$key] = $itemTransfer->getQuantity();
1228
            $arrayDe[$key] = $itemTransfer->getName();
1229
            $arrayVa[$key] = (int)$itemTransfer->getTaxRate();
1230
            $key++;
1231
        }
1232
1233
        $container->setIt($arrayIt);
1234
        $container->setId($arrayId);
1235
        $container->setPr($arrayPr);
1236
        $container->setNo($arrayNo);
1237
        $container->setDe($arrayDe);
1238
        $container->setVa($arrayVa);
1239
1240
        return $container;
1241
    }
1242
1243
    /**
1244
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
1245
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1246
     *
1247
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1248
     */
1249
    protected function preparePartialRefundOrderItems(
1250
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
1251
        AbstractRequestContainer $container
1252
    ): AbstractRequestContainer {
1253
        $arrayIt = [];
1254
        $arrayId = [];
1255
        $arrayPr = [];
1256
        $arrayNo = [];
1257
        $arrayDe = [];
1258
        $arrayVa = [];
1259
1260
        $key = 1;
1261
1262
        foreach ($payonePartialOperationRequestTransfer->getOrder()->getItems() as $itemTransfer) {
1263
            if (!in_array($itemTransfer->getIdSalesOrderItem(), $payonePartialOperationRequestTransfer->getSalesOrderItemIds())) {
1264
                continue;
1265
            }
1266
1267
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
1268
            $arrayId[$key] = $itemTransfer->getSku();
1269
            $arrayPr[$key] = $itemTransfer->getRefundableAmount();
1270
            $arrayNo[$key] = $itemTransfer->getQuantity();
1271
            $arrayDe[$key] = $itemTransfer->getName();
1272
            $arrayVa[$key] = (int)$itemTransfer->getTaxRate();
1273
            $key++;
1274
        }
1275
1276
        $container->setIt($arrayIt);
1277
        $container->setId($arrayId);
1278
        $container->setPr($arrayPr);
1279
        $container->setNo($arrayNo);
1280
        $container->setDe($arrayDe);
1281
        $container->setVa($arrayVa);
1282
1283
        return $container;
1284
    }
1285
1286
    /**
1287
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
1288
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1289
     *
1290
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1291
     */
1292
    protected function preparePartialRefundExpenses(
1293
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
1294
        AbstractRequestContainer $container
1295
    ): AbstractRequestContainer {
1296
        $arrayIt = $container->getIt() ?? [];
1297
        $arrayId = $container->getId() ?? [];
1298
        $arrayPr = $container->getPr() ?? [];
1299
        $arrayNo = $container->getNo() ?? [];
1300
        $arrayDe = $container->getDe() ?? [];
1301
        $arrayVa = $container->getVa() ?? [];
1302
1303
        $key = count($arrayId) + 1;
1304
1305
        foreach ($payonePartialOperationRequestTransfer->getRefund()->getExpenses() as $expenseTransfer) {
1306
            $expenseType = PayoneApiConstants::INVOICING_ITEM_TYPE_HANDLING;
1307
            if ($expenseTransfer->getType() === ShipmentConfig::SHIPMENT_EXPENSE_TYPE) {
1308
                $expenseType = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
1309
            }
1310
1311
            $arrayIt[$key] = $expenseType;
1312
            $arrayId[$key] = $expenseType;
1313
            $arrayPr[$key] = $expenseTransfer->getRefundableAmount();
1314
            $arrayNo[$key] = $expenseTransfer->getQuantity();
1315
            $arrayDe[$key] = $expenseTransfer->getName();
1316
            $arrayVa[$key] = (int)$expenseTransfer->getTaxRate();
1317
            $key++;
1318
        }
1319
1320
        $container->setIt($arrayIt);
1321
        $container->setId($arrayId);
1322
        $container->setPr($arrayPr);
1323
        $container->setNo($arrayNo);
1324
        $container->setDe($arrayDe);
1325
        $container->setVa($arrayVa);
1326
1327
        return $container;
1328
    }
1329
1330
    /**
1331
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1332
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1333
     *
1334
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1335
     */
1336
    protected function prepareOrderShipment(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1337
    {
1338
        $arrayIt = $container->getIt() ?? [];
1339
        $arrayId = $container->getId() ?? [];
1340
        $arrayPr = $container->getPr() ?? [];
1341
        $arrayNo = $container->getNo() ?? [];
1342
        $arrayDe = $container->getDe() ?? [];
1343
        $arrayVa = $container->getVa() ?? [];
1344
1345
        $key = count($arrayId) + 1;
1346
1347
        $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
1348
        $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
1349
        $arrayPr[$key] = $this->getDeliveryCosts($orderTransfer);
1350
        $arrayNo[$key] = 1;
1351
        $arrayDe[$key] = 'Shipment';
1352
        $arrayVa[$key] = 0;
1353
1354
        $container->setIt($arrayIt);
1355
        $container->setId($arrayId);
1356
        $container->setPr($arrayPr);
1357
        $container->setNo($arrayNo);
1358
        $container->setDe($arrayDe);
1359
        $container->setVa($arrayVa);
1360
1361
        return $container;
1362
    }
1363
1364
    /**
1365
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1366
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1367
     *
1368
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1369
     */
1370
    protected function prepareOrderDiscount(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1371
    {
1372
        $arrayIt = $container->getIt() ?? [];
1373
        $arrayId = $container->getId() ?? [];
1374
        $arrayPr = $container->getPr() ?? [];
1375
        $arrayNo = $container->getNo() ?? [];
1376
        $arrayDe = $container->getDe() ?? [];
1377
        $arrayVa = $container->getVa() ?? [];
1378
1379
        $key = count($arrayId) + 1;
1380
1381
        $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_VOUCHER;
1382
        $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_VOUCHER;
1383
        $arrayPr[$key] = - $orderTransfer->getTotals()->getDiscountTotal();
1384
        $arrayNo[$key] = 1;
1385
        $arrayDe[$key] = 'Discount';
1386
        $arrayVa[$key] = 0;
1387
1388
        $container->setIt($arrayIt);
1389
        $container->setId($arrayId);
1390
        $container->setPr($arrayPr);
1391
        $container->setNo($arrayNo);
1392
        $container->setDe($arrayDe);
1393
        $container->setVa($arrayVa);
1394
1395
        return $container;
1396
    }
1397
1398
    /**
1399
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1400
     *
1401
     * @return int
1402
     */
1403
    protected function getDeliveryCosts(OrderTransfer $orderTransfer): int
1404
    {
1405
        foreach ($orderTransfer->getExpenses() as $expense) {
1406
            if ($expense->getType() === static::SHIPMENT_EXPENSE_TYPE) {
0 ignored issues
show
Deprecated Code introduced by
The constant SprykerEco\Zed\Payone\Bu...::SHIPMENT_EXPENSE_TYPE has been deprecated: Necessary in order to save compatibility with spryker/shipping version less than "^8.0.0". use \Spryker\Shared\Shipment\ShipmentConfig::SHIPMENT_EXPENSE_TYPE instead if shipping version is higher ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1406
            if ($expense->getType() === /** @scrutinizer ignore-deprecated */ static::SHIPMENT_EXPENSE_TYPE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1407
                return $expense->getSumGrossPrice();
1408
            }
1409
        }
1410
1411
        return 0;
1412
    }
1413
1414
    /**
1415
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1416
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1417
     *
1418
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1419
     */
1420
    protected function prepareOrderHandling(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1421
    {
1422
        $arrayIt = $container->getIt() ?? [];
1423
        $arrayId = $container->getId() ?? [];
1424
        $arrayPr = $container->getPr() ?? [];
1425
        $arrayNo = $container->getNo() ?? [];
1426
        $arrayDe = $container->getDe() ?? [];
1427
        $arrayVa = $container->getVa() ?? [];
1428
1429
        $key = count($arrayId) + 1;
1430
1431
        foreach ($orderTransfer->getExpenses() as $expense) {
1432
            if ($expense->getType() !== static::SHIPMENT_EXPENSE_TYPE) {
0 ignored issues
show
Deprecated Code introduced by
The constant SprykerEco\Zed\Payone\Bu...::SHIPMENT_EXPENSE_TYPE has been deprecated: Necessary in order to save compatibility with spryker/shipping version less than "^8.0.0". use \Spryker\Shared\Shipment\ShipmentConfig::SHIPMENT_EXPENSE_TYPE instead if shipping version is higher ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1432
            if ($expense->getType() !== /** @scrutinizer ignore-deprecated */ static::SHIPMENT_EXPENSE_TYPE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1433
                $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_HANDLING;
1434
                $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_HANDLING;
1435
                $arrayPr[$key] = $expense->getSumGrossPrice();
1436
                $arrayNo[$key] = 1;
1437
                $arrayDe[$key] = 'Handling';
1438
                $arrayVa[$key] = 0;
1439
                $key++;
1440
            }
1441
        }
1442
1443
        $container->setIt($arrayIt);
1444
        $container->setId($arrayId);
1445
        $container->setPr($arrayPr);
1446
        $container->setNo($arrayNo);
1447
        $container->setDe($arrayDe);
1448
        $container->setVa($arrayVa);
1449
1450
        return $container;
1451
    }
1452
1453
    /**
1454
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
1455
     *
1456
     * @return int
1457
     */
1458
    protected function calculatePartialCaptureItemsAmount(PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer): int
1459
    {
1460
        $itemsAmount = 0;
1461
        foreach ($payonePartialOperationRequestTransfer->getOrder()->getItems() as $itemTransfer) {
1462
            if (in_array($itemTransfer->getIdSalesOrderItem(), $payonePartialOperationRequestTransfer->getSalesOrderItemIds())) {
1463
                $itemsAmount += $itemTransfer->getSumPriceToPayAggregation();
1464
            }
1465
        }
1466
1467
        return $itemsAmount;
1468
    }
1469
1470
    /**
1471
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
1472
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1473
     *
1474
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1475
     */
1476
    protected function preparePartialCaptureOrderItems(
1477
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
1478
        AbstractRequestContainer $container
1479
    ): AbstractRequestContainer {
1480
        $arrayIt = [];
1481
        $arrayId = [];
1482
        $arrayPr = [];
1483
        $arrayNo = [];
1484
        $arrayDe = [];
1485
        $arrayVa = [];
1486
1487
        $key = 1;
1488
1489
        foreach ($payonePartialOperationRequestTransfer->getOrder()->getItems() as $itemTransfer) {
1490
            if (!in_array($itemTransfer->getIdSalesOrderItem(), $payonePartialOperationRequestTransfer->getSalesOrderItemIds())) {
1491
                continue;
1492
            }
1493
1494
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
1495
            $arrayId[$key] = substr($itemTransfer->getSku(), 0, 32);
1496
            $arrayPr[$key] = $itemTransfer->getUnitPriceToPayAggregation();
1497
            $arrayNo[$key] = $itemTransfer->getQuantity();
1498
            $arrayDe[$key] = $itemTransfer->getName();
1499
            $arrayVa[$key] = (int)$itemTransfer->getTaxRate();
1500
            $key++;
1501
        }
1502
1503
        $container->setIt($arrayIt);
1504
        $container->setId($arrayId);
1505
        $container->setPr($arrayPr);
1506
        $container->setNo($arrayNo);
1507
        $container->setDe($arrayDe);
1508
        $container->setVa($arrayVa);
1509
1510
        return $container;
1511
    }
1512
1513
    /**
1514
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1515
     *
1516
     * @return int
1517
     */
1518
    protected function calculateExpensesCost(OrderTransfer $orderTransfer): int
1519
    {
1520
        $expensesCostAmount = 0;
1521
1522
        foreach ($orderTransfer->getExpenses() as $expense) {
1523
            if ($expense->getType() !== static::SHIPMENT_EXPENSE_TYPE) {
0 ignored issues
show
Deprecated Code introduced by
The constant SprykerEco\Zed\Payone\Bu...::SHIPMENT_EXPENSE_TYPE has been deprecated: Necessary in order to save compatibility with spryker/shipping version less than "^8.0.0". use \Spryker\Shared\Shipment\ShipmentConfig::SHIPMENT_EXPENSE_TYPE instead if shipping version is higher ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1523
            if ($expense->getType() !== /** @scrutinizer ignore-deprecated */ static::SHIPMENT_EXPENSE_TYPE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
1524
                $expensesCostAmount += $expense->getSumGrossPrice();
1525
            }
1526
        }
1527
1528
        return $expensesCostAmount;
1529
    }
1530
1531
    /**
1532
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer $responseContainer
1533
     *
1534
     * @return string
1535
     */
1536
    protected function getPartialCaptureStatus(CaptureResponseContainer $responseContainer): string
1537
    {
1538
        if ($responseContainer->getStatus() === PayoneApiConstants::RESPONSE_TYPE_APPROVED) {
1539
            return PayoneTransactionStatusConstants::STATUS_CAPTURE_APPROVED;
1540
        }
1541
1542
        return PayoneTransactionStatusConstants::STATUS_CAPTURE_FAILED;
1543
    }
1544
1545
    /**
1546
     * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface $paymentMethodMapper
1547
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
1548
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
1549
     *
1550
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface
1551
     */
1552
    protected function getPostSaveHookRequestContainer(
1553
        PaymentMethodMapperInterface $paymentMethodMapper,
1554
        SpyPaymentPayone $paymentEntity,
1555
        QuoteTransfer $quoteTransfer
1556
    ): AuthorizationContainerInterface {
1557
        if (method_exists($paymentMethodMapper, 'mapPaymentToPreAuthorization')) {
1558
            return $paymentMethodMapper->mapPaymentToPreAuthorization($paymentEntity);
1559
        }
1560
1561
        $orderTransfer = (new OrderTransfer())
1562
            ->setTotals(
1563
                (new TotalsTransfer())
1564
                    ->setGrandTotal($quoteTransfer->getTotals()->getGrandTotal())
1565
            );
1566
1567
        return $paymentMethodMapper->mapPaymentToAuthorization($paymentEntity, $orderTransfer);
1568
    }
1569
}
1570