Completed
Push — master ( 8f260e...cc8332 )
by Oleksandr
17s queued 14s
created

PaymentManager::getInvoice()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 25
rs 9.7
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
        $requestContainer = $this->prepareOrderHandling($captureTransfer->getOrder(), $requestContainer);
304
305
        if (!empty($captureTransfer->getSettleaccount())) {
306
            $businnessContainer = new BusinessContainer();
307
            $businnessContainer->setSettleAccount($captureTransfer->getSettleaccount());
308
            $requestContainer->setBusiness($businnessContainer);
309
        }
310
311
        $this->setStandardParameter($requestContainer);
312
313
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
314
315
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
316
        $responseContainer = new CaptureResponseContainer($rawResponse);
317
318
        $this->updateApiLogAfterCapture($apiLogEntity, $responseContainer);
319
320
        $responseMapper = new CaptureResponseMapper();
321
        $responseTransfer = $responseMapper->getCaptureResponseTransfer($responseContainer);
322
323
        return $responseTransfer;
324
    }
325
326
    /**
327
     * @param int $idPayment
328
     *
329
     * @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...
330
     */
331
    public function debitPayment($idPayment)
332
    {
333
        $paymentEntity = $this->getPaymentEntity($idPayment);
334
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
335
336
        $requestContainer = $paymentMethodMapper->mapPaymentToDebit($paymentEntity);
337
        $this->setStandardParameter($requestContainer);
338
339
        $paymentEntity = $this->findPaymentByTransactionId($paymentEntity->getTransactionId());
340
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
341
342
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
343
        $responseContainer = new DebitResponseContainer($rawResponse);
344
345
        $this->updateApiLogAfterDebit($apiLogEntity, $responseContainer);
346
347
        $responseMapper = new DebitResponseMapper();
348
        $responseTransfer = $responseMapper->getDebitResponseTransfer($responseContainer);
349
350
        return $responseTransfer;
351
    }
352
353
    /**
354
     * @param \Generated\Shared\Transfer\PayoneCreditCardTransfer $creditCardData
355
     *
356
     * @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...
357
     */
358
    public function creditCardCheck(PayoneCreditCardTransfer $creditCardData)
359
    {
360
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\CreditCardPseudo $paymentMethodMapper */
361
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper($creditCardData->getPayment()->getPaymentMethod());
362
        $requestContainer = $paymentMethodMapper->mapCreditCardCheck($creditCardData);
363
364
        $this->setStandardParameter($requestContainer);
365
366
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
367
        $responseContainer = new CreditCardCheckResponseContainer($rawResponse);
368
369
        $responseMapper = new CreditCardCheckResponseMapper();
370
        $responseTransfer = $responseMapper->getCreditCardCheckResponseTransfer($responseContainer);
371
372
        return $responseTransfer;
373
    }
374
375
    /**
376
     * @param \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer $bankAccountCheckTransfer
377
     *
378
     * @return \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer
379
     */
380
    public function bankAccountCheck(PayoneBankAccountCheckTransfer $bankAccountCheckTransfer)
381
    {
382
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
383
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER);
384
        $requestContainer = $paymentMethodMapper->mapBankAccountCheck($bankAccountCheckTransfer);
385
        $this->setStandardParameter($requestContainer);
386
387
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
388
        $responseContainer = new BankAccountCheckResponseContainer($rawResponse);
389
390
        $bankAccountCheckTransfer->setErrorCode($responseContainer->getErrorcode());
391
        $bankAccountCheckTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
392
        $bankAccountCheckTransfer->setStatus($responseContainer->getStatus());
393
        $bankAccountCheckTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
394
395
        return $bankAccountCheckTransfer;
396
    }
397
398
    /**
399
     * @param \Generated\Shared\Transfer\PayoneManageMandateTransfer $manageMandateTransfer
400
     *
401
     * @return \Generated\Shared\Transfer\PayoneManageMandateTransfer
402
     */
403
    public function manageMandate(PayoneManageMandateTransfer $manageMandateTransfer)
404
    {
405
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
406
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
407
        $requestContainer = $paymentMethodMapper->mapManageMandate($manageMandateTransfer);
408
        $this->setStandardParameter($requestContainer);
409
410
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
411
        $responseContainer = new ManageMandateResponseContainer($rawResponse);
412
413
        $manageMandateTransfer->setErrorCode($responseContainer->getErrorcode());
414
        $manageMandateTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
415
        $manageMandateTransfer->setStatus($responseContainer->getStatus());
416
        $manageMandateTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
417
        $manageMandateTransfer->setMandateIdentification($responseContainer->getMandateIdentification());
418
        $manageMandateTransfer->setMandateText($responseContainer->getMandateText());
419
        $manageMandateTransfer->setIban($responseContainer->getIban());
420
        $manageMandateTransfer->setBic($responseContainer->getBic());
421
422
        return $manageMandateTransfer;
423
    }
