Passed
Pull Request — master (#45)
by Aleksey
05:14
created

PaymentManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 9
dl 0
loc 20
rs 9.9666
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 ArrayObject;
11
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...
12
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...
13
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...
14
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...
15
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...
16
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...
17
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...
18
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...
19
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...
20
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...
21
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...
22
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...
23
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...
24
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...
25
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...
26
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...
27
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...
28
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...
29
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...
30
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...
31
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...
32
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...
33
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...
34
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...
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\ShipmentConstants;
38
use SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface;
39
use SprykerEco\Shared\Payone\PayoneApiConstants;
40
use SprykerEco\Shared\Payone\PayoneTransactionStatusConstants;
41
use SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface;
42
use SprykerEco\Zed\Payone\Business\Api\Call\CreditCardCheck;
43
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
44
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface;
45
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Capture\BusinessContainer;
46
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
47
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
48
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer;
49
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
50
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer;
51
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer;
52
use SprykerEco\Zed\Payone\Business\Api\Response\Container\BankAccountCheckResponseContainer;
53
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer;
54
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CreditCardCheckResponseContainer;
55
use SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer;
56
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GenericPaymentResponseContainer;
57
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetFileResponseContainer;
58
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer;
59
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetSecurityInvoiceResponseContainer;
60
use SprykerEco\Zed\Payone\Business\Api\Response\Container\ManageMandateResponseContainer;
61
use SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer;
62
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\AuthorizationResponseMapper;
63
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CaptureResponseMapper;
64
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CreditCardCheckResponseMapper;
65
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\DebitResponseMapper;
66
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\RefundResponseMapper;
67
use SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException;
68
use SprykerEco\Zed\Payone\Business\Key\HashGenerator;
69
use SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface;
70
use SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface;
71
use SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface;
72
use SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface;
73
use SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface;
74
75
class PaymentManager implements PaymentManagerInterface
76
{
77
    public const LOG_TYPE_API_LOG = 'SpyPaymentPayoneApiLog';
78
    public const LOG_TYPE_TRANSACTION_STATUS_LOG = 'SpyPaymentPayoneTransactionStatusLog';
79
    public const ERROR_ACCESS_DENIED_MESSAGE = 'Access denied';
80
81
    /**
82
     * @var \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
83
     */
84
    protected $executionAdapter;
85
86
    /**
87
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface
88
     */
89
    protected $queryContainer;
90
91
    /**
92
     * @var \Generated\Shared\Transfer\PayoneStandardParameterTransfer
93
     */
94
    protected $standardParameter;
95
96
    /**
97
     * @var \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface
98
     */
99
    protected $sequenceNumberProvider;
100
101
    /**
102
     * @var \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface
103
     */
104
    protected $modeDetector;
105
106
    /**
107
     * @var \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface
108
     */
109
    protected $hashGenerator;
110
111
    /**
112
     * @var \SprykerEco\Zed\Payone\Business\Key\UrlHmacGenerator
113
     */
114
    protected $urlHmacGenerator;
115
116
    /**
117
     * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface[]
118
     */
119
    protected $registeredMethodMappers;
120
121
    /**
122
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface
123
     */
124
    protected $payoneRepository;
125
126
    /**
127
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface
128
     */
129
    protected $payoneEntityManager;
130
131
    /**
132
     * @param \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface $executionAdapter
133
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer
134
     * @param \Generated\Shared\Transfer\PayoneStandardParameterTransfer $standardParameter
135
     * @param \SprykerEco\Zed\Payone\Business\Key\HashGenerator $hashGenerator
136
     * @param \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface $sequenceNumberProvider
137
     * @param \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface $modeDetector
138
     * @param \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface $urlHmacGenerator
139
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface $payoneRepository
140
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface $payoneEntityManager
141
     */
142
    public function __construct(
143
        AdapterInterface $executionAdapter,
144
        PayoneQueryContainerInterface $queryContainer,
145
        PayoneStandardParameterTransfer $standardParameter,
146
        HashGenerator $hashGenerator,
147
        SequenceNumberProviderInterface $sequenceNumberProvider,
148
        ModeDetectorInterface $modeDetector,
149
        HmacGeneratorInterface $urlHmacGenerator,
150
        PayoneRepositoryInterface $payoneRepository,
151
        PayoneEntityManagerInterface $payoneEntityManager
152
    ) {
153
        $this->executionAdapter = $executionAdapter;
154
        $this->queryContainer = $queryContainer;
155
        $this->standardParameter = $standardParameter;
156
        $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...
157
        $this->sequenceNumberProvider = $sequenceNumberProvider;
158
        $this->modeDetector = $modeDetector;
159
        $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...
160
        $this->payoneRepository = $payoneRepository;
161
        $this->payoneEntityManager = $payoneEntityManager;
162
    }
163
164
    /**
165
     * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface $paymentMethodMapper
166
     *
167
     * @return void
168
     */
169
    public function registerPaymentMethodMapper(PaymentMethodMapperInterface $paymentMethodMapper)
170
    {
171
        $paymentMethodMapper->setStandardParameter($this->standardParameter);
172
        $paymentMethodMapper->setSequenceNumberProvider($this->sequenceNumberProvider);
173
        $paymentMethodMapper->setUrlHmacGenerator($this->urlHmacGenerator);
174
        $this->registeredMethodMappers[$paymentMethodMapper->getName()] = $paymentMethodMapper;
175
    }
176
177
    /**
178
     * @param string $name
179
     *
180
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface|null
181
     */
182
    protected function findPaymentMethodMapperByName($name)
183
    {
184
        if (array_key_exists($name, $this->registeredMethodMappers)) {
185
            return $this->registeredMethodMappers[$name];
186
        }
187
188
        return null;
189
    }
190
191
    /**
192
     * @param string $paymentMethodName
193
     *
194
     * @throws \SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException
195
     *
196
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
197
     */
198
    protected function getRegisteredPaymentMethodMapper($paymentMethodName)
199
    {
200
        $paymentMethodMapper = $this->findPaymentMethodMapperByName($paymentMethodName);
201
        if ($paymentMethodMapper === null) {
202
            throw new InvalidPaymentMethodException(
203
                sprintf('No registered payment method mapper found for given method name %s', $paymentMethodName)
204
            );
205
        }
206
207
        return $paymentMethodMapper;
208
    }
209
210
    /**
211
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
212
     *
213
     * @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...
214
     */
215
    public function authorizePayment(OrderTransfer $orderTransfer)
216
    {
217
        $paymentEntity = $this->getPaymentEntity($orderTransfer->getIdSalesOrder());
218
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
219
        $requestContainer = $paymentMethodMapper->mapPaymentToAuthorization($paymentEntity, $orderTransfer);
220
        $requestContainer = $this->prepareOrderItems($orderTransfer, $requestContainer);
221
        $requestContainer = $this->prepareOrderShipment($orderTransfer, $requestContainer);
222
        $requestContainer = $this->prepareOrderDiscount($orderTransfer, $requestContainer);
223
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
224
225
        $responseMapper = new AuthorizationResponseMapper();
226
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
227
228
        return $responseTransfer;
229
    }
230
231
    /**
232
     * @param int $idSalesOrder
233
     *
234
     * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer
235
     */
236
    public function preAuthorizePayment($idSalesOrder)
237
    {
238
        $paymentEntity = $this->getPaymentEntity($idSalesOrder);
239
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
240
        $requestContainer = $paymentMethodMapper->mapPaymentToPreAuthorization($paymentEntity);
241
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
242
243
        $responseMapper = new AuthorizationResponseMapper();
244
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
245
246
        return $responseTransfer;
247
    }
248
249
    /**
250
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
251
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface $requestContainer
252
     *
253
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer
254
     */
255
    protected function performAuthorizationRequest(SpyPaymentPayone $paymentEntity, AuthorizationContainerInterface $requestContainer)
256
    {
257
        $this->setStandardParameter($requestContainer);
258
259
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
260
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
261
        $responseContainer = new AuthorizationResponseContainer($rawResponse);
262
        $this->updatePaymentAfterAuthorization($paymentEntity, $responseContainer);
263
        $this->updateApiLogAfterAuthorization($apiLogEntity, $responseContainer);
264
        $this->updatePaymentDetailAfterAuthorization($paymentEntity, $responseContainer);
265
266
        return $responseContainer;
267
    }
268
269
    /**
270
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
271
     *
272
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
273
     */
274
    protected function getPaymentMethodMapper(SpyPaymentPayone $paymentEntity)
275
    {
276
        return $this->getRegisteredPaymentMethodMapper($paymentEntity->getPaymentMethod());
277
    }
278
279
    /**
280
     * @param int $orderId
281
     *
282
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
283
     */
284
    protected function getPaymentEntity($orderId)
285
    {
286
        return $this->queryContainer->createPaymentById($orderId)->findOne();
287
    }
288
289
    /**
290
     * @param \Generated\Shared\Transfer\PayoneCaptureTransfer $captureTransfer
291
     *
292
     * @return \Generated\Shared\Transfer\CaptureResponseTransfer
293
     */
294
    public function capturePayment(PayoneCaptureTransfer $captureTransfer): CaptureResponseTransfer
295
    {
296
        $paymentEntity = $this->getPaymentEntity($captureTransfer->getPayment()->getFkSalesOrder());
297
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
298
299
        $requestContainer = $paymentMethodMapper->mapPaymentToCapture($paymentEntity);
300
        $requestContainer = $this->prepareOrderItems($captureTransfer->getOrder(), $requestContainer);
301
        $requestContainer = $this->prepareOrderShipment($captureTransfer->getOrder(), $requestContainer);
302
        $requestContainer = $this->prepareOrderDiscount($captureTransfer->getOrder(), $requestContainer);
303
304
        if (!empty($captureTransfer->getSettleaccount())) {
305
            $businnessContainer = new BusinessContainer();
306
            $businnessContainer->setSettleAccount($captureTransfer->getSettleaccount());
307
            $requestContainer->setBusiness($businnessContainer);
308
        }
309
310
        $this->setStandardParameter($requestContainer);
311
312
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
313
314
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
315
        $responseContainer = new CaptureResponseContainer($rawResponse);
316
317
        $this->updateApiLogAfterCapture($apiLogEntity, $responseContainer);
318
319
        $responseMapper = new CaptureResponseMapper();
320
        $responseTransfer = $responseMapper->getCaptureResponseTransfer($responseContainer);
321
322
        return $responseTransfer;
323
    }
324
325
    /**
326
     * @param int $idPayment
327
     *
328
     * @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...
329
     */
330
    public function debitPayment($idPayment)
331
    {
332
        $paymentEntity = $this->getPaymentEntity($idPayment);
333
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
334
335
        $requestContainer = $paymentMethodMapper->mapPaymentToDebit($paymentEntity);
336
        $this->setStandardParameter($requestContainer);
337
338
        $paymentEntity = $this->findPaymentByTransactionId($paymentEntity->getTransactionId());
339
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
340
341
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
342
        $responseContainer = new DebitResponseContainer($rawResponse);
343
344
        $this->updateApiLogAfterDebit($apiLogEntity, $responseContainer);
345
346
        $responseMapper = new DebitResponseMapper();
347
        $responseTransfer = $responseMapper->getDebitResponseTransfer($responseContainer);
348
349
        return $responseTransfer;
350
    }
351
352
    /**
353
     * @param \Generated\Shared\Transfer\PayoneCreditCardTransfer $creditCardData
354
     *
355
     * @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...
356
     */
357
    public function creditCardCheck(PayoneCreditCardTransfer $creditCardData)
358
    {
359
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo $paymentMethodMapper */
360
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper($creditCardData->getPayment()->getPaymentMethod());
361
        $requestContainer = $paymentMethodMapper->mapCreditCardCheck($creditCardData);
362
363
        $this->setStandardParameter($requestContainer);
364
365
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
366
        $responseContainer = new CreditCardCheckResponseContainer($rawResponse);
367
368
        $responseMapper = new CreditCardCheckResponseMapper();
369
        $responseTransfer = $responseMapper->getCreditCardCheckResponseTransfer($responseContainer);
370
371
        return $responseTransfer;
372
    }
373
374
    /**
375
     * @param \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer $bankAccountCheckTransfer
376
     *
377
     * @return \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer
378
     */
379
    public function bankAccountCheck(PayoneBankAccountCheckTransfer $bankAccountCheckTransfer)
380
    {
381
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
382
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER);
383
        $requestContainer = $paymentMethodMapper->mapBankAccountCheck($bankAccountCheckTransfer);
384
        $this->setStandardParameter($requestContainer);
385
386
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
387
        $responseContainer = new BankAccountCheckResponseContainer($rawResponse);
388
389
        $bankAccountCheckTransfer->setErrorCode($responseContainer->getErrorcode());
390
        $bankAccountCheckTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
391
        $bankAccountCheckTransfer->setStatus($responseContainer->getStatus());
392
        $bankAccountCheckTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
393
394
        return $bankAccountCheckTransfer;
395
    }
396
397
    /**
398
     * @param \Generated\Shared\Transfer\PayoneManageMandateTransfer $manageMandateTransfer
399
     *
400
     * @return \Generated\Shared\Transfer\PayoneManageMandateTransfer
401
     */
402
    public function manageMandate(PayoneManageMandateTransfer $manageMandateTransfer)
403
    {
404
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
405
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
406
        $requestContainer = $paymentMethodMapper->mapManageMandate($manageMandateTransfer);
407
        $this->setStandardParameter($requestContainer);
408
409
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
410
        $responseContainer = new ManageMandateResponseContainer($rawResponse);
411
412
        $manageMandateTransfer->setErrorCode($responseContainer->getErrorcode());
413
        $manageMandateTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
414
        $manageMandateTransfer->setStatus($responseContainer->getStatus());
415
        $manageMandateTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
416
        $manageMandateTransfer->setMandateIdentification($responseContainer->getMandateIdentification());
417
        $manageMandateTransfer->setMandateText($responseContainer->getMandateText());
418
        $manageMandateTransfer->setIban($responseContainer->getIban());
419
        $manageMandateTransfer->setBic($responseContainer->getBic());
420
421
        return $manageMandateTransfer;
422
    }
423
424
    /**
425
     * @param \Generated\Shared\Transfer\PayoneGetFileTransfer $getFileTransfer
426
     *
427
     * @return \Generated\Shared\Transfer\PayoneGetFileTransfer
428
     */
429
    public function getFile(PayoneGetFileTransfer $getFileTransfer)
430
    {
431
        $responseContainer = new GetFileResponseContainer();
432
        $paymentEntity = $this->findPaymentByFileReferenceAndCustomerId(
433
            $getFileTransfer->getReference(),
434
            $getFileTransfer->getCustomerId()
435
        );
436
437
        if ($paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery, thus it always evaluated to true.
Loading history...
438
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
439
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
440
            $requestContainer = $paymentMethodMapper->mapGetFile($getFileTransfer);
441
            $this->setStandardParameter($requestContainer);
442
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
443
            $responseContainer->init($rawResponse);
444
        } else {
445
            $this->setAccessDeniedError($responseContainer);
446
        }
447
448
        $getFileTransfer->setRawResponse($responseContainer->getRawResponse());
449
        $getFileTransfer->setStatus($responseContainer->getStatus());
450
        $getFileTransfer->setErrorCode($responseContainer->getErrorcode());
451
        $getFileTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
452
        $getFileTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
453
454
        return $getFileTransfer;
455
    }
456
457
    /**
458
     * @param \Generated\Shared\Transfer\PayoneGetInvoiceTransfer $getInvoiceTransfer
459
     *
460
     * @return \Generated\Shared\Transfer\PayoneGetInvoiceTransfer
461
     */
462
    public function getInvoice(PayoneGetInvoiceTransfer $getInvoiceTransfer)
463
    {
464
        $responseContainer = new GetInvoiceResponseContainer();
465
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
466
            $getInvoiceTransfer->getReference(),
467
            $getInvoiceTransfer->getCustomerId()
468
        );
469
470
        if ($paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery, thus it always evaluated to true.
Loading history...
471
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice $paymentMethodMapper */
472
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_INVOICE);
473
            $requestContainer = $paymentMethodMapper->mapGetInvoice($getInvoiceTransfer);
474
            $this->setStandardParameter($requestContainer);
475
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
476
            $responseContainer->init($rawResponse);
477
        } else {
478
            $this->setAccessDeniedError($responseContainer);
479
        }
