Passed
Pull Request — master (#45)
by Aleksey
08:22
created

PaymentManager   F

Complexity

Total Complexity 75

Size/Duplication

Total Lines 1163
Duplicated Lines 0 %

Importance

Changes 9
Bugs 0 Features 1
Metric Value
eloc 491
dl 0
loc 1163
rs 2.4
c 9
b 0
f 1
wmc 75

48 Methods

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

How to fix   Complexity   

Complex Class

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

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

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

1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Business\Payment;
9
10
use ArrayObject;
11
use Generated\Shared\Transfer\CaptureResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CaptureResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\Transfer\CheckoutErrorTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutErrorTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Generated\Shared\Transfer\CheckoutResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CheckoutResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Generated\Shared\Transfer\PaymentDetailTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentDetailTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Generated\Shared\Transfer\PayoneBankAccountCheckTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ankAccountCheckTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Generated\Shared\Transfer\PayoneCaptureTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneCaptureTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...heckRequestDataTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Generated\Shared\Transfer\PayoneCreditCardTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneCreditCardTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Generated\Shared\Transfer\PayoneGetFileTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneGetFileTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Generated\Shared\Transfer\PayoneGetInvoiceTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneGetInvoiceTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...SecurityInvoiceTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...CheckoutRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Generated\Shared\Transfer\PayoneManageMandateTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...neManageMandateTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Generated\Shared\Transfer\PayoneOrderItemFilterTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...OrderItemFilterTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Generated\Shared\Transfer\PayonePartialOperationRequestTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...perationRequestTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ntLogCollectionTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use Generated\Shared\Transfer\PayonePaymentLogTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentLogTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Generated\Shared\Transfer\PayonePaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayonePaymentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...PaymentResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Generated\Shared\Transfer\PayoneRefundTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneRefundTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Generated\Shared\Transfer\PayoneStandardParameterTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...andardParameterTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use Generated\Shared\Transfer\RefundResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RefundResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayone was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
use Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use Spryker\Shared\Shipment\ShipmentConstants;
38
use SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface;
39
use SprykerEco\Shared\Payone\PayoneApiConstants;
40
use SprykerEco\Shared\Payone\PayoneTransactionStatusConstants;
41
use SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface;
42
use SprykerEco\Zed\Payone\Business\Api\Call\CreditCardCheck;
43
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
44
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface;
45
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Capture\BusinessContainer;
46
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
47
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
48
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer;
49
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
50
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer;
51
use SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer;
52
use SprykerEco\Zed\Payone\Business\Api\Response\Container\BankAccountCheckResponseContainer;
53
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer;
54
use SprykerEco\Zed\Payone\Business\Api\Response\Container\CreditCardCheckResponseContainer;
55
use SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer;
56
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GenericPaymentResponseContainer;
57
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetFileResponseContainer;
58
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer;
59
use SprykerEco\Zed\Payone\Business\Api\Response\Container\GetSecurityInvoiceResponseContainer;
60
use SprykerEco\Zed\Payone\Business\Api\Response\Container\ManageMandateResponseContainer;
61
use SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer;
62
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\AuthorizationResponseMapper;
63
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CaptureResponseMapper;
64
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\CreditCardCheckResponseMapper;
65
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\DebitResponseMapper;
66
use SprykerEco\Zed\Payone\Business\Api\Response\Mapper\RefundResponseMapper;
67
use SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException;
68
use SprykerEco\Zed\Payone\Business\Key\HashGenerator;
69
use SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface;
70
use SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface;
71
use SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface;
72
use SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface;
73
use SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface;
74
75
class PaymentManager implements PaymentManagerInterface
76
{
77
    public const LOG_TYPE_API_LOG = 'SpyPaymentPayoneApiLog';
78
    public const LOG_TYPE_TRANSACTION_STATUS_LOG = 'SpyPaymentPayoneTransactionStatusLog';
79
    public const ERROR_ACCESS_DENIED_MESSAGE = 'Access denied';
80
81
    /**
82
     * @var \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface
83
     */
84
    protected $executionAdapter;
85
86
    /**
87
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface
88
     */
89
    protected $queryContainer;
90
91
    /**
92
     * @var \Generated\Shared\Transfer\PayoneStandardParameterTransfer
93
     */
94
    protected $standardParameter;
95
96
    /**
97
     * @var \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface
98
     */
99
    protected $sequenceNumberProvider;
100
101
    /**
102
     * @var \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface
103
     */
104
    protected $modeDetector;
105
106
    /**
107
     * @var \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface
108
     */
109
    protected $hashGenerator;
110
111
    /**
112
     * @var \SprykerEco\Zed\Payone\Business\Key\UrlHmacGenerator
113
     */
114
    protected $urlHmacGenerator;
115
116
    /**
117
     * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface[]
118
     */
119
    protected $registeredMethodMappers;
120
121
    /**
122
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface
123
     */
124
    protected $payoneRepository;
125
126
    /**
127
     * @var \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface
128
     */
129
    protected $payoneEntityManager;
130
131
    /**
132
     * @param \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface $executionAdapter
133
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer
134
     * @param \Generated\Shared\Transfer\PayoneStandardParameterTransfer $standardParameter
135
     * @param \SprykerEco\Zed\Payone\Business\Key\HashGenerator $hashGenerator
136
     * @param \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface $sequenceNumberProvider
137
     * @param \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface $modeDetector
138
     * @param \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface $urlHmacGenerator
139
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneRepositoryInterface $payoneRepository
140
     * @param \SprykerEco\Zed\Payone\Persistence\PayoneEntityManagerInterface $payoneEntityManager
141
     */
142
    public function __construct(
143
        AdapterInterface $executionAdapter,
144
        PayoneQueryContainerInterface $queryContainer,
145
        PayoneStandardParameterTransfer $standardParameter,
146
        HashGenerator $hashGenerator,
147
        SequenceNumberProviderInterface $sequenceNumberProvider,
148
        ModeDetectorInterface $modeDetector,
149
        HmacGeneratorInterface $urlHmacGenerator,
150
        PayoneRepositoryInterface $payoneRepository,
151
        PayoneEntityManagerInterface $payoneEntityManager
152
    ) {
153
        $this->executionAdapter = $executionAdapter;
154
        $this->queryContainer = $queryContainer;
155
        $this->standardParameter = $standardParameter;
156
        $this->hashGenerator = $hashGenerator;
0 ignored issues
show
Documentation Bug introduced by
It seems like $hashGenerator of type SprykerEco\Zed\Payone\Business\Key\HashGenerator is incompatible with the declared type SprykerEco\Zed\Payone\Bu...\HmacGeneratorInterface of property $hashGenerator.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

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

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

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

class Alien {}

class Dalek extends Alien {}

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

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
160
        $this->payoneRepository = $payoneRepository;
161
        $this->payoneEntityManager = $payoneEntityManager;
162
    }
163
164
    /**
165
     * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface $paymentMethodMapper
166
     *
167
     * @return void
168
     */
169
    public function registerPaymentMethodMapper(PaymentMethodMapperInterface $paymentMethodMapper)
170
    {
171
        $paymentMethodMapper->setStandardParameter($this->standardParameter);
172
        $paymentMethodMapper->setSequenceNumberProvider($this->sequenceNumberProvider);
173
        $paymentMethodMapper->setUrlHmacGenerator($this->urlHmacGenerator);
174
        $this->registeredMethodMappers[$paymentMethodMapper->getName()] = $paymentMethodMapper;
175
    }
176
177
    /**
178
     * @param string $name
179
     *
180
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface|null
181
     */
182
    protected function findPaymentMethodMapperByName($name)
183
    {
184
        if (array_key_exists($name, $this->registeredMethodMappers)) {
185
            return $this->registeredMethodMappers[$name];
186
        }
187
188
        return null;
189
    }
190
191
    /**
192
     * @param string $paymentMethodName
193
     *
194
     * @throws \SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException
195
     *
196
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
197
     */
198
    protected function getRegisteredPaymentMethodMapper($paymentMethodName)
199
    {
200
        $paymentMethodMapper = $this->findPaymentMethodMapperByName($paymentMethodName);
201
        if ($paymentMethodMapper === null) {
202
            throw new InvalidPaymentMethodException(
203
                sprintf('No registered payment method mapper found for given method name %s', $paymentMethodName)
204
            );
205
        }
206
207
        return $paymentMethodMapper;
208
    }
209
210
    /**
211
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
212
     *
213
     * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...izationResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
214
     */
215
    public function authorizePayment(OrderTransfer $orderTransfer)
216
    {
217
        $paymentEntity = $this->getPaymentEntity($orderTransfer->getIdSalesOrder());
218
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
219
        $requestContainer = $paymentMethodMapper->mapPaymentToAuthorization($paymentEntity, $orderTransfer);
220
        $requestContainer = $this->prepareOrderItems($orderTransfer, $requestContainer);
221
        $requestContainer = $this->prepareOrderShipment($orderTransfer, $requestContainer);
222
        $requestContainer = $this->prepareOrderDiscount($orderTransfer, $requestContainer);
223
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
224
225
        $responseMapper = new AuthorizationResponseMapper();
226
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
227
228
        return $responseTransfer;
229
    }
230
231
    /**
232
     * @param int $idSalesOrder
233
     *
234
     * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer
235
     */
236
    public function preAuthorizePayment($idSalesOrder)
237
    {
238
        $paymentEntity = $this->getPaymentEntity($idSalesOrder);
239
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
240
        $requestContainer = $paymentMethodMapper->mapPaymentToPreAuthorization($paymentEntity);
241
        $responseContainer = $this->performAuthorizationRequest($paymentEntity, $requestContainer);
242
243
        $responseMapper = new AuthorizationResponseMapper();
244
        $responseTransfer = $responseMapper->getAuthorizationResponseTransfer($responseContainer);
245
246
        return $responseTransfer;
247
    }
248
249
    /**
250
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
251
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface $requestContainer
252
     *
253
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer
254
     */
255
    protected function performAuthorizationRequest(SpyPaymentPayone $paymentEntity, AuthorizationContainerInterface $requestContainer)
256
    {
257
        $this->setStandardParameter($requestContainer);
258
259
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
260
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
261
        $responseContainer = new AuthorizationResponseContainer($rawResponse);
262
        $this->updatePaymentAfterAuthorization($paymentEntity, $responseContainer);
263
        $this->updateApiLogAfterAuthorization($apiLogEntity, $responseContainer);
264
        $this->updatePaymentDetailAfterAuthorization($paymentEntity, $responseContainer);
265
266
        return $responseContainer;
267
    }
268
269
    /**
270
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
271
     *
272
     * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface
273
     */
274
    protected function getPaymentMethodMapper(SpyPaymentPayone $paymentEntity)
275
    {
276
        return $this->getRegisteredPaymentMethodMapper($paymentEntity->getPaymentMethod());
277
    }
278
279
    /**
280
     * @param int $orderId
281
     *
282
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
283
     */
284
    protected function getPaymentEntity($orderId)
285
    {
286
        return $this->queryContainer->createPaymentById($orderId)->findOne();
287
    }
288
289
    /**
290
     * @param \Generated\Shared\Transfer\PayoneCaptureTransfer $captureTransfer
291
     *
292
     * @return \Generated\Shared\Transfer\CaptureResponseTransfer
293
     */
294
    public function capturePayment(PayoneCaptureTransfer $captureTransfer): CaptureResponseTransfer
295
    {
296
        $paymentEntity = $this->getPaymentEntity($captureTransfer->getPayment()->getFkSalesOrder());
297
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
298
299
        $requestContainer = $paymentMethodMapper->mapPaymentToCapture($paymentEntity);
300
        $requestContainer = $this->prepareOrderItems($captureTransfer->getOrder(), $requestContainer);
301
        $requestContainer = $this->prepareOrderShipment($captureTransfer->getOrder(), $requestContainer);
302
        $requestContainer = $this->prepareOrderDiscount($captureTransfer->getOrder(), $requestContainer);
303
304
        if (!empty($captureTransfer->getSettleaccount())) {
305
            $businnessContainer = new BusinessContainer();
306
            $businnessContainer->setSettleAccount($captureTransfer->getSettleaccount());
307
            $requestContainer->setBusiness($businnessContainer);
308
        }
309
310
        $this->setStandardParameter($requestContainer);
311
312
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
313
314
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
315
        $responseContainer = new CaptureResponseContainer($rawResponse);
316
317
        $this->updateApiLogAfterCapture($apiLogEntity, $responseContainer);
318
319
        $responseMapper = new CaptureResponseMapper();
320
        $responseTransfer = $responseMapper->getCaptureResponseTransfer($responseContainer);
321
322
        return $responseTransfer;
323
    }
324
325
    /**
326
     * @param int $idPayment
327
     *
328
     * @return \Generated\Shared\Transfer\DebitResponseTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\DebitResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
329
     */
330
    public function debitPayment($idPayment)
331
    {
332
        $paymentEntity = $this->getPaymentEntity($idPayment);
333
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
334
335
        $requestContainer = $paymentMethodMapper->mapPaymentToDebit($paymentEntity);
336
        $this->setStandardParameter($requestContainer);
337
338
        $paymentEntity = $this->findPaymentByTransactionId($paymentEntity->getTransactionId());
339
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
340
341
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
342
        $responseContainer = new DebitResponseContainer($rawResponse);
343
344
        $this->updateApiLogAfterDebit($apiLogEntity, $responseContainer);
345
346
        $responseMapper = new DebitResponseMapper();
347
        $responseTransfer = $responseMapper->getDebitResponseTransfer($responseContainer);
348
349
        return $responseTransfer;
350
    }
351
352
    /**
353
     * @param \Generated\Shared\Transfer\PayoneCreditCardTransfer $creditCardData
354
     *
355
     * @return \Generated\Shared\Transfer\CreditCardCheckResponseTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rdCheckResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
356
     */
357
    public function creditCardCheck(PayoneCreditCardTransfer $creditCardData)
358
    {
359
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo $paymentMethodMapper */
360
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper($creditCardData->getPayment()->getPaymentMethod());
361
        $requestContainer = $paymentMethodMapper->mapCreditCardCheck($creditCardData);
362
363
        $this->setStandardParameter($requestContainer);
364
365
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
366
        $responseContainer = new CreditCardCheckResponseContainer($rawResponse);
367
368
        $responseMapper = new CreditCardCheckResponseMapper();
369
        $responseTransfer = $responseMapper->getCreditCardCheckResponseTransfer($responseContainer);
370
371
        return $responseTransfer;
372
    }
373
374
    /**
375
     * @param \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer $bankAccountCheckTransfer
376
     *
377
     * @return \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer
378
     */
379
    public function bankAccountCheck(PayoneBankAccountCheckTransfer $bankAccountCheckTransfer)
380
    {
381
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
382
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER);
383
        $requestContainer = $paymentMethodMapper->mapBankAccountCheck($bankAccountCheckTransfer);
384
        $this->setStandardParameter($requestContainer);
385
386
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
387
        $responseContainer = new BankAccountCheckResponseContainer($rawResponse);
388
389
        $bankAccountCheckTransfer->setErrorCode($responseContainer->getErrorcode());
390
        $bankAccountCheckTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
391
        $bankAccountCheckTransfer->setStatus($responseContainer->getStatus());
392
        $bankAccountCheckTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
393
394
        return $bankAccountCheckTransfer;
395
    }
396
397
    /**
398
     * @param \Generated\Shared\Transfer\PayoneManageMandateTransfer $manageMandateTransfer
399
     *
400
     * @return \Generated\Shared\Transfer\PayoneManageMandateTransfer
401
     */
402
    public function manageMandate(PayoneManageMandateTransfer $manageMandateTransfer)
403
    {
404
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
405
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
406
        $requestContainer = $paymentMethodMapper->mapManageMandate($manageMandateTransfer);
407
        $this->setStandardParameter($requestContainer);
408
409
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
410
        $responseContainer = new ManageMandateResponseContainer($rawResponse);
411
412
        $manageMandateTransfer->setErrorCode($responseContainer->getErrorcode());
413
        $manageMandateTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
414
        $manageMandateTransfer->setStatus($responseContainer->getStatus());
415
        $manageMandateTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
416
        $manageMandateTransfer->setMandateIdentification($responseContainer->getMandateIdentification());
417
        $manageMandateTransfer->setMandateText($responseContainer->getMandateText());
418
        $manageMandateTransfer->setIban($responseContainer->getIban());
419
        $manageMandateTransfer->setBic($responseContainer->getBic());
420
421
        return $manageMandateTransfer;
422
    }
423
424
    /**
425
     * @param \Generated\Shared\Transfer\PayoneGetFileTransfer $getFileTransfer
426
     *
427
     * @return \Generated\Shared\Transfer\PayoneGetFileTransfer
428
     */
429
    public function getFile(PayoneGetFileTransfer $getFileTransfer)
430
    {
431
        $responseContainer = new GetFileResponseContainer();
432
        $paymentEntity = $this->findPaymentByFileReferenceAndCustomerId(
433
            $getFileTransfer->getReference(),
434
            $getFileTransfer->getCustomerId()
435
        );
436
437
        if ($paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery, thus it always evaluated to true.
Loading history...
438
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
439
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
440
            $requestContainer = $paymentMethodMapper->mapGetFile($getFileTransfer);
441
            $this->setStandardParameter($requestContainer);
442
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
443
            $responseContainer->init($rawResponse);
444
        } else {
445
            $this->setAccessDeniedError($responseContainer);
446
        }
447
448
        $getFileTransfer->setRawResponse($responseContainer->getRawResponse());
449
        $getFileTransfer->setStatus($responseContainer->getStatus());
450
        $getFileTransfer->setErrorCode($responseContainer->getErrorcode());
451
        $getFileTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
452
        $getFileTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
453
454
        return $getFileTransfer;
455
    }
456
457
    /**
458
     * @param \Generated\Shared\Transfer\PayoneGetInvoiceTransfer $getInvoiceTransfer
459
     *
460
     * @return \Generated\Shared\Transfer\PayoneGetInvoiceTransfer
461
     */
462
    public function getInvoice(PayoneGetInvoiceTransfer $getInvoiceTransfer)
463
    {
464
        $responseContainer = new GetInvoiceResponseContainer();
465
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
466
            $getInvoiceTransfer->getReference(),
467
            $getInvoiceTransfer->getCustomerId()
468
        );
469
470
        if ($paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery, thus it always evaluated to true.
Loading history...
471
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice $paymentMethodMapper */
472
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_INVOICE);
473
            $requestContainer = $paymentMethodMapper->mapGetInvoice($getInvoiceTransfer);
474
            $this->setStandardParameter($requestContainer);
475
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
476
            $responseContainer->init($rawResponse);
477
        } else {
478
            $this->setAccessDeniedError($responseContainer);
479
        }
