Passed
Push — master ( 17985b...bb9cd2 )
by Oleksandr
04:32 queued 11s
created

PaymentManager::prepareOrderHandling()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

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

588
        return $this->queryContainer->createPaymentByTransactionIdQuery(/** @scrutinizer ignore-type */ $transactionId)->findOne();
Loading history...
589
    }
590
591
    /**
592
     * @param string $invoiceTitle
593
     * @param int $customerId
594
     *
595
     * @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...
596
     */
597
    protected function findPaymentByInvoiceTitleAndCustomerId($invoiceTitle, $customerId)
598
    {
599
        return $this->queryContainer->createPaymentByInvoiceTitleAndCustomerIdQuery($invoiceTitle, $customerId)->findOne();
600
    }
601
602
    /**
603
     * @param string $fileReference
604
     * @param int $customerId
605
     *
606
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
607
     */
608
    protected function findPaymentByFileReferenceAndCustomerId($fileReference, $customerId)
609
    {
610
        return $this->queryContainer->createPaymentByFileReferenceAndCustomerIdQuery($fileReference, $customerId)->findOne();
611
    }
612
613
    /**
614
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
615
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
616
     *
617
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog
618
     */
619
    protected function initializeApiLog(SpyPaymentPayone $paymentEntity, AbstractRequestContainer $container)
620
    {
621
        $entity = new SpyPaymentPayoneApiLog();
622
        $entity->setSpyPaymentPayone($paymentEntity);
623
        $entity->setRequest($container->getRequest());
624
        $entity->setMode($container->getMode());
625
        $entity->setMerchantId($container->getMid());
626
        $entity->setPortalId($container->getPortalid());
627
        if ($container instanceof CaptureContainer || $container instanceof RefundContainer || $container instanceof DebitContainer) {
628
            $entity->setSequenceNumber($container->getSequenceNumber());
629
        }
630
        // Logging request data for debug
631
        $entity->setRawRequest(json_encode($container->toArray()));
632
        $entity->save();
633
634
        return $entity;
635
    }
636
637
    /**
638
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
639
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
640
     *
641
     * @return void
642
     */
643
    protected function updateApiLogAfterAuthorization(SpyPaymentPayoneApiLog $apiLogEntity, AuthorizationResponseContainer $responseContainer)
644
    {
645
        $apiLogEntity->setStatus($responseContainer->getStatus());
646
        $apiLogEntity->setUserId($responseContainer->getUserid());
647
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
648
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
649
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
650
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
651
        $apiLogEntity->setRedirectUrl($responseContainer->getRedirecturl());
652
        $apiLogEntity->setSequenceNumber(0);
653
654
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
655
        $apiLogEntity->save();
656
    }
657
658
    /**
659
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
660
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer $responseContainer
661
     *
662
     * @return void
663
     */
664
    protected function updateApiLogAfterCapture(SpyPaymentPayoneApiLog $apiLogEntity, CaptureResponseContainer $responseContainer)
665
    {
666
        $apiLogEntity->setStatus($responseContainer->getStatus());
667
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
668
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
669
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
670
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
671
672
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
673
        $apiLogEntity->save();
674
    }
675
676
    /**
677
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
678
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer $responseContainer
679
     *
680
     * @return void
681
     */
682
    protected function updateApiLogAfterDebit(SpyPaymentPayoneApiLog $apiLogEntity, DebitResponseContainer $responseContainer)
683
    {
684
        $apiLogEntity->setStatus($responseContainer->getStatus());
685
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
686
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
687
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
688
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
689
690
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
691
        $apiLogEntity->save();
692
    }
693
694
    /**
695
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
696
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer
697
     *
698
     * @return void
699
     */
700
    protected function updateApiLogAfterRefund(SpyPaymentPayoneApiLog $apiLogEntity, RefundResponseContainer $responseContainer)
701
    {
702
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
703
        $apiLogEntity->setStatus($responseContainer->getStatus());
704
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
705
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
706
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
707
708
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
709
        $apiLogEntity->save();
710
    }
711
712
    /**
713
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
714
     *
715
     * @return void
716
     */
717
    protected function setStandardParameter(AbstractRequestContainer $container)