480
481
        $getInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
482
        $getInvoiceTransfer->setStatus($responseContainer->getStatus());
483
        $getInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
484
        $getInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
485
486
        return $getInvoiceTransfer;
487
    }
488
489
    /**
490
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
491
     *
492
     * @return \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer
493
     */
494
    public function getSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer): PayoneGetSecurityInvoiceTransfer
495
    {
496
        $responseContainer = new GetSecurityInvoiceResponseContainer();
497
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
498
            $getSecurityInvoiceTransfer->getReference(),
499
            $getSecurityInvoiceTransfer->getCustomerId()
500
        );
501
502
        if (!$paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery, thus it always evaluated to true.
Loading history...
503
            $this->setAccessDeniedError($responseContainer);
504
505
            return $getSecurityInvoiceTransfer;
506
        }
507
508
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\SecurityInvoice $paymentMethodMapper */
509
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE);
510
        $requestContainer = $paymentMethodMapper->mapGetSecurityInvoice($getSecurityInvoiceTransfer);
511
        $this->setStandardParameter($requestContainer);
512
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
513
        $responseContainer->init($rawResponse);
514
515
        $getSecurityInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
516
        $getSecurityInvoiceTransfer->setStatus($responseContainer->getStatus());
517
        $getSecurityInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
