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

PaymentManager::executePartialRefund()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 23
rs 9.7666
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
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
584
585
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
586
        $responseContainer = new RefundResponseContainer($rawResponse);
587
588
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
589
        $this->updatePaymentPayoneOrderItemsWithStatus(
590
            $payonePartialOperationRequestTransfer,
591
            $this->getPartialRefundStatus($responseContainer)
592
        );
593
594
        $responseMapper = new RefundResponseMapper();
595
596
        return $responseMapper->getRefundResponseTransfer($responseContainer);
597
    }
598
599
    /**
600
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
601
     * @param string $refundStatus
602
     *
603
     * @return void
604
     */
605
    protected function updatePaymentPayoneOrderItemsWithStatus(
606
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
607
        string $refundStatus
608
    ): void {
609
        $payoneOrderItemFilterTransfer = (new PayoneOrderItemFilterTransfer())
610
            ->setIdSalesOrder($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder())
611
            ->setSalesOrderItemIds($payonePartialOperationRequestTransfer->getSalesOrderItemIds());
612
613
        $payoneOrderItemTransfers = $this->payoneRepository->findPaymentPayoneOrderItemByFilter($payoneOrderItemFilterTransfer);
614
615
        foreach ($payoneOrderItemTransfers as $payoneOrderItemTransfer) {
616
            $payoneOrderItemTransfer->setStatus($refundStatus);
617
            $this->payoneEntityManager->updatePaymentPayoneOrderItem($payoneOrderItemTransfer);
618
        }
619
    }
620
621
    /**
622
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer
623
     *
624
     * @return string
625
     */
626
    protected function getPartialRefundStatus(RefundResponseContainer $responseContainer): string
627
    {
628
        if ($responseContainer->getStatus() === PayoneApiConstants::RESPONSE_TYPE_APPROVED) {
629
            return PayoneTransactionStatusConstants::STATUS_REFUND_APPROVED;
630
        }
631
632
        return PayoneTransactionStatusConstants::STATUS_REFUND_FAILED;
633
    }
634
635
    /**
636
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
637
     *
638
     * @return \Generated\Shared\Transfer\PayonePaymentTransfer
639
     */
640
    protected function getPayment(OrderTransfer $orderTransfer)
641
    {
642
        $payment = $this->queryContainer->createPaymentByOrderId($orderTransfer->getIdSalesOrder())->findOne();
643
        $paymentDetail = $payment->getSpyPaymentPayoneDetail();
644
645
        $paymentDetailTransfer = new PaymentDetailTransfer();
646
        $paymentDetailTransfer->fromArray($paymentDetail->toArray(), true);
647
648
        $paymentTransfer = new PayonePaymentTransfer();
649
        $paymentTransfer->fromArray($payment->toArray(), true);
650
        $paymentTransfer->setPaymentDetail($paymentDetailTransfer);
651
652
        return $paymentTransfer;
653
    }
654
655
    /**
656
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
657
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
658
     *
659
     * @return void
660
     */
661
    protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
662
    {
663
        $paymentEntity->setTransactionId($responseContainer->getTxid());
664
        $paymentEntity->save();
665
    }
666
667
    /**
668
     * @param string $transactionId
669
     *
670
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
671
     */
672
    protected function findPaymentByTransactionId($transactionId)
673
    {
674
        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

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

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

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

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

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

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

1035
        /** @scrutinizer ignore-call */ 
1036
        $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(
Loading history...
1036
            $baseGenericPaymentContainer,
1037
            $requestTransfer
1038
        );
1039
        $responseTransfer = $this->performGenericRequest($requestContainer);
1040
1041
        return $responseTransfer;
1042
    }
1043
1044
    /**
1045
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
1046
     *
1047
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1048
     */
1049
    public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer)
1050
    {
1051
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
1052
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
1053
        );
1054
1055
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
1056
        $baseGenericPaymentContainer->getPaydata()->setAction(
1057
            PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION
1058
        );
1059
        $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

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