Passed
Pull Request — master (#23)
by Volodymyr
48:37
created

PaymentManager::getSecurityInvoice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
dl 26
loc 26
c 0
b 0
f 0
rs 9.504
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Business\Payment;
9
10
use Generated\Shared\Transfer\CheckoutErrorTransfer;
11
use Generated\Shared\Transfer\CheckoutResponseTransfer;
12
use Generated\Shared\Transfer\OrderTransfer;
13
use Generated\Shared\Transfer\PaymentDetailTransfer;
14
use Generated\Shared\Transfer\PayoneBankAccountCheckTransfer;
15
use Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer;
16
use Generated\Shared\Transfer\PayoneCreditCardTransfer;
17
use Generated\Shared\Transfer\PayoneGetFileTransfer;
18
use Generated\Shared\Transfer\PayoneGetInvoiceTransfer;
19
use Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer;
20
use Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer;
21
use Generated\Shared\Transfer\PayoneManageMandateTransfer;
22
use Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer;
23
use Generated\Shared\Transfer\PayonePaymentLogTransfer;
24
use Generated\Shared\Transfer\PayonePaymentTransfer;
25
use Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer;
26
use Generated\Shared\Transfer\PayoneRefundTransfer;
27
use Generated\Shared\Transfer\PayoneStandardParameterTransfer;
28
use Generated\Shared\Transfer\QuoteTransfer;
29
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
30
use Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog;
31
use SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface;
32
use SprykerEco\Shared\Payone\PayoneApiConstants;
33
use SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface;
34
use SprykerEco\Zed\Payone\Business\Api\Call\CreditCardCheck;
35
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
36
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface;
37
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Capture\BusinessContainer;
38
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
39
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
40
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer;
41
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
42
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer;
43
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer;
44
use SprykerEco\Zed\Payone\Business\Api\Response\Container\BankAccountCheckResponseContainer;
45
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer;
46
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CreditCardCheckResponseContainer;
47
use SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer;
48
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GenericPaymentResponseContainer;
49
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetFileResponseContainer;
50
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer;
51
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetSecurityInvoiceResponseContainer;
52
use SprykerEco\Zed\Payone\Business\Api\Response\Container\ManageMandateResponseContainer;
53
use SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer;
54
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\AuthorizationResponseMapper;
55
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CaptureResponseMapper;
56
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CreditCardCheckResponseMapper;
57
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\DebitResponseMapper;
58
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\RefundResponseMapper;
59
use SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException;
60
use SprykerEco\Zed\Payone\Business\Key\HashGenerator;
61
use SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface;
62
use SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface;
63
use SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface;
64
65
class PaymentManager implements PaymentManagerInterface
66
{
67
    const LOG_TYPE_API_LOG = 'SpyPaymentPayoneApiLog';
68
    const LOG_TYPE_TRANSACTION_STATUS_LOG = 'SpyPaymentPayoneTransactionStatusLog';
69
    const ERROR_ACCESS_DENIED_MESSAGE = 'Access denied';
70
71
    /**
72
     * @var \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
73
     */
74
    protected $executionAdapter;
75
76
    /**
77
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface
78
     */
79
    protected $queryContainer;
80
81
    /**
82
     * @var \Generated\Shared\Transfer\PayoneStandardParameterTransfer
83
     */
84
    protected $standardParameter;
85
86
    /**
87
     * @var \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface
88
     */
89
    protected $sequenceNumberProvider;
90
91
    /**
92
     * @var \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface
93
     */
94
    protected $modeDetector;
95
96
    /**
97
     * @var \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface
98
     */
99
    protected $hashGenerator;
100
101
    /**
102
     * @var \SprykerEco\Zed\Payone\Business\Key\UrlHmacGenerator
103
     */
104
    protected $urlHmacGenerator;
105
106
    /**
107
     * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface[]
108
     */
109
    protected $registeredMethodMappers;
110
111
    /**
112
     * @param \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface $executionAdapter
113
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer
114
     * @param \Generated\Shared\Transfer\PayoneStandardParameterTransfer $standardParameter
115
     * @param \SprykerEco\Zed\Payone\Business\Key\HashGenerator $hashGenerator
116
     * @param \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface $sequenceNumberProvider
117
     * @param \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface $modeDetector
118
     * @param \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface $urlHmacGenerator
119
     */
120
    public function __construct(
121
        AdapterInterface $executionAdapter,
122
        PayoneQueryContainerInterface $queryContainer,
123
        PayoneStandardParameterTransfer $standardParameter,
124
        HashGenerator $hashGenerator,
125
        SequenceNumberProviderInterface $sequenceNumberProvider,
126
        ModeDetectorInterface $modeDetector,
127
        HmacGeneratorInterface $urlHmacGenerator
128
    ) {
129
130
        $this->executionAdapter = $executionAdapter;
131
        $this->queryContainer = $queryContainer;
132
        $this->standardParameter = $standardParameter;
133
        $this->hashGenerator = $hashGenerator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $hashGenerator of type object<SprykerEco\Zed\Pa...ness\Key\HashGenerator> is incompatible with the declared type object<SprykerEco\Zed\Pa...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...
134
        $this->sequenceNumberProvider = $sequenceNumberProvider;
135
        $this->modeDetector = $modeDetector;
136
        $this->urlHmacGenerator = $urlHmacGenerator;
0 ignored issues
show
Documentation Bug introduced by
$urlHmacGenerator is of type object<SprykerEco\Zed\Pa...HmacGeneratorInterface>, but the property $urlHmacGenerator was declared to be of type object<SprykerEco\Zed\Pa...s\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...
137
    }
138
139
    /**
140
     * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface $paymentMethodMapper
141
     *
142
     * @return void
143
     */
144
    public function registerPaymentMethodMapper(PaymentMethodMapperInterface $paymentMethodMapper)
145
    {
146
        $paymentMethodMapper->setStandardParameter($this->standardParameter);
147
        $paymentMethodMapper->setSequenceNumberProvider($this->sequenceNumberProvider);
148
        $paymentMethodMapper->setUrlHmacGenerator($this->urlHmacGenerator);
149
        $this->registeredMethodMappers[$paymentMethodMapper->getName()] = $paymentMethodMapper;
150
    }
151
152
    /**
153
     * @param string $name
154
     *
155
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface|null
156
     */
157
    protected function findPaymentMethodMapperByName($name)
158
    {
159
        if (array_key_exists($name, $this->registeredMethodMappers)) {
160
            return $this->registeredMethodMappers[$name];
161
        }
162
163
        return null;
164
    }
165
166
    /**
167
     * @param string $paymentMethodName
168
     *
169
     * @throws \SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException
170
     *
171
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
172
     */
173
    protected function getRegisteredPaymentMethodMapper($paymentMethodName)
174
    {
175
        $paymentMethodMapper = $this->findPaymentMethodMapperByName($paymentMethodName);
176
        if ($paymentMethodMapper === null) {
177
            throw new InvalidPaymentMethodException(
178
                sprintf('No registered payment method mapper found for given method name %s', $paymentMethodName)
179
            );
180
        }
181
182
        return $paymentMethodMapper;
183
    }
184
185
    /**
186
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
187
     *
188
     * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer
189
     */
190 View Code Duplication
    public function authorizePayment(OrderTransfer $orderTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
191
    {
192
        $paymentEntity = $this->getPaymentEntity($orderTransfer->getIdSalesOrder());
193
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
194
        $requestContainer = $paymentMethodMapper->mapPaymentToAuthorization($paymentEntity, $orderTransfer);
195
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
196
197
        $responseMapper = new AuthorizationResponseMapper();
198
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
199
200
        return $responseTransfer;
201
    }
202
203
    /**
204
     * @param int $idSalesOrder
205
     *
206
     * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer
207
     */
208 View Code Duplication
    public function preAuthorizePayment($idSalesOrder)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
209
    {
210
        $paymentEntity = $this->getPaymentEntity($idSalesOrder);
211
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
212
        $requestContainer = $paymentMethodMapper->mapPaymentToPreAuthorization($paymentEntity);
213
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
214
215
        $responseMapper = new AuthorizationResponseMapper();
216
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
217
218
        return $responseTransfer;
219
    }
220
221
    /**
222
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
223
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface $requestContainer
224
     *
225
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer
226
     */
227
    protected function performAuthorizationRequest(SpyPaymentPayone $paymentEntity, AuthorizationContainerInterface $requestContainer)
228
    {
229
        $this->setStandardParameter($requestContainer);
0 ignored issues
show
Documentation introduced by
$requestContainer is of type object<SprykerEco\Zed\Pa...tionContainerInterface>, but the function expects a object<SprykerEco\Zed\Pa...stractRequestContainer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
230
231
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
0 ignored issues
show
Documentation introduced by
$requestContainer is of type object<SprykerEco\Zed\Pa...tionContainerInterface>, but the function expects a object<SprykerEco\Zed\Pa...stractRequestContainer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
232
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
0 ignored issues
show
Documentation introduced by
$requestContainer is of type object<SprykerEco\Zed\Pa...tionContainerInterface>, but the function expects a object<SprykerEco\Zed\Pa...stractRequestContainer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
233
        $responseContainer = new AuthorizationResponseContainer($rawResponse);
234
        $this->updatePaymentAfterAuthorization($paymentEntity, $responseContainer);
235
        $this->updateApiLogAfterAuthorization($apiLogEntity, $responseContainer);
236
        $this->updatePaymentDetailAfterAuthorization($paymentEntity, $responseContainer);
237
238
        return $responseContainer;
239
    }
240
241
    /**
242
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
243
     *
244
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
245
     */
246
    protected function getPaymentMethodMapper(SpyPaymentPayone $paymentEntity)
247
    {
248
        return $this->getRegisteredPaymentMethodMapper($paymentEntity->getPaymentMethod());
249
    }
250
251
    /**
252
     * @param int $orderId
253
     *
254
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
255
     */
256
    protected function getPaymentEntity($orderId)
257
    {
258
        return $this->queryContainer->createPaymentById($orderId)->findOne();
259
    }
260
261
    /**
262
     * @param \Generated\Shared\Transfer\PayoneCaptureTransfer $captureTransfer
263
     *
264
     * @return \Generated\Shared\Transfer\CaptureResponseTransfer
265
     */
266
    public function capturePayment($captureTransfer)
267
    {
268
        $paymentEntity = $this->getPaymentEntity($captureTransfer->getPayment()->getFkSalesOrder());
269
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
270
271
        $requestContainer = $paymentMethodMapper->mapPaymentToCapture($paymentEntity);
272
        $requestContainer->setAmount($captureTransfer->getAmount());
273
274
        if (!empty($captureTransfer->getSettleaccount())) {
275
            $businnessContainer = new BusinessContainer();
276
            $businnessContainer->setSettleAccount($captureTransfer->getSettleaccount());
277
            $requestContainer->setBusiness($businnessContainer);
278
        }
279
280
        $this->setStandardParameter($requestContainer);
281
282
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
283
284
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
285
        $responseContainer = new CaptureResponseContainer($rawResponse);
286
287
        $this->updateApiLogAfterCapture($apiLogEntity, $responseContainer);
288
289
        $responseMapper = new CaptureResponseMapper();
290
        $responseTransfer = $responseMapper->getCaptureResponseTransfer($responseContainer);
291
292
        return $responseTransfer;
293
    }
294
295
    /**
296
     * @param int $idPayment
297
     *
298
     * @return \Generated\Shared\Transfer\DebitResponseTransfer
299
     */
300
    public function debitPayment($idPayment)
301
    {
302
        $paymentEntity = $this->getPaymentEntity($idPayment);
303
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
304
305
        $requestContainer = $paymentMethodMapper->mapPaymentToDebit($paymentEntity);
306
        $this->setStandardParameter($requestContainer);
307
308
        $paymentEntity = $this->findPaymentByTransactionId($paymentEntity->getTransactionId());
309
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
310
311
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
312
        $responseContainer = new DebitResponseContainer($rawResponse);
313
314
        $this->updateApiLogAfterDebit($apiLogEntity, $responseContainer);
315
316
        $responseMapper = new DebitResponseMapper();
317
        $responseTransfer = $responseMapper->getDebitResponseTransfer($responseContainer);
318
319
        return $responseTransfer;
320
    }
321
322
    /**
323
     * @param \Generated\Shared\Transfer\PayoneCreditCardTransfer $creditCardData
324
     *
325
     * @return \Generated\Shared\Transfer\CreditCardCheckResponseTransfer
326
     */
327
    public function creditCardCheck(PayoneCreditCardTransfer $creditCardData)
328
    {
329
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo $paymentMethodMapper */
330
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper($creditCardData->getPayment()->getPaymentMethod());
331
        $requestContainer = $paymentMethodMapper->mapCreditCardCheck($creditCardData);
332
333
        $this->setStandardParameter($requestContainer);
334
335
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
336
        $responseContainer = new CreditCardCheckResponseContainer($rawResponse);
337
338
        $responseMapper = new CreditCardCheckResponseMapper();
339
        $responseTransfer = $responseMapper->getCreditCardCheckResponseTransfer($responseContainer);
340
341
        return $responseTransfer;
342
    }
343
344
    /**
345
     * @param \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer $bankAccountCheckTransfer
346
     *
347
     * @return \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer
348
     */
349
    public function bankAccountCheck(PayoneBankAccountCheckTransfer $bankAccountCheckTransfer)
350
    {
351
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
352
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER);
353
        $requestContainer = $paymentMethodMapper->mapBankAccountCheck($bankAccountCheckTransfer);
354
        $this->setStandardParameter($requestContainer);
355
356
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
357
        $responseContainer = new BankAccountCheckResponseContainer($rawResponse);
358
359
        $bankAccountCheckTransfer->setErrorCode($responseContainer->getErrorcode());
360
        $bankAccountCheckTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
361
        $bankAccountCheckTransfer->setStatus($responseContainer->getStatus());
362
        $bankAccountCheckTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
363
364
        return $bankAccountCheckTransfer;
365
    }
366
367
    /**
368
     * @param \Generated\Shared\Transfer\PayoneManageMandateTransfer $manageMandateTransfer
369
     *
370
     * @return \Generated\Shared\Transfer\PayoneManageMandateTransfer
371
     */
372
    public function manageMandate(PayoneManageMandateTransfer $manageMandateTransfer)
373
    {
374
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
375
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
376
        $requestContainer = $paymentMethodMapper->mapManageMandate($manageMandateTransfer);
377
        $this->setStandardParameter($requestContainer);
378
379
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
380
        $responseContainer = new ManageMandateResponseContainer($rawResponse);
381
382
        $manageMandateTransfer->setErrorCode($responseContainer->getErrorcode());
383
        $manageMandateTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
384
        $manageMandateTransfer->setStatus($responseContainer->getStatus());
385
        $manageMandateTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
386
        $manageMandateTransfer->setMandateIdentification($responseContainer->getMandateIdentification());
387
        $manageMandateTransfer->setMandateText($responseContainer->getMandateText());
388
        $manageMandateTransfer->setIban($responseContainer->getIban());
389
        $manageMandateTransfer->setBic($responseContainer->getBic());
390
391
        return $manageMandateTransfer;
392
    }
393
394
    /**
395
     * @param \Generated\Shared\Transfer\PayoneGetFileTransfer $getFileTransfer
396
     *
397
     * @return \Generated\Shared\Transfer\PayoneGetFileTransfer
398
     */
399 View Code Duplication
    public function getFile(PayoneGetFileTransfer $getFileTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
400
    {
401
        $responseContainer = new GetFileResponseContainer();
402
        $paymentEntity = $this->findPaymentByFileReferenceAndCustomerId(
403
            $getFileTransfer->getReference(),
404
            $getFileTransfer->getCustomerId()
405
        );
406
407
        if ($paymentEntity) {
408
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
409
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
410
            $requestContainer = $paymentMethodMapper->mapGetFile($getFileTransfer);
411
            $this->setStandardParameter($requestContainer);
412
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
413
            $responseContainer->init($rawResponse);
414
        } else {
415
            $this->setAccessDeniedError($responseContainer);
416
        }
417
418
        $getFileTransfer->setRawResponse($responseContainer->getRawResponse());
419
        $getFileTransfer->setStatus($responseContainer->getStatus());
420
        $getFileTransfer->setErrorCode($responseContainer->getErrorcode());
421
        $getFileTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
422
        $getFileTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
423
424
        return $getFileTransfer;
425
    }
426
427
    /**
428
     * @param \Generated\Shared\Transfer\PayoneGetInvoiceTransfer $getInvoiceTransfer
429
     *
430
     * @return \Generated\Shared\Transfer\PayoneGetInvoiceTransfer
431
     */
432 View Code Duplication
    public function getInvoice(PayoneGetInvoiceTransfer $getInvoiceTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
433
    {
434
        $responseContainer = new GetInvoiceResponseContainer();
435
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
436
            $getInvoiceTransfer->getReference(),
437
            $getInvoiceTransfer->getCustomerId()
438
        );
439
440
        if ($paymentEntity) {
441
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice $paymentMethodMapper */
442
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_INVOICE);
443
            $requestContainer = $paymentMethodMapper->mapGetInvoice($getInvoiceTransfer);
444
            $this->setStandardParameter($requestContainer);
445
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
446
            $responseContainer->init($rawResponse);
447
        } else {
448
            $this->setAccessDeniedError($responseContainer);
449
        }
450
451
        $getInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
452
        $getInvoiceTransfer->setStatus($responseContainer->getStatus());
453
        $getInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
454
        $getInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
455
456
        return $getInvoiceTransfer;
457
    }
458
459
    /**
460
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
461
     *
462
     * @return \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer
463
     */
464 View Code Duplication
    public function getSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
    {
466
        $responseContainer = new GetSecurityInvoiceResponseContainer();
467
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
468
            $getSecurityInvoiceTransfer->getReference(),
469
            $getSecurityInvoiceTransfer->getCustomerId()
470
        );
471
472
        if ($paymentEntity) {
473
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice $paymentMethodMapper */
474
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE);
475
            $requestContainer = $paymentMethodMapper->mapGetSecurityInvoice($getSecurityInvoiceTransfer);
476
            $this->setStandardParameter($requestContainer);
477
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
478
            $responseContainer->init($rawResponse);
479
        } else {
480
            $this->setAccessDeniedError($responseContainer);
481
        }
482
483
        $getSecurityInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
484
        $getSecurityInvoiceTransfer->setStatus($responseContainer->getStatus());
485
        $getSecurityInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
486
        $getSecurityInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
487
488
        return $getSecurityInvoiceTransfer;
489
    }