518
        $getSecurityInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
519
520
        return $getSecurityInvoiceTransfer;
521
    }
522
523
    /**
524
     * @param int $transactionId
525
     *
526
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer
527
     */
528
    public function getInvoiceTitle($transactionId)
529
    {
530
        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...
531
            PayoneApiConstants::INVOICE_TITLE_PREFIX_INVOICE,
532
            $transactionId,
533
            0,
534
        ]);
535
    }
536
537
    /**
538
     * @param \Generated\Shared\Transfer\PayoneRefundTransfer $refundTransfer
539
     *
540
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
541
     */
542
    public function refundPayment(PayoneRefundTransfer $refundTransfer)
543
    {
544
        $payonePaymentTransfer = $refundTransfer->getPayment();
545
546
        $paymentEntity = $this->getPaymentEntity($payonePaymentTransfer->getFkSalesOrder());
547
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
548
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
549
        $requestContainer->setAmount(0 - $paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
550
        $requestContainer = $this->prepareOrderItems($refundTransfer->getOrder(), $requestContainer);
551
        $requestContainer = $this->prepareOrderShipment($refundTransfer->getOrder(), $requestContainer);
552
        $requestContainer = $this->prepareOrderDiscount($refundTransfer->getOrder(), $requestContainer);
553
554
        $this->setStandardParameter($requestContainer);
555
556
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
557
558
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
559
        $responseContainer = new RefundResponseContainer($rawResponse);
560
561
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
562
563
        $responseMapper = new RefundResponseMapper();
564
        $responseTransfer = $responseMapper->getRefundResponseTransfer($responseContainer);
565
566
        return $responseTransfer;
567
    }
568
569
    /**
570
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
571
     *
572
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
573
     */
574
    public function executePartialRefund(PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer): RefundResponseTransfer
575
    {
576
        $paymentEntity = $this->getPaymentEntity($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder());
577
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
578
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
579
580
        $requestContainer->setAmount($payonePartialOperationRequestTransfer->getRefund()->getAmount() * -1);
581
        $requestContainer = $this->preparePartialRefundOrderItems($payonePartialOperationRequestTransfer, $requestContainer);
582
        $this->setStandardParameter($requestContainer);
583
584
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
585
        $responseContainer = new RefundResponseContainer($rawResponse);
586
587
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
588
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
589
590
        $refundStatus = PayoneTransactionStatusConstants::STATUS_REFUND_FAILED;
591
        if ($responseContainer->getStatus() === PayoneApiConstants::RESPONSE_TYPE_APPROVED) {
592
            $refundStatus = PayoneTransactionStatusConstants::STATUS_REFUND_APPROVED;
593
        }
594
595
        $this->updatePaymentPayoneOrderItemsWithStatus($payonePartialOperationRequestTransfer, $refundStatus);
596
597
        $responseMapper = new RefundResponseMapper();
598
599
        return $responseMapper->getRefundResponseTransfer($responseContainer);
600
    }
601
602
    /**
603
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
604
     * @param string $refundStatus
605
     *
606
     * @return void
607
     */
608
    protected function updatePaymentPayoneOrderItemsWithStatus(
609
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
610
        string $refundStatus
611
    ): void {
612
        $payoneOrderItemFilterTransfer = (new PayoneOrderItemFilterTransfer())
613
            ->setIdSalesOrder($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder())
614
            ->setSalesOrderItemIds($payonePartialOperationRequestTransfer->getSalesOrderItemIds());
615
616
        $payoneOrderItemTransfers = $this->payoneRepository->findPaymentPayoneOrderItemByFilter($payoneOrderItemFilterTransfer);
617
618
        foreach ($payoneOrderItemTransfers as $payoneOrderItemTransfer) {
619
            $payoneOrderItemTransfer->setStatus($refundStatus);
620
            $this->payoneEntityManager->updatePaymentPayoneOrderItem($payoneOrderItemTransfer);
621
        }
622
    }
623
624
    /**
625
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
626
     *
627
     * @return \Generated\Shared\Transfer\PayonePaymentTransfer
628
     */
629
    protected function getPayment(OrderTransfer $orderTransfer)
630
    {
631
        $payment = $this->queryContainer->createPaymentByOrderId($orderTransfer->getIdSalesOrder())->findOne();
632
        $paymentDetail = $payment->getSpyPaymentPayoneDetail();
633
634
        $paymentDetailTransfer = new PaymentDetailTransfer();
635
        $paymentDetailTransfer->fromArray($paymentDetail->toArray(), true);
636
637
        $paymentTransfer = new PayonePaymentTransfer();
638
        $paymentTransfer->fromArray($payment->toArray(), true);
639
        $paymentTransfer->setPaymentDetail($paymentDetailTransfer);
640
641
        return $paymentTransfer;
642
    }
643
644
    /**
645
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
646
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
647
     *
648
     * @return void
649
     */
650
    protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
651
    {
652
        $paymentEntity->setTransactionId($responseContainer->getTxid());
653
        $paymentEntity->save();
654
    }
655
656
    /**
657
     * @param string $transactionId
658
     *
659
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
660
     */
661
    protected function findPaymentByTransactionId($transactionId)
662
    {
663
        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

663
        return $this->queryContainer->createPaymentByTransactionIdQuery(/** @scrutinizer ignore-type */ $transactionId)->findOne();
Loading history...
664
    }
665
666
    /**
667
     * @param string $invoiceTitle
668
     * @param int $customerId
669
     *
670
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery 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...
671
     */
672
    protected function findPaymentByInvoiceTitleAndCustomerId($invoiceTitle, $customerId)
673
    {
674
        return $this->queryContainer->createPaymentByInvoiceTitleAndCustomerIdQuery($invoiceTitle, $customerId)->findOne();
675
    }
676
677
    /**
678
     * @param string $fileReference
679
     * @param int $customerId
680
     *
681
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
682
     */
683
    protected function findPaymentByFileReferenceAndCustomerId($fileReference, $customerId)
684
    {
685
        return $this->queryContainer->createPaymentByFileReferenceAndCustomerIdQuery($fileReference, $customerId)->findOne();
686
    }
687
688
    /**
689
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
690
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
691
     *
692
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog
693
     */
694
    protected function initializeApiLog(SpyPaymentPayone $paymentEntity, AbstractRequestContainer $container)
695
    {
696
        $entity = new SpyPaymentPayoneApiLog();
697
        $entity->setSpyPaymentPayone($paymentEntity);
698
        $entity->setRequest($container->getRequest());
699
        $entity->setMode($container->getMode());
700
        $entity->setMerchantId($container->getMid());
701
        $entity->setPortalId($container->getPortalid());
702
        if ($container instanceof CaptureContainer || $container instanceof RefundContainer || $container instanceof DebitContainer) {
703
            $entity->setSequenceNumber($container->getSequenceNumber());
704
        }
705
        // Logging request data for debug
706
        $entity->setRawRequest(json_encode($container->toArray()));
707
        $entity->save();
708
709
        return $entity;
710
    }
711
712
    /**
713
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
714
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
715
     *
716
     * @return void
717
     */
718
    protected function updateApiLogAfterAuthorization(SpyPaymentPayoneApiLog $apiLogEntity, AuthorizationResponseContainer $responseContainer)
719
    {
720
        $apiLogEntity->setStatus($responseContainer->getStatus());
721
        $apiLogEntity->setUserId($responseContainer->getUserid());
722
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
723
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
724
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
725
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
726
        $apiLogEntity->setRedirectUrl($responseContainer->getRedirecturl());
727
        $apiLogEntity->setSequenceNumber(0);
728
729
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
730
        $apiLogEntity->save();
731
    }
732
733
    /**
734
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
735
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer $responseContainer
736
     *
737
     * @return void
738
     */
739
    protected function updateApiLogAfterCapture(SpyPaymentPayoneApiLog $apiLogEntity, CaptureResponseContainer $responseContainer)
740
    {
741
        $apiLogEntity->setStatus($responseContainer->getStatus());
742
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
743
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
744
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
745
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
746
747
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
748
        $apiLogEntity->save();
749
    }
750
751
    /**
752
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
753
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer $responseContainer
754
     *
755
     * @return void
756
     */
757
    protected function updateApiLogAfterDebit(SpyPaymentPayoneApiLog $apiLogEntity, DebitResponseContainer $responseContainer)
758
    {
759
        $apiLogEntity->setStatus($responseContainer->getStatus());
760
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
761
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
762
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
763
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
764
765
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
766
        $apiLogEntity->save();
767
    }
768
769
    /**
770
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
771
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer
772
     *
773
     * @return void
774
     */
775
    protected function updateApiLogAfterRefund(SpyPaymentPayoneApiLog $apiLogEntity, RefundResponseContainer $responseContainer)
776
    {
777
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
778
        $apiLogEntity->setStatus($responseContainer->getStatus());
779
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
780
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
781
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
782
783
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
784
        $apiLogEntity->save();
785
    }
786
787
    /**
788
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
789
     *
790
     * @return void
791
     */
792
    protected function setStandardParameter(AbstractRequestContainer $container)
793
    {
794
        $container->setApiVersion(PayoneApiConstants::API_VERSION_3_9);
795
        $container->setEncoding($this->standardParameter->getEncoding());
796
        $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

796
        $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...
797
        $container->setMid($this->standardParameter->getMid());
798
        $container->setPortalid($this->standardParameter->getPortalId());
799
        $container->setMode($this->modeDetector->getMode());
800
        $container->setIntegratorName(PayoneApiConstants::INTEGRATOR_NAME_SPRYKER);
801
        $container->setIntegratorVersion(PayoneApiConstants::INTEGRATOR_VERSION_3_0_0);
802
        $container->setSolutionName(PayoneApiConstants::SOLUTION_NAME_SPRYKER);
803
        $container->setSolutionVersion(PayoneApiConstants::SOLUTION_VERSION_3_0_0);
804
    }
805
806
    /**
807
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer $container
808
     *
809
     * @return void
810
     */
811
    protected function setAccessDeniedError(AbstractResponseContainer $container)
812
    {
813
        $container->setStatus(PayoneApiConstants::RESPONSE_TYPE_ERROR);
814
        $container->setErrormessage(static::ERROR_ACCESS_DENIED_MESSAGE);
815
        $container->setCustomermessage(static::ERROR_ACCESS_DENIED_MESSAGE);
816
    }
817
818
    /**
819
     * @param int $idOrder
820
     *
821
     * @return \Generated\Shared\Transfer\PaymentDetailTransfer
822
     */
823
    public function getPaymentDetail($idOrder)
824
    {
825
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
826
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
827
        $paymentDetailTransfer = new PaymentDetailTransfer();
828
        $paymentDetailTransfer->fromArray($paymentDetailEntity->toArray(), true);
829
830
        return $paymentDetailTransfer;
831
    }
832
833
    /**
834
     * Gets payment logs (both api and transaction status) for specific orders in chronological order.
835
     *
836
     * @param \Propel\Runtime\Collection\ObjectCollection|\ArrayObject $orders
837
     *
838
     * @return \Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer
839
     */
840
    public function getPaymentLogs($orders)
841
    {
842
        $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

842
        $apiLogs = $this->queryContainer->createApiLogsByOrderIds(/** @scrutinizer ignore-type */ $orders)->find()->getData();
Loading history...
843
844
        $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

844
        $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds(/** @scrutinizer ignore-type */ $orders)->find()->getData();
Loading history...
845
846
        $logs = [];
847
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLog */
848
        foreach ($apiLogs as $apiLog) {
849
            $key = $apiLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 'a' . $apiLog->getIdPaymentPayoneApiLog();
850
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
851
            $payonePaymentLogTransfer->fromArray($apiLog->toArray(), true);
852
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_API_LOG);
853
            $logs[$key] = $payonePaymentLogTransfer;
854
        }
855
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $transactionStatusLog */
856
        foreach ($transactionStatusLogs as $transactionStatusLog) {
857
            $key = $transactionStatusLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 't' . $transactionStatusLog->getIdPaymentPayoneTransactionStatusLog();
858
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
859
            $payonePaymentLogTransfer->fromArray($transactionStatusLog->toArray(), true);
860
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_TRANSACTION_STATUS_LOG);
861
            $logs[$key] = $payonePaymentLogTransfer;
862
        }