718
    {
719
        $container->setApiVersion(PayoneApiConstants::API_VERSION_3_9);
720
        $container->setEncoding($this->standardParameter->getEncoding());
721
        $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

721
        $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...
722
        $container->setMid($this->standardParameter->getMid());
723
        $container->setPortalid($this->standardParameter->getPortalId());
724
        $container->setMode($this->modeDetector->getMode());
725
        $container->setIntegratorName(PayoneApiConstants::INTEGRATOR_NAME_SPRYKER);
726
        $container->setIntegratorVersion(PayoneApiConstants::INTEGRATOR_VERSION_3_0_0);
727
        $container->setSolutionName(PayoneApiConstants::SOLUTION_NAME_SPRYKER);
728
        $container->setSolutionVersion(PayoneApiConstants::SOLUTION_VERSION_3_0_0);
729
    }
730
731
    /**
732
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer $container
733
     *
734
     * @return void
735
     */
736
    protected function setAccessDeniedError(AbstractResponseContainer $container)
737
    {
738
        $container->setStatus(PayoneApiConstants::RESPONSE_TYPE_ERROR);
739
        $container->setErrormessage(static::ERROR_ACCESS_DENIED_MESSAGE);
740
        $container->setCustomermessage(static::ERROR_ACCESS_DENIED_MESSAGE);
741
    }
742
743
    /**
744
     * @param int $idOrder
745
     *
746
     * @return \Generated\Shared\Transfer\PaymentDetailTransfer
747
     */
748
    public function getPaymentDetail($idOrder)
749
    {
750
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
751
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
752
        $paymentDetailTransfer = new PaymentDetailTransfer();
753
        $paymentDetailTransfer->fromArray($paymentDetailEntity->toArray(), true);
754
755
        return $paymentDetailTransfer;
756
    }
757
758
    /**
759
     * Gets payment logs (both api and transaction status) for specific orders in chronological order.
760
     *
761
     * @param \Propel\Runtime\Collection\ObjectCollection|\ArrayObject $orders
762
     *
763
     * @return \Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer
764
     */
765
    public function getPaymentLogs($orders)
766
    {
767
        $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

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

769
        $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds(/** @scrutinizer ignore-type */ $orders)->find()->getData();
Loading history...
770
771
        $logs = [];
772
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLog */
773
        foreach ($apiLogs as $apiLog) {
774
            $key = $apiLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 'a' . $apiLog->getIdPaymentPayoneApiLog();
775
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
776
            $payonePaymentLogTransfer->fromArray($apiLog->toArray(), true);
777
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_API_LOG);
778
            $logs[$key] = $payonePaymentLogTransfer;
779
        }
780
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $transactionStatusLog */
781
        foreach ($transactionStatusLogs as $transactionStatusLog) {
782
            $key = $transactionStatusLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 't' . $transactionStatusLog->getIdPaymentPayoneTransactionStatusLog();
783
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
784
            $payonePaymentLogTransfer->fromArray($transactionStatusLog->toArray(), true);
785
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_TRANSACTION_STATUS_LOG);
786
            $logs[$key] = $payonePaymentLogTransfer;
787
        }
788
789
        ksort($logs);
790
791
        $payonePaymentLogCollectionTransfer = new PayonePaymentLogCollectionTransfer();
792
793
        foreach ($logs as $log) {
794
            $payonePaymentLogCollectionTransfer->addPaymentLogs($log);
795
        }
796
797
        return $payonePaymentLogCollectionTransfer;
798
    }
799
800
    /**
801
     * @param \Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer
802
     *
803
     * @return array
804
     */
805
    public function getCreditCardCheckRequestData(PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer)
806
    {
807
        $this->standardParameter->fromArray($creditCardCheckRequestDataTransfer->toArray(), true);
808
809
        $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

809
        $creditCardCheck = new CreditCardCheck($this->standardParameter, /** @scrutinizer ignore-type */ $this->hashGenerator, $this->modeDetector);
Loading history...
810
811
        $data = $creditCardCheck->mapCreditCardCheckData();
812
813
        return $data->toArray();
814
    }
815
816
    /**
817
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
818
     *
819
     * @return bool
820
     */
821
    public function isRefundPossible(OrderTransfer $orderTransfer)