490
491
    /**
492
     * @param int $transactionId
493
     *
494
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer
495
     */
496
    public function getInvoiceTitle($transactionId)
497
    {
498
        return implode('-', [
499
            PayoneApiConstants::INVOICE_TITLE_PREFIX_INVOICE,
500
            $transactionId,
501
            0,
502
        ]);
503
    }
504
505
    /**
506
     * @param \Generated\Shared\Transfer\PayoneRefundTransfer $refundTransfer
507
     *
508
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
509
     */
510
    public function refundPayment(PayoneRefundTransfer $refundTransfer)
511
    {
512
        $payonePaymentTransfer = $refundTransfer->getPayment();
513
514
        $paymentEntity = $this->getPaymentEntity($payonePaymentTransfer->getFkSalesOrder());
515
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
516
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
517
        $requestContainer->setAmount($refundTransfer->getAmount());
518
        $this->setStandardParameter($requestContainer);
519
520
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
521
522
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
523
        $responseContainer = new RefundResponseContainer($rawResponse);
524
525
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
526
527
        $responseMapper = new RefundResponseMapper();
528
        $responseTransfer = $responseMapper->getRefundResponseTransfer($responseContainer);
529
530
        return $responseTransfer;
531
    }
532
533
    /**
534
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
535
     *
536
     * @return \Generated\Shared\Transfer\PayonePaymentTransfer
537
     */