424
425
    /**
426
     * @param \Generated\Shared\Transfer\PayoneGetFileTransfer $getFileTransfer
427
     *
428
     * @return \Generated\Shared\Transfer\PayoneGetFileTransfer
429
     */
430
    public function getFile(PayoneGetFileTransfer $getFileTransfer)
431
    {
432
        $responseContainer = new GetFileResponseContainer();
433
        $paymentEntity = $this->findPaymentByFileReferenceAndCustomerId(
434
            $getFileTransfer->getReference(),
435
            $getFileTransfer->getCustomerId()
436
        );
437
438
        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...
439
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */
440
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT);
441
            $requestContainer = $paymentMethodMapper->mapGetFile($getFileTransfer);
442
            $this->setStandardParameter($requestContainer);
443
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
444
            $responseContainer->init($rawResponse);
445
        } else {
446
            $this->setAccessDeniedError($responseContainer);
447
        }
448
449
        $getFileTransfer->setRawResponse($responseContainer->getRawResponse());
450
        $getFileTransfer->setStatus($responseContainer->getStatus());
451
        $getFileTransfer->setErrorCode($responseContainer->getErrorcode());
452
        $getFileTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage());
453
        $getFileTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
454
455
        return $getFileTransfer;
456
    }
457
458
    /**
459
     * @param \Generated\Shared\Transfer\PayoneGetInvoiceTransfer $getInvoiceTransfer
460
     *
461
     * @return \Generated\Shared\Transfer\PayoneGetInvoiceTransfer
462
     */
463
    public function getInvoice(PayoneGetInvoiceTransfer $getInvoiceTransfer)
464
    {
465
        $responseContainer = new GetInvoiceResponseContainer();
466
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
467
            $getInvoiceTransfer->getReference(),
468
            $getInvoiceTransfer->getCustomerId()
469
        );
470
471
        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...
472
            /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice $paymentMethodMapper */
473
            $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_INVOICE);
474
            $requestContainer = $paymentMethodMapper->mapGetInvoice($getInvoiceTransfer);
475
            $this->setStandardParameter($requestContainer);
476
            $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
477
            $responseContainer->init($rawResponse);
478
        } else {
479
            $this->setAccessDeniedError($responseContainer);
480
        }
481
482
        $getInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
483
        $getInvoiceTransfer->setStatus($responseContainer->getStatus());
484
        $getInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
485
        $getInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
486
487
        return $getInvoiceTransfer;
488
    }
489
490
    /**
491
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
492
     *
493
     * @return \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer
494
     */
495
    public function getSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer): PayoneGetSecurityInvoiceTransfer
496
    {
497
        $responseContainer = new GetSecurityInvoiceResponseContainer();
498
        $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId(
499
            $getSecurityInvoiceTransfer->getReference(),
500
            $getSecurityInvoiceTransfer->getCustomerId()
501
        );
502
503
        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...
504
            $this->setAccessDeniedError($responseContainer);
505
506
            return $getSecurityInvoiceTransfer;
507
        }
508
509
        /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\SecurityInvoice $paymentMethodMapper */
510
        $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE);
511
        $requestContainer = $paymentMethodMapper->mapGetSecurityInvoice($getSecurityInvoiceTransfer);
512
        $this->setStandardParameter($requestContainer);
513
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
514
        $responseContainer->init($rawResponse);
515
516
        $getSecurityInvoiceTransfer->setRawResponse($responseContainer->getRawResponse());
517
        $getSecurityInvoiceTransfer->setStatus($responseContainer->getStatus());
518
        $getSecurityInvoiceTransfer->setErrorCode($responseContainer->getErrorcode());
519
        $getSecurityInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage());
520
521
        return $getSecurityInvoiceTransfer;
522
    }
523
524
    /**
525
     * @param int $transactionId
526
     *
527
     * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer
528
     */
529
    public function getInvoiceTitle($transactionId)
530
    {
531
        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...
532
            PayoneApiConstants::INVOICE_TITLE_PREFIX_INVOICE,
533
            $transactionId,
534
            0,
535
        ]);
536
    }
537
538
    /**
539
     * @param \Generated\Shared\Transfer\PayoneRefundTransfer $refundTransfer
540
     *
541
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
542
     */
543
    public function refundPayment(PayoneRefundTransfer $refundTransfer)