863
864
        ksort($logs);
865
866
        $payonePaymentLogCollectionTransfer = new PayonePaymentLogCollectionTransfer();
867
868
        foreach ($logs as $log) {
869
            $payonePaymentLogCollectionTransfer->addPaymentLogs($log);
870
        }
871
872
        return $payonePaymentLogCollectionTransfer;
873
    }
874
875
    /**
876
     * @param \Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer
877
     *
878
     * @return array
879
     */
880
    public function getCreditCardCheckRequestData(PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer)
881
    {
882
        $this->standardParameter->fromArray($creditCardCheckRequestDataTransfer->toArray(), true);
883
884
        $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

884
        $creditCardCheck = new CreditCardCheck($this->standardParameter, /** @scrutinizer ignore-type */ $this->hashGenerator, $this->modeDetector);
Loading history...
885
886
        $data = $creditCardCheck->mapCreditCardCheckData();
887
888
        return $data->toArray();
889
    }
890
891
    /**
892
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
893
     *
894
     * @return bool
895
     */
896
    public function isRefundPossible(OrderTransfer $orderTransfer)
897
    {
898
        $paymentTransfer = $this->getPayment($orderTransfer);
899
900
        if (!$this->isPaymentDataRequired($orderTransfer)) {
901
            return true;
902
        }
903
904
        $paymentDetailTransfer = $paymentTransfer->getPaymentDetail();
905
906
        return $paymentDetailTransfer->getBic() && $paymentDetailTransfer->getIban();
907
    }