538
    protected function getPayment(OrderTransfer $orderTransfer)
539
    {
540
        $payment = $this->queryContainer->createPaymentByOrderId($orderTransfer->getIdSalesOrder())->findOne();
541
        $paymentDetail = $payment->getSpyPaymentPayoneDetail();
542
543
        $paymentDetailTransfer = new PaymentDetailTransfer();
544
        $paymentDetailTransfer->fromArray($paymentDetail->toArray(), true);
545
546
        $paymentTransfer = new PayonePaymentTransfer();
547
        $paymentTransfer->fromArray($payment->toArray(), true);
548
        $paymentTransfer->setPaymentDetail($paymentDetailTransfer);
549
550
        return $paymentTransfer;
551
    }
552
553
    /**
554
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
555
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
556
     *
557
     * @return void
558
     */
559
    protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
560
    {
561
        $paymentEntity->setTransactionId($responseContainer->getTxid());
562
        $paymentEntity->save();
563
    }
564
565
    /**
566
     * @param string $transactionId
567
     *
568
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
569
     */
570
    protected function findPaymentByTransactionId($transactionId)
571
    {
572
        return $this->queryContainer->createPaymentByTransactionIdQuery($transactionId)->findOne();
573
    }
574
575
    /**
576
     * @param string $invoiceTitle
577
     * @param int $customerId
578
     *
579
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
580
     */