822
    {
823
        $paymentTransfer = $this->getPayment($orderTransfer);
824
825
        if (!$this->isPaymentDataRequired($orderTransfer)) {
826
            return true;
827
        }
828
829
        $paymentDetailTransfer = $paymentTransfer->getPaymentDetail();
830
831
        return $paymentDetailTransfer->getBic() && $paymentDetailTransfer->getIban();
832
    }
833
834
    /**
835
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
836
     *
837
     * @return bool
838
     */
839
    public function isPaymentDataRequired(OrderTransfer $orderTransfer)
840
    {
841
        $paymentTransfer = $this->getPayment($orderTransfer);
842
843
        // Return early if we don't need the iban or bic data
844
        $paymentMethod = $paymentTransfer->getPaymentMethod();
845
        $whiteList = [
846
            PayoneApiConstants::PAYMENT_METHOD_E_WALLET,
847
            PayoneApiConstants::PAYMENT_METHOD_CREDITCARD_PSEUDO,
848
            PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER,
849
        ];
850
851
        if (in_array($paymentMethod, $whiteList)) {
852
            return false;
853
        }
854
855
        return true;
856
    }
857
858
    /**
859
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
860
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
861
     *
862
     * @return \Generated\Shared\Transfer\CheckoutResponseTransfer
863
     */
864
    public function postSaveHook(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)
865
    {
866
        $apiLogsQuery = $this->queryContainer->createLastApiLogsByOrderId($quoteTransfer->getPayment()->getPayone()->getFkSalesOrder());
867
        $apiLog = $apiLogsQuery->findOne();
868
869
        if ($apiLog) {
870
            $redirectUrl = $apiLog->getRedirectUrl();
871
872
            if ($redirectUrl !== null) {
873
                $checkoutResponse->setIsExternalRedirect(true);
874
                $checkoutResponse->setRedirectUrl($redirectUrl);
875
            }
876
877
            $errorCode = $apiLog->getErrorCode();
878
879
            if ($errorCode) {
880
                $error = new CheckoutErrorTransfer();
881
                $error->setMessage($apiLog->getErrorMessageUser());
882
                $error->setErrorCode($errorCode);
883
                $checkoutResponse->addError($error);
884
                $checkoutResponse->setIsSuccess(false);
885
            }
886
        }
887
888
        return $checkoutResponse;
889
    }
890
891
    /**
892
     * @param \Generated\Shared\Transfer\PaymentDetailTransfer $paymentDataTransfer
893
     * @param int $idOrder
894
     *
895
     * @return void
896
     */
897
    public function updatePaymentDetail(PaymentDetailTransfer $paymentDataTransfer, $idOrder)
898
    {
899
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
900
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
901
902
        $paymentDetailEntity->fromArray($paymentDataTransfer->toArray());
903
904
        $paymentDetailEntity->save();
905
    }
906
907
    /**
908
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
909
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
910
     *
911
     * @return void
912
     */
913
    protected function updatePaymentDetailAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
914
    {
915
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
916
917
        $paymentDetailEntity->setClearingBankAccountHolder($responseContainer->getClearingBankaccountholder());
918
        $paymentDetailEntity->setClearingBankCountry($responseContainer->getClearingBankcountry());
919
        $paymentDetailEntity->setClearingBankAccount($responseContainer->getClearingBankaccount());
920
        $paymentDetailEntity->setClearingBankCode($responseContainer->getClearingBankcode());
921
        $paymentDetailEntity->setClearingBankIban($responseContainer->getClearingBankiban());
922
        $paymentDetailEntity->setClearingBankBic($responseContainer->getClearingBankbic());
923
        $paymentDetailEntity->setClearingBankCity($responseContainer->getClearingBankcity());
924
        $paymentDetailEntity->setClearingBankName($responseContainer->getClearingBankname());
925
926
        if ($responseContainer->getMandateIdentification()) {
927
            $paymentDetailEntity->setMandateIdentification($responseContainer->getMandateIdentification());
928
        }
929
930
        if ($paymentEntity->getPaymentMethod() == PayoneApiConstants::PAYMENT_METHOD_INVOICE) {
931
            $paymentDetailEntity->setInvoiceTitle($this->getInvoiceTitle($paymentEntity->getTransactionId()));
932
        }
933
934
        $paymentDetailEntity->save();
935
    }
936
937
    /**
938
     * @param \Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer
939
     *
940
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
941
     */