544
    {
545
        $payonePaymentTransfer = $refundTransfer->getPayment();
546
547
        $paymentEntity = $this->getPaymentEntity($payonePaymentTransfer->getFkSalesOrder());
548
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
549
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
550
        $requestContainer->setAmount(0 - $paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
551
        $requestContainer = $this->prepareOrderItems($refundTransfer->getOrder(), $requestContainer);
552
        $requestContainer = $this->prepareOrderShipment($refundTransfer->getOrder(), $requestContainer);
553
        $requestContainer = $this->prepareOrderDiscount($refundTransfer->getOrder(), $requestContainer);
554
555
        $this->setStandardParameter($requestContainer);
556
557
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
558
559
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
560
        $responseContainer = new RefundResponseContainer($rawResponse);
561
562
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
563
564
        $responseMapper = new RefundResponseMapper();
565
        $responseTransfer = $responseMapper->getRefundResponseTransfer($responseContainer);
566
567
        return $responseTransfer;
568
    }
569
570
    /**
571
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
572
     *
573
     * @return \Generated\Shared\Transfer\RefundResponseTransfer
574
     */
575
    public function executePartialRefund(PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer): RefundResponseTransfer
576
    {
577
        $paymentEntity = $this->getPaymentEntity($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder());
578
        $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);
579
        $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);
580
581
        $requestContainer->setAmount($payonePartialOperationRequestTransfer->getRefund()->getAmount() * -1);
582
        $requestContainer = $this->preparePartialRefundOrderItems($payonePartialOperationRequestTransfer, $requestContainer);
583
        $this->setStandardParameter($requestContainer);
584
        $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);
585
586
        $rawResponse = $this->executionAdapter->sendRequest($requestContainer);
587
        $responseContainer = new RefundResponseContainer($rawResponse);
588
589
        $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);
590
        $this->updatePaymentPayoneOrderItemsWithStatus(
591
            $payonePartialOperationRequestTransfer,
592
            $this->getPartialRefundStatus($responseContainer)
593
        );
594
595
        $responseMapper = new RefundResponseMapper();
596
597
        return $responseMapper->getRefundResponseTransfer($responseContainer);
598
    }
599
600
    /**
601
     * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer
602
     * @param string $refundStatus
603
     *
604
     * @return void
605
     */
606
    protected function updatePaymentPayoneOrderItemsWithStatus(
607
        PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,
608
        string $refundStatus
609
    ): void {
610
        $payoneOrderItemFilterTransfer = (new PayoneOrderItemFilterTransfer())
611
            ->setIdSalesOrder($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder())
612
            ->setSalesOrderItemIds($payonePartialOperationRequestTransfer->getSalesOrderItemIds());
613
614
        $payoneOrderItemTransfers = $this->payoneRepository->findPaymentPayoneOrderItemByFilter($payoneOrderItemFilterTransfer);
615
616
        foreach ($payoneOrderItemTransfers as $payoneOrderItemTransfer) {
617
            $payoneOrderItemTransfer->setStatus($refundStatus);
618
            $this->payoneEntityManager->updatePaymentPayoneOrderItem($payoneOrderItemTransfer);
619
        }
620
    }
621
622
    /**
623
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer
624
     *
625
     * @return string
626
     */
627
    protected function getPartialRefundStatus(RefundResponseContainer $responseContainer): string
628
    {
629
        if ($responseContainer->getStatus() === PayoneApiConstants::RESPONSE_TYPE_APPROVED) {
630
            return PayoneTransactionStatusConstants::STATUS_REFUND_APPROVED;
631
        }
632
633
        return PayoneTransactionStatusConstants::STATUS_REFUND_FAILED;
634
    }
635
636
    /**
637
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
638
     *
639
     * @return \Generated\Shared\Transfer\PayonePaymentTransfer
640
     */
641
    protected function getPayment(OrderTransfer $orderTransfer)
642
    {
643
        $payment = $this->queryContainer->createPaymentByOrderId($orderTransfer->getIdSalesOrder())->findOne();
644
        $paymentDetail = $payment->getSpyPaymentPayoneDetail();
645
646
        $paymentDetailTransfer = new PaymentDetailTransfer();
647
        $paymentDetailTransfer->fromArray($paymentDetail->toArray(), true);
648
649
        $paymentTransfer = new PayonePaymentTransfer();
650
        $paymentTransfer->fromArray($payment->toArray(), true);
651
        $paymentTransfer->setPaymentDetail($paymentDetailTransfer);
652
653
        return $paymentTransfer;
654
    }
655
656
    /**
657
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
658
     * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer
659
     *
660
     * @return void
661
     */
662
    protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)
663
    {
664
        $paymentEntity->setTransactionId($responseContainer->getTxid());
665
        $paymentEntity->save();
666
    }
667
668
    /**
669
     * @param string $transactionId
670
     *
671
     * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone
672
     */
673
    protected function findPaymentByTransactionId($transactionId)
674
    {
675
        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

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

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

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

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

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

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

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

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