581
    protected function findPaymentByInvoiceTitleAndCustomerId($invoiceTitle, $customerId)
582
    {
583
        return $this->queryContainer->createPaymentByInvoiceTitleAndCustomerIdQuery($invoiceTitle, $customerId)->findOne();
584
    }
585
586
    /**
587
     * @param string $fileReference
588
     * @param int $customerId
589
     *
590
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery
591
     */
592
    protected function findPaymentByFileReferenceAndCustomerId($fileReference, $customerId)
593
    {
594
        return $this->queryContainer->createPaymentByFileReferenceAndCustomerIdQuery($fileReference, $customerId)->findOne();
595
    }
596
597
    /**
598
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
599
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
600
     *
601
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog
602
     */
603
    protected function initializeApiLog(SpyPaymentPayone $paymentEntity, AbstractRequestContainer $container)
604
    {
605
        $entity = new SpyPaymentPayoneApiLog();
606
        $entity->setSpyPaymentPayone($paymentEntity);
607
        $entity->setRequest($container->getRequest());
608
        $entity->setMode($container->getMode());
609
        $entity->setMerchantId($container->getMid());
610
        $entity->setPortalId($container->getPortalid());
611
        if ($container instanceof CaptureContainer || $container instanceof RefundContainer || $container instanceof DebitContainer) {
612
            $entity->setSequenceNumber($container->getSequenceNumber());
613
        }
614
        // Logging request data for debug
615
        $entity->setRawRequest(json_encode($container->toArray()));
616
        $entity->save();
617
618
        return $entity;
619
    }