942
    public function initPaypalExpressCheckout(PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer)
943
    {
944
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
945
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
946
        );
947
        $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

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

949
        /** @scrutinizer ignore-call */ 
950
        $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(
Loading history...
950
            $baseGenericPaymentContainer,
951
            $requestTransfer
952
        );
953
        $responseTransfer = $this->performGenericRequest($requestContainer);
954
955
        return $responseTransfer;
956
    }
957
958
    /**
959
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
960
     *
961
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
962
     */
963
    public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer)
964
    {
965
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
966
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
967
        );
968
969
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
970
        $baseGenericPaymentContainer->getPaydata()->setAction(
971
            PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION
972
        );
973
        $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

973
        /** @scrutinizer ignore-call */ 
974
        $requestContainer = $paymentMethodMapper->mapQuoteTransferToGenericPayment(
Loading history...
974
            $baseGenericPaymentContainer,
975
            $quoteTransfer
976
        );
977
        $responseTransfer = $this->performGenericRequest($requestContainer);
978
979
        return $responseTransfer;
980
    }
981
982
    /**
983
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $requestContainer
984
     *
985
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
986
     */
987
    protected function performGenericRequest(GenericPaymentContainer $requestContainer)
988
    {
989
        $this->setStandardParameter($requestContainer);
990
991
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
992
        $responseContainer = new GenericPaymentResponseContainer($rawResponse);
993
        $responseTransfer = new PayonePaypalExpressCheckoutGenericPaymentResponseTransfer();
994
        $responseTransfer->setRedirectUrl($responseContainer->getRedirectUrl());
995
        $responseTransfer->setWorkOrderId($responseContainer->getWorkOrderId());
996
        $responseTransfer->setRawResponse(json_encode($rawResponse));
997
        $responseTransfer->setStatus($responseContainer->getStatus());
998
        $responseTransfer->setCustomerMessage($responseContainer->getCustomermessage());
999
        $responseTransfer->setErrorMessage($responseContainer->getErrormessage());
1000
        $responseTransfer->setErrorCode($responseContainer->getErrorcode());
1001
        $responseTransfer->setEmail($responseContainer->getEmail());
1002
        $responseTransfer->setShippingFirstName($responseContainer->getShippingFirstname());
1003
        $responseTransfer->setShippingLastName($responseContainer->getShippingLastname());
1004
        $responseTransfer->setShippingCompany($responseContainer->getShippingCompany());
1005
        $responseTransfer->setShippingCountry($responseContainer->getShippingCountry());
1006
        $responseTransfer->setShippingState($responseContainer->getShippingState());
1007
        $responseTransfer->setShippingStreet($responseContainer->getShippingStreet());
1008
        $responseTransfer->setShippingAddressAdition($responseContainer->getShippingAddressaddition());
1009
        $responseTransfer->setShippingCity($responseContainer->getShippingCity());
1010
        $responseTransfer->setShippingZip($responseContainer->getShippingZip());
1011
1012
        return $responseTransfer;
1013
    }
1014
1015
    /**
1016
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1017
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1018
     *
1019
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1020
     */