480
481
        $getInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
482
        $getInvoiceTransfer->setStatus($responseContainer->getStatus());
483
        $getInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
484
        $getInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
485
486
        return $getInvoiceTransfer;
487
    }
488
489
    /**
490
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
491
     *
492
     * @return \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer
493
     */
494
    public function getSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer): PayoneGetSecurityInvoiceTransfer
495
    {
496
        $responseContainer = new GetSecurityInvoiceResponseContainer();
497
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
498
            $getSecurityInvoiceTransfer->getReference(),
499
            $getSecurityInvoiceTransfer->getCustomerId()
500
        );
501
502
        if (!$paymentEntity) {
0 ignored issues
show
introduced by
$paymentEntity is of type Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery, thus it always evaluated to true.
Loading history...
503
            $this->setAccessDeniedError($responseContainer);
504
505
            return $getSecurityInvoiceTransfer;
506
        }
507
508
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\SecurityInvoice $paymentMethodMapper */
509
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE);
510
        $requestContainer = $paymentMethodMapper->mapGetSecurityInvoice($getSecurityInvoiceTransfer);
511
        $this->setStandardParameter($requestContainer);
512
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
513
        $responseContainer->init($rawResponse);
514
515
        $getSecurityInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
516
        $getSecurityInvoiceTransfer->setStatus($responseContainer->getStatus());