620
621
    /**
622
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
623
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
624
     *
625
     * @return void
626
     */
627
    protected function updateApiLogAfterAuthorization(SpyPaymentPayoneApiLog $apiLogEntity, AuthorizationResponseContainer $responseContainer)
628
    {
629
        $apiLogEntity->setStatus($responseContainer->getStatus());
630
        $apiLogEntity->setUserId($responseContainer->getUserid());
631
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
632
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
633
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
634
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
635
        $apiLogEntity->setRedirectUrl($responseContainer->getRedirecturl());
636
        $apiLogEntity->setSequenceNumber(0);
637
638
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
639
        $apiLogEntity->save();
640
    }
641
642
    /**
643
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
644
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer $responseContainer
645
     *
646
     * @return void
647
     */
648 View Code Duplication
    protected function updateApiLogAfterCapture(SpyPaymentPayoneApiLog $apiLogEntity, CaptureResponseContainer $responseContainer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
649
    {
650
        $apiLogEntity->setStatus($responseContainer->getStatus());
651
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
652
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
653
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
654
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
655
656
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
657
        $apiLogEntity->save();
658
    }
659
660
    /**
661
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
662
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer $responseContainer
663
     *
664
     * @return void
665
     */
666 View Code Duplication
    protected function updateApiLogAfterDebit(SpyPaymentPayoneApiLog $apiLogEntity, DebitResponseContainer $responseContainer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
667
    {
668
        $apiLogEntity->setStatus($responseContainer->getStatus());
669
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
670
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
671
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
672
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
673
674
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
675
        $apiLogEntity->save();
676
    }
677
678
    /**
679
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity
680
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer
681
     *
682
     * @return void
683
     */
684 View Code Duplication
    protected function updateApiLogAfterRefund(SpyPaymentPayoneApiLog $apiLogEntity, RefundResponseContainer $responseContainer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
685
    {
686
        $apiLogEntity->setTransactionId($responseContainer->getTxid());
687
        $apiLogEntity->setStatus($responseContainer->getStatus());
688
        $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());
689
        $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());
690
        $apiLogEntity->setErrorCode($responseContainer->getErrorcode());
691
692
        $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));