908
909
    /**
910
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
911
     *
912
     * @return bool
913
     */
914
    public function isPaymentDataRequired(OrderTransfer $orderTransfer)
915
    {
916
        $paymentTransfer = $this->getPayment($orderTransfer);
917
918
        // Return early if we don't need the iban or bic data
919
        $paymentMethod = $paymentTransfer->getPaymentMethod();
920
        $whiteList = [
921
            PayoneApiConstants::PAYMENT_METHOD_E_WALLET,
922
            PayoneApiConstants::PAYMENT_METHOD_CREDITCARD_PSEUDO,
923
            PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER,
924
        ];
925
926
        if (in_array($paymentMethod, $whiteList)) {
927
            return false;
928
        }
929
930
        return true;
931
    }
932
933
    /**
934
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
935
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
936
     *
937
     * @return \Generated\Shared\Transfer\CheckoutResponseTransfer
938
     */
939
    public function postSaveHook(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)
940
    {
941
        $apiLogsQuery = $this->queryContainer->createLastApiLogsByOrderId($quoteTransfer->getPayment()->getPayone()->getFkSalesOrder());
942
        $apiLog = $apiLogsQuery->findOne();
943
944
        if ($apiLog) {
945
            $redirectUrl = $apiLog->getRedirectUrl();
946
947
            if ($redirectUrl !== null) {
948
                $checkoutResponse->setIsExternalRedirect(true);
949
                $checkoutResponse->setRedirectUrl($redirectUrl);
950
            }
951
952
            $errorCode = $apiLog->getErrorCode();
953
954
            if ($errorCode) {
955
                $error = new CheckoutErrorTransfer();
956
                $error->setMessage($apiLog->getErrorMessageUser());
957
                $error->setErrorCode($errorCode);
958
                $checkoutResponse->addError($error);
959
                $checkoutResponse->setIsSuccess(false);
960
            }
961
        }
962
963
        return $checkoutResponse;
964
    }