517
        $getSecurityInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
518
        $getSecurityInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
519
520
        return $getSecurityInvoiceTransfer;
521
    }
522
523
    /**
524
     * @param int $transactionId
525
     *
526
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer
527
     */
528
    public function getInvoiceTitle($transactionId)
529
    {
530
        return implode('-', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return implode('-', arra...CE, $transactionId, 0)) returns the type string which is incompatible with the documented return type SprykerEco\Zed\Payone\Bu...nvoiceResponseContainer.
Loading history...
531
            PayoneApiConstants::INVOICE_TITLE_PREFIX_INVOICE,
532
            $transactionId,
533
            0,
534
        ]);
535
    }
536
537
    /**
538
     * @param \Generated\Shared\Transfer\PayoneRefundTransfer $refundTransfer
539
     *
540
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
541
     */
542
    public function refundPayment(PayoneRefundTransfer $refundTransfer)
543
    {
544
        $payonePaymentTransfer = $refundTransfer->getPayment();
545
546
        $paymentEntity = $this->getPaymentEntity($payonePaymentTransfer->getFkSalesOrder());
547
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
548
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
549
        $requestContainer->setAmount(0 - $paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
550
        $requestContainer = $this->prepareOrderItems($refundTransfer->getOrder(), $requestContainer);
551
        $requestContainer = $this->prepareOrderShipment($refundTransfer->getOrder(), $requestContainer);
552
        $requestContainer = $this->prepareOrderDiscount($refundTransfer->getOrder(), $requestContainer);
553
554
        $this->setStandardParameter($requestContainer);
555
556
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
557
558
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
559
        $responseContainer = new RefundResponseContainer($rawResponse);
560
561
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
562
563
        $responseMapper = new RefundResponseMapper();
564
        $responseTransfer = $responseMapper->getRefundResponseTransfer($responseContainer);
565
566
        return $responseTransfer;
567
    }
568
569
    /**
570
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
571
     *
572
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
573
     */
574
    public function executePartialRefund(PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer): RefundResponseTransfer
575
    {
576
        $paymentEntity = $this->getPaymentEntity($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder());
577
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
578
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
579
580
        $requestContainer->setAmount($payonePartialOperationRequestTransfer->getRefund()->getAmount() * -1);
581
        $requestContainer = $this->preparePartialRefundOrderItems($payonePartialOperationRequestTransfer, $requestContainer);
582
        $this->setStandardParameter($requestContainer);
583
584
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
585
        $responseContainer = new RefundResponseContainer($rawResponse);
586
587
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
588
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
589
590
        $payoneOrderItemFilterTransfer = (new PayoneOrderItemFilterTransfer())
591
            ->setIdSalesOrder($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder())
592
            ->setSalesOrderItemIds($payonePartialOperationRequestTransfer->getSalesOrderItemIds());
593
594
        $refundStatus = PayoneTransactionStatusConstants::STATUS_REFUND_FAILED;
595
        if ($responseContainer->getStatus() === PayoneApiConstants::RESPONSE_TYPE_APPROVED) {
596
            $refundStatus = PayoneTransactionStatusConstants::STATUS_REFUND_APPROVED;
597
        }
598
599
        $payoneOrderItemTransfers = $this->payoneRepository->findPaymentPayoneOrderItemByFilter($payoneOrderItemFilterTransfer);
600
601
        foreach ($payoneOrderItemTransfers as $payoneOrderItemTransfer) {
602
            $payoneOrderItemTransfer->setStatus($refundStatus);
603
            $this->payoneEntityManager->updatePaymentPayoneOrderItem($payoneOrderItemTransfer);
604
        }
605
606
        $responseMapper = new RefundResponseMapper();
607
608
        return $responseMapper->getRefundResponseTransfer($responseContainer);
609
    }
610
611
    /**
612
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
613
     *
614
     * @return \Generated\Shared\Transfer\PayonePaymentTransfer
615
     */
616
    protected function getPayment(OrderTransfer $orderTransfer)
617
    {
618
        $payment = $this->queryContainer->createPaymentByOrderId($orderTransfer->getIdSalesOrder())->findOne();
619
        $paymentDetail = $payment->getSpyPaymentPayoneDetail();
620
621
        $paymentDetailTransfer = new PaymentDetailTransfer();
622
        $paymentDetailTransfer->fromArray($paymentDetail->toArray(), true);
623
624
        $paymentTransfer = new PayonePaymentTransfer();
625
        $paymentTransfer->fromArray($payment->toArray(), true);
626
        $paymentTransfer->setPaymentDetail($paymentDetailTransfer);
627
628
        return $paymentTransfer;
629
    }
630
631
    /**
632
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
633
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
634
     *
635
     * @return void
636
     */
637
    protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
638
    {
639
        $paymentEntity->setTransactionId($responseContainer->getTxid());
640
        $paymentEntity->save();
641
    }
642
643
    /**
644
     * @param string $transactionId
645
     *
646
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
647
     */
648
    protected function findPaymentByTransactionId($transactionId)
649
    {
650
        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

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

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

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

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

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

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

1011
        /** @scrutinizer ignore-call */ 
1012
        $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(
Loading history...
1012
            $baseGenericPaymentContainer,
1013
            $requestTransfer
1014
        );
1015
        $responseTransfer = $this->performGenericRequest($requestContainer);
1016
1017
        return $responseTransfer;
1018
    }
1019
1020
    /**
1021
     * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer
1022
     *
1023
     * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer
1024
     */
1025
    public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer)
1026
    {
1027
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(
1028
            PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT
1029
        );
1030
1031
        $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();
1032
        $baseGenericPaymentContainer->getPaydata()->setAction(
1033
            PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION
1034
        );
1035
        $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

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