693
        $apiLogEntity->save();
694
    }
695
696
    /**
697
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container
698
     *
699
     * @return void
700
     */
701
    protected function setStandardParameter(AbstractRequestContainer $container)
702
    {
703
        $container->setApiVersion(PayoneApiConstants::API_VERSION_3_9);
704
        $container->setEncoding($this->standardParameter->getEncoding());
705
        $container->setKey($this->hashGenerator->hash($this->standardParameter->getKey()));
0 ignored issues
show
Bug introduced by
The call to hash() misses a required argument $key.

This check looks for function calls that miss required arguments.

Loading history...
706
        $container->setMid($this->standardParameter->getMid());
707
        $container->setPortalid($this->standardParameter->getPortalId());
708
        $container->setMode($this->modeDetector->getMode());
709
        $container->setIntegratorName(PayoneApiConstants::INTEGRATOR_NAME_SPRYKER);
710
        $container->setIntegratorVersion(PayoneApiConstants::INTEGRATOR_VERSION_3_0_0);
711
        $container->setSolutionName(PayoneApiConstants::SOLUTION_NAME_SPRYKER);
712
        $container->setSolutionVersion(PayoneApiConstants::SOLUTION_VERSION_3_0_0);
713
    }
714
715
    /**
716
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer $container
717
     *
718
     * @return void
719
     */
720
    protected function setAccessDeniedError(AbstractResponseContainer $container)
721
    {
722
        $container->setStatus(PayoneApiConstants::RESPONSE_TYPE_ERROR);
723
        $container->setErrormessage(static::ERROR_ACCESS_DENIED_MESSAGE);
724
        $container->setCustomermessage(static::ERROR_ACCESS_DENIED_MESSAGE);
725
    }
726
727
    /**
728
     * @param int $idOrder
729
     *
730
     * @return \Generated\Shared\Transfer\PaymentDetailTransfer
731
     */
732 View Code Duplication
    public function getPaymentDetail($idOrder)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
733
    {
734
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
735
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
736
        $paymentDetailTransfer = new PaymentDetailTransfer();
737
        $paymentDetailTransfer->fromArray($paymentDetailEntity->toArray(), true);
738
739
        return $paymentDetailTransfer;
740
    }
741
742
    /**
743
     * Gets payment logs (both api and transaction status) for specific orders in chronological order.
744
     *
745
     * @param \Propel\Runtime\Collection\ObjectCollection|\ArrayObject $orders
746
     *
747
     * @return \Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer
748
     */
749
    public function getPaymentLogs($orders)
750
    {
751
        $apiLogs = $this->queryContainer->createApiLogsByOrderIds($orders)->find()->getData();
0 ignored issues
show
Bug introduced by
It seems like $orders defined by parameter $orders on line 749 can also be of type object<ArrayObject>; however, SprykerEco\Zed\Payone\Pe...eateApiLogsByOrderIds() does only seem to accept object<Propel\Runtime\Co...ction\ObjectCollection>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
752
753
        $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds($orders)->find()->getData();
0 ignored issues
show
Bug introduced by
It seems like $orders defined by parameter $orders on line 749 can also be of type object<ArrayObject>; however, SprykerEco\Zed\Payone\Pe...nStatusLogsByOrderIds() does only seem to accept object<Propel\Runtime\Co...ction\ObjectCollection>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
754
755
        $logs = [];
756
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLog */
757 View Code Duplication
        foreach ($apiLogs as $apiLog) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
758
            $key = $apiLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 'a' . $apiLog->getIdPaymentPayoneApiLog();
759
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
760
            $payonePaymentLogTransfer->fromArray($apiLog->toArray(), true);
761
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_API_LOG);
762
            $logs[$key] = $payonePaymentLogTransfer;