965
966
    /**
967
     * @param \Generated\Shared\Transfer\PaymentDetailTransfer $paymentDataTransfer
968
     * @param int $idOrder
969
     *
970
     * @return void
971
     */
972
    public function updatePaymentDetail(PaymentDetailTransfer $paymentDataTransfer, $idOrder)
973
    {
974
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
975
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
976
977
        $paymentDetailEntity->fromArray($paymentDataTransfer->toArray());
978
979
        $paymentDetailEntity->save();
980
    }
981
982
    /**
983
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
984
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
985
     *
986
     * @return void
987
     */
988
    protected function updatePaymentDetailAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
989
    {
990
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
991
992
        $paymentDetailEntity->setClearingBankAccountHolder($responseContainer->getClearingBankaccountholder());
993
        $paymentDetailEntity->setClearingBankCountry($responseContainer->getClearingBankcountry());
994
        $paymentDetailEntity->setClearingBankAccount($responseContainer->getClearingBankaccount());
995
        $paymentDetailEntity->setClearingBankCode($responseContainer->getClearingBankcode());
996
        $paymentDetailEntity->setClearingBankIban($responseContainer->getClearingBankiban());
997
        $paymentDetailEntity->setClearingBankBic($responseContainer->getClearingBankbic());
998
        $paymentDetailEntity->setClearingBankCity($responseContainer->getClearingBankcity());
999
        $paymentDetailEntity->setClearingBankName($responseContainer->getClearingBankname());
1000
1001
        if ($responseContainer->getMandateIdentification()) {
1002
            $paymentDetailEntity->setMandateIdentification($responseContainer->getMandateIdentification());
1003
        }
1004
1005
        if ($paymentEntity->getPaymentMethod() == PayoneApiConstants::PAYMENT_METHOD_INVOICE) {
1006
            $paymentDetailEntity->setInvoiceTitle($this->getInvoiceTitle($paymentEntity->getTransactionId()));
1007
        }
1008
1009
        $paymentDetailEntity->save();
1010
    }