1021
    protected function prepareOrderItems(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1022
    {
1023
        $arrayIt = [];
1024
        $arrayId = [];
1025
        $arrayPr = [];
1026
        $arrayNo = [];
1027
        $arrayDe = [];
1028
        $arrayVa = [];
1029
1030
        $key = 1;
1031
1032
        foreach ($orderTransfer->getItems() as $itemTransfer) {
1033
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
1034
            $arrayId[$key] = $itemTransfer->getSku();
1035
            $arrayPr[$key] = $itemTransfer->getUnitGrossPrice();
1036
            $arrayNo[$key] = $itemTransfer->getQuantity();
1037
            $arrayDe[$key] = $itemTransfer->getName();
1038
            $arrayVa[$key] = (int)$itemTransfer->getTaxRate();
1039
            $key++;
1040
        }
1041
1042
        $container->setIt($arrayIt);
1043
        $container->setId($arrayId);
1044
        $container->setPr($arrayPr);
1045
        $container->setNo($arrayNo);
1046
        $container->setDe($arrayDe);
1047
        $container->setVa($arrayVa);
1048
1049
        return $container;
1050
    }
1051
1052
    /**
1053
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1054
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1055
     *
1056
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1057
     */
1058
    protected function prepareOrderShipment(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1059
    {
1060
        $arrayIt = $container->getIt() ?? [];
1061
        $arrayId = $container->getId() ?? [];
1062
        $arrayPr = $container->getPr() ?? [];
1063
        $arrayNo = $container->getNo() ?? [];
1064
        $arrayDe = $container->getDe() ?? [];
1065
        $arrayVa = $container->getVa() ?? [];
1066
1067
        $key = count($arrayId) + 1;
1068
        $expenses = $orderTransfer->getExpenses();
1069
1070
        $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
1071
        $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;
1072
        $arrayPr[$key] = $this->getDeliveryCosts($expenses);
1073
        $arrayNo[$key] = 1;
1074
        $arrayDe[$key] = 'Shipment';
1075
1076
        $container->setIt($arrayIt);
1077
        $container->setId($arrayId);
1078
        $container->setPr($arrayPr);
1079
        $container->setNo($arrayNo);
1080
        $container->setDe($arrayDe);
1081
        $container->setVa($arrayVa);
1082
1083
        return $container;
1084
    }
1085
1086
    /**
1087
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1088
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1089
     *
1090
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1091
     */
1092
    protected function prepareOrderDiscount(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1093
    {
1094
        $arrayIt = $container->getIt() ?? [];
1095
        $arrayId = $container->getId() ?? [];
1096
        $arrayPr = $container->getPr() ?? [];
1097
        $arrayNo = $container->getNo() ?? [];
1098
        $arrayDe = $container->getDe() ?? [];
1099
        $arrayVa = $container->getVa() ?? [];
1100
1101
        $key = count($arrayId) + 1;
1102
1103
        $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_VOUCHER;
1104
        $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_VOUCHER;
1105
        $arrayPr[$key] = - $orderTransfer->getTotals()->getDiscountTotal();
1106
        $arrayNo[$key] = 1;
1107
        $arrayDe[$key] = 'Discount';
1108
1109
        $container->setIt($arrayIt);
1110
        $container->setId($arrayId);
1111
        $container->setPr($arrayPr);
1112
        $container->setNo($arrayNo);
1113
        $container->setDe($arrayDe);
1114
        $container->setVa($arrayVa);
1115
1116
        return $container;
1117
    }
1118
1119
    /**
1120
     * @param \ArrayObject $expenses
1121
     *
1122
     * @return string
1123
     */
1124
    protected function getDeliveryCosts(ArrayObject $expenses): string
1125
    {
1126
        foreach ($expenses as $expense) {
1127
            if ($expense->getType() === ShipmentConstants::SHIPMENT_EXPENSE_TYPE) {
1128
                return $expense->getSumGrossPrice();
1129
            }
1130
        }
1131
        return 0;
1132
    }
1133
1134
    /**
1135
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
1136
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
1137
     *
1138
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
1139
     */
1140
    protected function prepareOrderHandling(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer
1141
    {
1142
        $arrayIt = $container->getIt() ?? [];
1143
        $arrayId = $container->getId() ?? [];
1144
        $arrayPr = $container->getPr() ?? [];
1145
        $arrayNo = $container->getNo() ?? [];
1146
        $arrayDe = $container->getDe() ?? [];
1147
        $arrayVa = $container->getVa() ?? [];
1148
1149
        $key = count($arrayId) + 1;
1150
1151
        foreach ($orderTransfer->getExpenses() as $expense) {
1152
            if ($expense->getType() !== ShipmentConstants::SHIPMENT_EXPENSE_TYPE) {
1153
                $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_HANDLING;
1154
                $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_HANDLING;
1155
                $arrayPr[$key] = $expense->getSumGrossPrice();
1156
                $arrayNo[$key] = 1;
1157
                $arrayDe[$key] = 'Handling';
1158
                $key++;
1159
            }
1160
        }
1161
1162
        $container->setIt($arrayIt);
1163
        $container->setId($arrayId);
1164
        $container->setPr($arrayPr);
1165
        $container->setNo($arrayNo);
1166
        $container->setDe($arrayDe);
1167
        $container->setVa($arrayVa);
1168
1169
        return $container;
1170
    }
1171
}
1172