763
        }
764
        /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $transactionStatusLog */
765 View Code Duplication
        foreach ($transactionStatusLogs as $transactionStatusLog) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
766
            $key = $transactionStatusLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 't' . $transactionStatusLog->getIdPaymentPayoneTransactionStatusLog();
767
            $payonePaymentLogTransfer = new PayonePaymentLogTransfer();
768
            $payonePaymentLogTransfer->fromArray($transactionStatusLog->toArray(), true);
769
            $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_TRANSACTION_STATUS_LOG);
770
            $logs[$key] = $payonePaymentLogTransfer;
771
        }
772
773
        ksort($logs);
774
775
        $payonePaymentLogCollectionTransfer = new PayonePaymentLogCollectionTransfer();
776
777
        foreach ($logs as $log) {
778
            $payonePaymentLogCollectionTransfer->addPaymentLogs($log);
779
        }
780
781
        return $payonePaymentLogCollectionTransfer;
782
    }
783
784
    /**
785
     * @param \Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer
786
     *
787
     * @return array
788
     */
789
    public function getCreditCardCheckRequestData(PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer)
790
    {
791
        $this->standardParameter->fromArray($creditCardCheckRequestDataTransfer->toArray(), true);
792
793
        $creditCardCheck = new CreditCardCheck($this->standardParameter, $this->hashGenerator, $this->modeDetector);
0 ignored issues
show
Documentation introduced by
$this->hashGenerator is of type object<SprykerEco\Zed\Pa...HmacGeneratorInterface>, but the function expects a object<SprykerEco\Zed\Pa...HashGeneratorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
794
795
        $data = $creditCardCheck->mapCreditCardCheckData();
796
797
        return $data->toArray();
798
    }
799
800
    /**
801
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
802
     *
803
     * @return bool
804
     */
805
    public function isRefundPossible(OrderTransfer $orderTransfer)
806
    {
807
        $paymentTransfer = $this->getPayment($orderTransfer);
808
809
        if (!$this->isPaymentDataRequired($orderTransfer)) {
810
            return true;
811
        }
812
813
        $paymentDetailTransfer = $paymentTransfer->getPaymentDetail();
814
815
        return $paymentDetailTransfer->getBic() && $paymentDetailTransfer->getIban();
816
    }
817
818
    /**
819
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
820
     *
821
     * @return bool
822
     */
823
    public function isPaymentDataRequired(OrderTransfer $orderTransfer)
824
    {
825
        $paymentTransfer = $this->getPayment($orderTransfer);
826
827
        // Return early if we don't need the iban or bic data
828
        $paymentMethod = $paymentTransfer->getPaymentMethod();
829
        $whiteList = [
830
            PayoneApiConstants::PAYMENT_METHOD_E_WALLET,
831
            PayoneApiConstants::PAYMENT_METHOD_CREDITCARD_PSEUDO,
832
            PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER,
833
        ];
834
835
        if (in_array($paymentMethod, $whiteList)) {
836
            return false;
837
        }
838
839
        return true;
840
    }
841
842
    /**
843
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
844
     * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse
845
     *
846
     * @return \Generated\Shared\Transfer\CheckoutResponseTransfer
847
     */
848
    public function postSaveHook(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)
849
    {
850
        $apiLogsQuery = $this->queryContainer->createLastApiLogsByOrderId($quoteTransfer->getPayment()->getPayone()->getFkSalesOrder());
851
        $apiLog = $apiLogsQuery->findOne();
852
853
        if ($apiLog) {
854
            $redirectUrl = $apiLog->getRedirectUrl();
855
856
            if ($redirectUrl !== null) {
857
                $checkoutResponse->setIsExternalRedirect(true);
858
                $checkoutResponse->setRedirectUrl($redirectUrl);
859
            }
860
861
            $errorCode = $apiLog->getErrorCode();
862
863
            if ($errorCode) {
864
                $error = new CheckoutErrorTransfer();
865
                $error->setMessage($apiLog->getErrorMessageUser());
866
                $error->setErrorCode($errorCode);
867
                $checkoutResponse->addError($error);
868
                $checkoutResponse->setIsSuccess(false);
869
            }
870
        }
871
872
        return $checkoutResponse;
873
    }
874
875
    /**
876
     * @param \Generated\Shared\Transfer\PaymentDetailTransfer $paymentDataTransfer
877
     * @param int $idOrder
878
     *
879
     * @return void
880
     */