1011
1012
    /**
1013
     * @param \Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer
1014
     *
1015
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1016
     */
1017
    public function initPaypalExpressCheckout(PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer)
1018
    {
1019
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
1020
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
1021
        );
1022
        $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

1022
        /** @scrutinizer ignore-call */ 
1023
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
Loading history...
1023
        $baseGenericPaymentContainer->getPaydata()->setAction(PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_SET_ACTION);
1024
        $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

1024
        /** @scrutinizer ignore-call */ 
1025
        $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(
Loading history...
1025
            $baseGenericPaymentContainer,
1026
            $requestTransfer
1027
        );
1028
        $responseTransfer = $this->performGenericRequest($requestContainer);
1029
1030
        return $responseTransfer;
1031
    }
1032
1033
    /**
1034
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
1035
     *
1036
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1037
     */
1038
    public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer)
1039
    {
1040
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
1041
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
1042
        );
1043
1044
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
1045
        $baseGenericPaymentContainer->getPaydata()->setAction(
1046
            PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION
1047
        );
1048
        $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

1048
        /** @scrutinizer ignore-call */ 
1049
        $requestContainer = $paymentMethodMapper->mapQuoteTransferToGenericPayment(
Loading history...
1049
            $baseGenericPaymentContainer,
1050
            $quoteTransfer
1051
        );
1052
        $responseTransfer = $this->performGenericRequest($requestContainer);
1053
1054
        return $responseTransfer;
1055
    }
1056
1057
    /**
1058
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $requestContainer
1059
     *
1060
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1061
     */
1062
    protected function performGenericRequest(GenericPaymentContainer $requestContainer)
1063
    {
1064
        $this->setStandardParameter($requestContainer);
1065
1066
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
1067
        $responseContainer = new GenericPaymentResponseContainer($rawResponse);
1068
        $responseTransfer = new PayonePaypalExpressCheckoutGenericPaymentResponseTransfer();
1069
        $responseTransfer->setRedirectUrl($responseContainer->getRedirectUrl());
1070
        $responseTransfer->setWorkOrderId($responseContainer->getWorkOrderId());
1071
        $responseTransfer->setRawResponse(json_encode($rawResponse));
1072
        $responseTransfer->setStatus($responseContainer->getStatus());
1073
        $responseTransfer->setCustomerMessage($responseContainer->getCustomermessage());
1074
        $responseTransfer->setErrorMessage($responseContainer->getErrormessage());
1075
        $responseTransfer->setErrorCode($responseContainer->getErrorcode());
1076
        $responseTransfer->setEmail($responseContainer->getEmail());
1077
        $responseTransfer->setShippingFirstName($responseContainer->getShippingFirstname());
1078
        $responseTransfer->setShippingLastName($responseContainer->getShippingLastname());
1079
        $responseTransfer->setShippingCompany($responseContainer->getShippingCompany());
1080
        $responseTransfer->setShippingCountry($responseContainer->getShippingCountry());
1081
        $responseTransfer->setShippingState($responseContainer->getShippingState());
1082
        $responseTransfer->setShippingStreet($responseContainer->getShippingStreet());
1083
        $responseTransfer->setShippingAddressAdition($responseContainer->getShippingAddressaddition());
1084
        $responseTransfer->setShippingCity($responseContainer->getShippingCity());
1085
        $responseTransfer->setShippingZip($responseContainer->getShippingZip());
1086
1087
        return $responseTransfer;
1088
    }