881 View Code Duplication
    public function updatePaymentDetail(PaymentDetailTransfer $paymentDataTransfer, $idOrder)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
882
    {
883
        $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();
884
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
885
886
        $paymentDetailEntity->fromArray($paymentDataTransfer->toArray());
887
888
        $paymentDetailEntity->save();
889
    }
890
891
    /**
892
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
893
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
894
     *
895
     * @return void
896
     */
897
    protected function updatePaymentDetailAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
898
    {
899
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
900
901
        $paymentDetailEntity->setClearingBankAccountHolder($responseContainer->getClearingBankaccountholder());
902
        $paymentDetailEntity->setClearingBankCountry($responseContainer->getClearingBankcountry());
903
        $paymentDetailEntity->setClearingBankAccount($responseContainer->getClearingBankaccount());
904
        $paymentDetailEntity->setClearingBankCode($responseContainer->getClearingBankcode());
905
        $paymentDetailEntity->setClearingBankIban($responseContainer->getClearingBankiban());
906
        $paymentDetailEntity->setClearingBankBic($responseContainer->getClearingBankbic());
907
        $paymentDetailEntity->setClearingBankCity($responseContainer->getClearingBankcity());
908
        $paymentDetailEntity->setClearingBankName($responseContainer->getClearingBankname());
909
910
        if ($responseContainer->getMandateIdentification()) {
911
            $paymentDetailEntity->setMandateIdentification($responseContainer->getMandateIdentification());
912
        }
913
914
        if ($paymentEntity->getPaymentMethod() == PayoneApiConstants::PAYMENT_METHOD_INVOICE) {
915
            $paymentDetailEntity->setInvoiceTitle($this->getInvoiceTitle($paymentEntity->getTransactionId()));
916
        }
917
918
        $paymentDetailEntity->save();
919
    }
920
921
    /**
922
     * @param \Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer
923
     *
924
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
925
     */
926 View Code Duplication
    public function initPaypalExpressCheckout(PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
927
    {
928
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
929
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
930
        );
931
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
932
        $baseGenericPaymentContainer->getPaydata()->setAction(PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_SET_ACTION);
933
        $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(
934
            $baseGenericPaymentContainer,
935
            $requestTransfer
936
        );
937
        $responseTransfer = $this->performGenericRequest($requestContainer);
938
939
        return $responseTransfer;
940
    }
941
942
    /**
943
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
944
     *
945
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
946
     */
947 View Code Duplication
    public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
948
    {
949
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
950
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
951
        );
952
953
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
954
        $baseGenericPaymentContainer->getPaydata()->setAction(
955
            PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION
956
        );
957
        $requestContainer = $paymentMethodMapper->mapQuoteTransferToGenericPayment(
958
            $baseGenericPaymentContainer,
959
            $quoteTransfer
960
        );
961
        $responseTransfer = $this->performGenericRequest($requestContainer);
962
963
        return $responseTransfer;
964
    }
965
966
    /**
967
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $requestContainer
968
     *
969
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
970
     */
971
    protected function performGenericRequest(GenericPaymentContainer $requestContainer)
972
    {
973
        $this->setStandardParameter($requestContainer);
974
975
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
976
        $responseContainer = new GenericPaymentResponseContainer($rawResponse);
977
        $responseTransfer = new PayonePaypalExpressCheckoutGenericPaymentResponseTransfer();
978
        $responseTransfer->setRedirectUrl($responseContainer->getRedirectUrl());
979
        $responseTransfer->setWorkOrderId($responseContainer->getWorkOrderId());
980
        $responseTransfer->setRawResponse(json_encode($rawResponse));
981
        $responseTransfer->setStatus($responseContainer->getStatus());
982
        $responseTransfer->setCustomerMessage($responseContainer->getCustomermessage());
983
        $responseTransfer->setErrorMessage($responseContainer->getErrormessage());
984
        $responseTransfer->setErrorCode($responseContainer->getErrorcode());
985
        $responseTransfer->setEmail($responseContainer->getEmail());
986
        $responseTransfer->setShippingFirstName($responseContainer->getShippingFirstname());
987
        $responseTransfer->setShippingLastName($responseContainer->getShippingLastname());
988
        $responseTransfer->setShippingCompany($responseContainer->getShippingCompany());
989
        $responseTransfer->setShippingCountry($responseContainer->getShippingCountry());
990
        $responseTransfer->setShippingState($responseContainer->getShippingState());
991
        $responseTransfer->setShippingStreet($responseContainer->getShippingStreet());
992
        $responseTransfer->setShippingAddressAdition($responseContainer->getShippingAddressaddition());
993
        $responseTransfer->setShippingCity($responseContainer->getShippingCity());
994
        $responseTransfer->setShippingZip($responseContainer->getShippingZip());
995
996
        return $responseTransfer;
997
    }
998
}
999