1089
1090
    /**
1091
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1092
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1093
     *
1094
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1095
     */
1096
    protected function prepareOrderItems(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1097
    {
1098
        $arrayIt = [];
1099
        $arrayId = [];
1100
        $arrayPr = [];
1101
        $arrayNo = [];
1102
        $arrayDe = [];
1103
        $arrayVa = [];
1104
1105
        $key = 1;
1106
1107
        foreach ($orderTransfer->getItems() as $itemTransfer) {
1108
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
1109
            $arrayId[$key] = $itemTransfer->getSku();
1110
            $arrayPr[$key] = $itemTransfer->getUnitGrossPrice();
1111
            $arrayNo[$key] = $itemTransfer->getQuantity();
1112
            $arrayDe[$key] = $itemTransfer->getName();
1113
            $arrayVa[$key] = (int)$itemTransfer->getTaxRate();
1114
            $key++;
1115
        }
1116
1117
        $container->setIt($arrayIt);
1118
        $container->setId($arrayId);
1119
        $container->setPr($arrayPr);
1120
        $container->setNo($arrayNo);
1121
        $container->setDe($arrayDe);
1122
        $container->setVa($arrayVa);
1123
1124
        return $container;
1125
    }
1126
1127
    /**
1128
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
1129
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1130
     *
1131
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1132
     */
1133
    protected function preparePartialRefundOrderItems(
1134
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
1135
        AbstractRequestContainer $container
1136
    ): AbstractRequestContainer {
1137
        $arrayIt = [];
1138
        $arrayId = [];
1139
        $arrayPr = [];
1140
        $arrayNo = [];
1141
        $arrayDe = [];
1142
        $arrayVa = [];
1143
1144
        $key = 1;
1145
1146
        foreach ($payonePartialOperationRequestTransfer->getOrder()->getItems() as $itemTransfer) {
1147
            if (!in_array($itemTransfer->getIdSalesOrderItem(), $payonePartialOperationRequestTransfer->getSalesOrderItemIds())) {
1148
                continue;
1149
            }
1150
1151
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
1152
            $arrayId[$key] = $itemTransfer->getSku();
1153
            $arrayPr[$key] = $itemTransfer->getRefundableAmount();
1154
            $arrayNo[$key] = $itemTransfer->getQuantity();
1155
            $arrayDe[$key] = $itemTransfer->getName();
1156
            $arrayVa[$key] = (int)$itemTransfer->getTaxRate();
1157
            $key++;
1158
        }
1159
1160
        $container->setIt($arrayIt);
1161
        $container->setId($arrayId);
1162
        $container->setPr($arrayPr);
1163
        $container->setNo($arrayNo);
1164
        $container->setDe($arrayDe);
1165
        $container->setVa($arrayVa);
1166
1167
        return $container;
1168
    }
1169
1170
    /**
1171
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1172
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1173
     *
1174
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1175
     */
1176
    protected function prepareOrderShipment(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1177
    {
1178
        $arrayIt = $container->getIt() ?? [];
1179
        $arrayId = $container->getId() ?? [];
1180
        $arrayPr = $container->getPr() ?? [];
1181
        $arrayNo = $container->getNo() ?? [];
1182
        $arrayDe = $container->getDe() ?? [];
1183
        $arrayVa = $container->getVa() ?? [];
1184
1185
        $key = count($arrayId) + 1;
1186
        $expenses = $orderTransfer->getExpenses();
1187
1188
        $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
1189
        $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
1190
        $arrayPr[$key] = $this->getDeliveryCosts($expenses);
1191
        $arrayNo[$key] = 1;
1192
        $arrayDe[$key] = 'Shipment';
1193
1194
        $container->setIt($arrayIt);
1195
        $container->setId($arrayId);
1196
        $container->setPr($arrayPr);
1197
        $container->setNo($arrayNo);
1198
        $container->setDe($arrayDe);
1199
        $container->setVa($arrayVa);
1200
1201
        return $container;
1202
    }
1203
1204
    /**
1205
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1206
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1207
     *
1208
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1209
     */
1210
    protected function prepareOrderDiscount(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1211
    {
1212
        $arrayIt = $container->getIt() ?? [];
1213
        $arrayId = $container->getId() ?? [];
1214
        $arrayPr = $container->getPr() ?? [];
1215
        $arrayNo = $container->getNo() ?? [];
1216
        $arrayDe = $container->getDe() ?? [];
1217
        $arrayVa = $container->getVa() ?? [];
1218
1219
        $key = count($arrayId) + 1;
1220
1221
        $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_VOUCHER;
1222
        $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_VOUCHER;
1223
        $arrayPr[$key] = - $orderTransfer->getTotals()->getDiscountTotal();
1224
        $arrayNo[$key] = 1;
1225
        $arrayDe[$key] = 'Discount';
1226
1227
        $container->setIt($arrayIt);
1228
        $container->setId($arrayId);
1229
        $container->setPr($arrayPr);
1230
        $container->setNo($arrayNo);
1231
        $container->setDe($arrayDe);
1232
        $container->setVa($arrayVa);
1233
1234
        return $container;
1235
    }
1236
1237
    /**
1238
     * @param \ArrayObject $expenses
1239
     *
1240
     * @return string
1241
     */
1242
    protected function getDeliveryCosts(ArrayObject $expenses): string
1243
    {
1244
        foreach ($expenses as $expense) {
1245
            if ($expense->getType() === ShipmentConstants::SHIPMENT_EXPENSE_TYPE) {
1246
                return $expense->getSumGrossPrice();
1247
            }
1248
        }
1249
1250
        return 0;
1251
    }
1252
}
1253