| Total Complexity | 77 | 
| Total Lines | 1187 | 
| Duplicated Lines | 0 % | 
| Changes | 11 | ||
| Bugs | 0 | Features | 1 | 
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  | 
            ||
| 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;  | 
            ||
| 157 | $this->sequenceNumberProvider = $sequenceNumberProvider;  | 
            ||
| 158 | $this->modeDetector = $modeDetector;  | 
            ||
| 159 | $this->urlHmacGenerator = $urlHmacGenerator;  | 
            ||
| 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)  | 
            ||
| 208 | }  | 
            ||
| 209 | |||
| 210 | /**  | 
            ||
| 211 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer  | 
            ||
| 212 | *  | 
            ||
| 213 | * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer  | 
            ||
| 214 | */  | 
            ||
| 215 | public function authorizePayment(OrderTransfer $orderTransfer)  | 
            ||
| 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  | 
            ||
| 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  | 
            ||
| 356 | */  | 
            ||
| 357 | public function creditCardCheck(PayoneCreditCardTransfer $creditCardData)  | 
            ||
| 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)  | 
            ||
| 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) { | 
            ||
| 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  | 
            ||
| 521 | }  | 
            ||
| 522 | |||
| 523 | /**  | 
            ||
| 524 | * @param int $transactionId  | 
            ||
| 525 | *  | 
            ||
| 526 | * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer  | 
            ||
| 527 | */  | 
            ||
| 528 | public function getInvoiceTitle($transactionId)  | 
            ||
| 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)  | 
            ||
| 567 | }  | 
            ||
| 568 | |||
| 569 | /**  | 
            ||
| 570 | * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer  | 
            ||
| 571 | *  | 
            ||
| 572 | * @return \Generated\Shared\Transfer\RefundResponseTransfer  | 
            ||
| 573 | */  | 
            ||
| 574 | public function executePartialRefund(PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer): RefundResponseTransfer  | 
            ||
| 575 |     { | 
            ||
| 576 | $paymentEntity = $this->getPaymentEntity($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder());  | 
            ||
| 577 | $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity);  | 
            ||
| 578 | $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity);  | 
            ||
| 579 | |||
| 580 | $requestContainer->setAmount($payonePartialOperationRequestTransfer->getRefund()->getAmount() * -1);  | 
            ||
| 581 | $requestContainer = $this->preparePartialRefundOrderItems($payonePartialOperationRequestTransfer, $requestContainer);  | 
            ||
| 582 | $this->setStandardParameter($requestContainer);  | 
            ||
| 583 | $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer);  | 
            ||
| 584 | |||
| 585 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer);  | 
            ||
| 586 | $responseContainer = new RefundResponseContainer($rawResponse);  | 
            ||
| 587 | |||
| 588 | $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer);  | 
            ||
| 589 | $this->updatePaymentPayoneOrderItemsWithStatus(  | 
            ||
| 590 | $payonePartialOperationRequestTransfer,  | 
            ||
| 591 | $this->getPartialRefundStatus($responseContainer)  | 
            ||
| 592 | );  | 
            ||
| 593 | |||
| 594 | $responseMapper = new RefundResponseMapper();  | 
            ||
| 595 | |||
| 596 | return $responseMapper->getRefundResponseTransfer($responseContainer);  | 
            ||
| 597 | }  | 
            ||
| 598 | |||
| 599 | /**  | 
            ||
| 600 | * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer  | 
            ||
| 601 | * @param string $refundStatus  | 
            ||
| 602 | *  | 
            ||
| 603 | * @return void  | 
            ||
| 604 | */  | 
            ||
| 605 | protected function updatePaymentPayoneOrderItemsWithStatus(  | 
            ||
| 606 | PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,  | 
            ||
| 607 | string $refundStatus  | 
            ||
| 608 |     ): void { | 
            ||
| 609 | $payoneOrderItemFilterTransfer = (new PayoneOrderItemFilterTransfer())  | 
            ||
| 610 | ->setIdSalesOrder($payonePartialOperationRequestTransfer->getOrder()->getIdSalesOrder())  | 
            ||
| 611 | ->setSalesOrderItemIds($payonePartialOperationRequestTransfer->getSalesOrderItemIds());  | 
            ||
| 612 | |||
| 613 | $payoneOrderItemTransfers = $this->payoneRepository->findPaymentPayoneOrderItemByFilter($payoneOrderItemFilterTransfer);  | 
            ||
| 614 | |||
| 615 |         foreach ($payoneOrderItemTransfers as $payoneOrderItemTransfer) { | 
            ||
| 616 | $payoneOrderItemTransfer->setStatus($refundStatus);  | 
            ||
| 617 | $this->payoneEntityManager->updatePaymentPayoneOrderItem($payoneOrderItemTransfer);  | 
            ||
| 618 | }  | 
            ||
| 619 | }  | 
            ||
| 620 | |||
| 621 | /**  | 
            ||
| 622 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer  | 
            ||
| 623 | *  | 
            ||
| 624 | * @return string  | 
            ||
| 625 | */  | 
            ||
| 626 | protected function getPartialRefundStatus(RefundResponseContainer $responseContainer): string  | 
            ||
| 627 |     { | 
            ||
| 628 |         if ($responseContainer->getStatus() === PayoneApiConstants::RESPONSE_TYPE_APPROVED) { | 
            ||
| 629 | return PayoneTransactionStatusConstants::STATUS_REFUND_APPROVED;  | 
            ||
| 630 | }  | 
            ||
| 631 | |||
| 632 | return PayoneTransactionStatusConstants::STATUS_REFUND_FAILED;  | 
            ||
| 633 | }  | 
            ||
| 634 | |||
| 635 | /**  | 
            ||
| 636 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer  | 
            ||
| 637 | *  | 
            ||
| 638 | * @return \Generated\Shared\Transfer\PayonePaymentTransfer  | 
            ||
| 639 | */  | 
            ||
| 640 | protected function getPayment(OrderTransfer $orderTransfer)  | 
            ||
| 653 | }  | 
            ||
| 654 | |||
| 655 | /**  | 
            ||
| 656 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity  | 
            ||
| 657 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer  | 
            ||
| 658 | *  | 
            ||
| 659 | * @return void  | 
            ||
| 660 | */  | 
            ||
| 661 | protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)  | 
            ||
| 662 |     { | 
            ||
| 663 | $paymentEntity->setTransactionId($responseContainer->getTxid());  | 
            ||
| 664 | $paymentEntity->save();  | 
            ||
| 665 | }  | 
            ||
| 666 | |||
| 667 | /**  | 
            ||
| 668 | * @param string $transactionId  | 
            ||
| 669 | *  | 
            ||
| 670 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone  | 
            ||
| 671 | */  | 
            ||
| 672 | protected function findPaymentByTransactionId($transactionId)  | 
            ||
| 673 |     { | 
            ||
| 674 | return $this->queryContainer->createPaymentByTransactionIdQuery($transactionId)->findOne();  | 
            ||
| 675 | }  | 
            ||
| 676 | |||
| 677 | /**  | 
            ||
| 678 | * @param string $invoiceTitle  | 
            ||
| 679 | * @param int $customerId  | 
            ||
| 680 | *  | 
            ||
| 681 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery  | 
            ||
| 682 | */  | 
            ||
| 683 | protected function findPaymentByInvoiceTitleAndCustomerId($invoiceTitle, $customerId)  | 
            ||
| 684 |     { | 
            ||
| 685 | return $this->queryContainer->createPaymentByInvoiceTitleAndCustomerIdQuery($invoiceTitle, $customerId)->findOne();  | 
            ||
| 686 | }  | 
            ||
| 687 | |||
| 688 | /**  | 
            ||
| 689 | * @param string $fileReference  | 
            ||
| 690 | * @param int $customerId  | 
            ||
| 691 | *  | 
            ||
| 692 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery  | 
            ||
| 693 | */  | 
            ||
| 694 | protected function findPaymentByFileReferenceAndCustomerId($fileReference, $customerId)  | 
            ||
| 697 | }  | 
            ||
| 698 | |||
| 699 | /**  | 
            ||
| 700 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity  | 
            ||
| 701 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container  | 
            ||
| 702 | *  | 
            ||
| 703 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog  | 
            ||
| 704 | */  | 
            ||
| 705 | protected function initializeApiLog(SpyPaymentPayone $paymentEntity, AbstractRequestContainer $container)  | 
            ||
| 706 |     { | 
            ||
| 707 | $entity = new SpyPaymentPayoneApiLog();  | 
            ||
| 708 | $entity->setSpyPaymentPayone($paymentEntity);  | 
            ||
| 709 | $entity->setRequest($container->getRequest());  | 
            ||
| 710 | $entity->setMode($container->getMode());  | 
            ||
| 711 | $entity->setMerchantId($container->getMid());  | 
            ||
| 712 | $entity->setPortalId($container->getPortalid());  | 
            ||
| 713 |         if ($container instanceof CaptureContainer || $container instanceof RefundContainer || $container instanceof DebitContainer) { | 
            ||
| 714 | $entity->setSequenceNumber($container->getSequenceNumber());  | 
            ||
| 715 | }  | 
            ||
| 716 | // Logging request data for debug  | 
            ||
| 717 | $entity->setRawRequest(json_encode($container->toArray()));  | 
            ||
| 718 | $entity->save();  | 
            ||
| 719 | |||
| 720 | return $entity;  | 
            ||
| 721 | }  | 
            ||
| 722 | |||
| 723 | /**  | 
            ||
| 724 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity  | 
            ||
| 725 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer  | 
            ||
| 726 | *  | 
            ||
| 727 | * @return void  | 
            ||
| 728 | */  | 
            ||
| 729 | protected function updateApiLogAfterAuthorization(SpyPaymentPayoneApiLog $apiLogEntity, AuthorizationResponseContainer $responseContainer)  | 
            ||
| 730 |     { | 
            ||
| 731 | $apiLogEntity->setStatus($responseContainer->getStatus());  | 
            ||
| 732 | $apiLogEntity->setUserId($responseContainer->getUserid());  | 
            ||
| 733 | $apiLogEntity->setTransactionId($responseContainer->getTxid());  | 
            ||
| 734 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());  | 
            ||
| 735 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());  | 
            ||
| 736 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode());  | 
            ||
| 737 | $apiLogEntity->setRedirectUrl($responseContainer->getRedirecturl());  | 
            ||
| 738 | $apiLogEntity->setSequenceNumber(0);  | 
            ||
| 739 | |||
| 740 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));  | 
            ||
| 741 | $apiLogEntity->save();  | 
            ||
| 742 | }  | 
            ||
| 743 | |||
| 744 | /**  | 
            ||
| 745 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity  | 
            ||
| 746 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer $responseContainer  | 
            ||
| 747 | *  | 
            ||
| 748 | * @return void  | 
            ||
| 749 | */  | 
            ||
| 750 | protected function updateApiLogAfterCapture(SpyPaymentPayoneApiLog $apiLogEntity, CaptureResponseContainer $responseContainer)  | 
            ||
| 751 |     { | 
            ||
| 752 | $apiLogEntity->setStatus($responseContainer->getStatus());  | 
            ||
| 753 | $apiLogEntity->setTransactionId($responseContainer->getTxid());  | 
            ||
| 754 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());  | 
            ||
| 755 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());  | 
            ||
| 756 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode());  | 
            ||
| 757 | |||
| 758 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));  | 
            ||
| 759 | $apiLogEntity->save();  | 
            ||
| 760 | }  | 
            ||
| 761 | |||
| 762 | /**  | 
            ||
| 763 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity  | 
            ||
| 764 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer $responseContainer  | 
            ||
| 765 | *  | 
            ||
| 766 | * @return void  | 
            ||
| 767 | */  | 
            ||
| 768 | protected function updateApiLogAfterDebit(SpyPaymentPayoneApiLog $apiLogEntity, DebitResponseContainer $responseContainer)  | 
            ||
| 769 |     { | 
            ||
| 770 | $apiLogEntity->setStatus($responseContainer->getStatus());  | 
            ||
| 771 | $apiLogEntity->setTransactionId($responseContainer->getTxid());  | 
            ||
| 772 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());  | 
            ||
| 773 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());  | 
            ||
| 774 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode());  | 
            ||
| 775 | |||
| 776 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));  | 
            ||
| 777 | $apiLogEntity->save();  | 
            ||
| 778 | }  | 
            ||
| 779 | |||
| 780 | /**  | 
            ||
| 781 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity  | 
            ||
| 782 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer  | 
            ||
| 783 | *  | 
            ||
| 784 | * @return void  | 
            ||
| 785 | */  | 
            ||
| 786 | protected function updateApiLogAfterRefund(SpyPaymentPayoneApiLog $apiLogEntity, RefundResponseContainer $responseContainer)  | 
            ||
| 787 |     { | 
            ||
| 788 | $apiLogEntity->setTransactionId($responseContainer->getTxid());  | 
            ||
| 789 | $apiLogEntity->setStatus($responseContainer->getStatus());  | 
            ||
| 790 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage());  | 
            ||
| 791 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage());  | 
            ||
| 792 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode());  | 
            ||
| 793 | |||
| 794 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray()));  | 
            ||
| 795 | $apiLogEntity->save();  | 
            ||
| 796 | }  | 
            ||
| 797 | |||
| 798 | /**  | 
            ||
| 799 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container  | 
            ||
| 800 | *  | 
            ||
| 801 | * @return void  | 
            ||
| 802 | */  | 
            ||
| 803 | protected function setStandardParameter(AbstractRequestContainer $container)  | 
            ||
| 804 |     { | 
            ||
| 805 | $container->setApiVersion(PayoneApiConstants::API_VERSION_3_9);  | 
            ||
| 806 | $container->setEncoding($this->standardParameter->getEncoding());  | 
            ||
| 807 | $container->setKey($this->hashGenerator->hash($this->standardParameter->getKey()));  | 
            ||
| 808 | $container->setMid($this->standardParameter->getMid());  | 
            ||
| 809 | $container->setPortalid($this->standardParameter->getPortalId());  | 
            ||
| 810 | $container->setMode($this->modeDetector->getMode());  | 
            ||
| 811 | $container->setIntegratorName(PayoneApiConstants::INTEGRATOR_NAME_SPRYKER);  | 
            ||
| 812 | $container->setIntegratorVersion(PayoneApiConstants::INTEGRATOR_VERSION_3_0_0);  | 
            ||
| 813 | $container->setSolutionName(PayoneApiConstants::SOLUTION_NAME_SPRYKER);  | 
            ||
| 814 | $container->setSolutionVersion(PayoneApiConstants::SOLUTION_VERSION_3_0_0);  | 
            ||
| 815 | }  | 
            ||
| 816 | |||
| 817 | /**  | 
            ||
| 818 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer $container  | 
            ||
| 819 | *  | 
            ||
| 820 | * @return void  | 
            ||
| 821 | */  | 
            ||
| 822 | protected function setAccessDeniedError(AbstractResponseContainer $container)  | 
            ||
| 823 |     { | 
            ||
| 824 | $container->setStatus(PayoneApiConstants::RESPONSE_TYPE_ERROR);  | 
            ||
| 825 | $container->setErrormessage(static::ERROR_ACCESS_DENIED_MESSAGE);  | 
            ||
| 826 | $container->setCustomermessage(static::ERROR_ACCESS_DENIED_MESSAGE);  | 
            ||
| 827 | }  | 
            ||
| 828 | |||
| 829 | /**  | 
            ||
| 830 | * @param int $idOrder  | 
            ||
| 831 | *  | 
            ||
| 832 | * @return \Generated\Shared\Transfer\PaymentDetailTransfer  | 
            ||
| 833 | */  | 
            ||
| 834 | public function getPaymentDetail($idOrder)  | 
            ||
| 835 |     { | 
            ||
| 836 | $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();  | 
            ||
| 837 | $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();  | 
            ||
| 838 | $paymentDetailTransfer = new PaymentDetailTransfer();  | 
            ||
| 839 | $paymentDetailTransfer->fromArray($paymentDetailEntity->toArray(), true);  | 
            ||
| 840 | |||
| 841 | return $paymentDetailTransfer;  | 
            ||
| 842 | }  | 
            ||
| 843 | |||
| 844 | /**  | 
            ||
| 845 | * Gets payment logs (both api and transaction status) for specific orders in chronological order.  | 
            ||
| 846 | *  | 
            ||
| 847 | * @param \Propel\Runtime\Collection\ObjectCollection|\ArrayObject $orders  | 
            ||
| 848 | *  | 
            ||
| 849 | * @return \Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer  | 
            ||
| 850 | */  | 
            ||
| 851 | public function getPaymentLogs($orders)  | 
            ||
| 852 |     { | 
            ||
| 853 | $apiLogs = $this->queryContainer->createApiLogsByOrderIds($orders)->find()->getData();  | 
            ||
| 854 | |||
| 855 | $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds($orders)->find()->getData();  | 
            ||
| 856 | |||
| 857 | $logs = [];  | 
            ||
| 858 | /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLog */  | 
            ||
| 859 |         foreach ($apiLogs as $apiLog) { | 
            ||
| 860 |             $key = $apiLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 'a' . $apiLog->getIdPaymentPayoneApiLog(); | 
            ||
| 861 | $payonePaymentLogTransfer = new PayonePaymentLogTransfer();  | 
            ||
| 862 | $payonePaymentLogTransfer->fromArray($apiLog->toArray(), true);  | 
            ||
| 863 | $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_API_LOG);  | 
            ||
| 864 | $logs[$key] = $payonePaymentLogTransfer;  | 
            ||
| 865 | }  | 
            ||
| 866 | /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $transactionStatusLog */  | 
            ||
| 867 |         foreach ($transactionStatusLogs as $transactionStatusLog) { | 
            ||
| 868 |             $key = $transactionStatusLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 't' . $transactionStatusLog->getIdPaymentPayoneTransactionStatusLog(); | 
            ||
| 869 | $payonePaymentLogTransfer = new PayonePaymentLogTransfer();  | 
            ||
| 870 | $payonePaymentLogTransfer->fromArray($transactionStatusLog->toArray(), true);  | 
            ||
| 871 | $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_TRANSACTION_STATUS_LOG);  | 
            ||
| 872 | $logs[$key] = $payonePaymentLogTransfer;  | 
            ||
| 873 | }  | 
            ||
| 874 | |||
| 875 | ksort($logs);  | 
            ||
| 876 | |||
| 877 | $payonePaymentLogCollectionTransfer = new PayonePaymentLogCollectionTransfer();  | 
            ||
| 878 | |||
| 879 |         foreach ($logs as $log) { | 
            ||
| 880 | $payonePaymentLogCollectionTransfer->addPaymentLogs($log);  | 
            ||
| 881 | }  | 
            ||
| 882 | |||
| 883 | return $payonePaymentLogCollectionTransfer;  | 
            ||
| 884 | }  | 
            ||
| 885 | |||
| 886 | /**  | 
            ||
| 887 | * @param \Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer  | 
            ||
| 888 | *  | 
            ||
| 889 | * @return array  | 
            ||
| 890 | */  | 
            ||
| 891 | public function getCreditCardCheckRequestData(PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer)  | 
            ||
| 892 |     { | 
            ||
| 893 | $this->standardParameter->fromArray($creditCardCheckRequestDataTransfer->toArray(), true);  | 
            ||
| 894 | |||
| 895 | $creditCardCheck = new CreditCardCheck($this->standardParameter, $this->hashGenerator, $this->modeDetector);  | 
            ||
| 896 | |||
| 897 | $data = $creditCardCheck->mapCreditCardCheckData();  | 
            ||
| 898 | |||
| 899 | return $data->toArray();  | 
            ||
| 900 | }  | 
            ||
| 901 | |||
| 902 | /**  | 
            ||
| 903 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer  | 
            ||
| 904 | *  | 
            ||
| 905 | * @return bool  | 
            ||
| 906 | */  | 
            ||
| 907 | public function isRefundPossible(OrderTransfer $orderTransfer)  | 
            ||
| 908 |     { | 
            ||
| 909 | $paymentTransfer = $this->getPayment($orderTransfer);  | 
            ||
| 910 | |||
| 911 |         if (!$this->isPaymentDataRequired($orderTransfer)) { | 
            ||
| 912 | return true;  | 
            ||
| 913 | }  | 
            ||
| 914 | |||
| 915 | $paymentDetailTransfer = $paymentTransfer->getPaymentDetail();  | 
            ||
| 916 | |||
| 917 | return $paymentDetailTransfer->getBic() && $paymentDetailTransfer->getIban();  | 
            ||
| 918 | }  | 
            ||
| 919 | |||
| 920 | /**  | 
            ||
| 921 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer  | 
            ||
| 922 | *  | 
            ||
| 923 | * @return bool  | 
            ||
| 924 | */  | 
            ||
| 925 | public function isPaymentDataRequired(OrderTransfer $orderTransfer)  | 
            ||
| 926 |     { | 
            ||
| 927 | $paymentTransfer = $this->getPayment($orderTransfer);  | 
            ||
| 928 | |||
| 929 | // Return early if we don't need the iban or bic data  | 
            ||
| 930 | $paymentMethod = $paymentTransfer->getPaymentMethod();  | 
            ||
| 931 | $whiteList = [  | 
            ||
| 932 | PayoneApiConstants::PAYMENT_METHOD_E_WALLET,  | 
            ||
| 933 | PayoneApiConstants::PAYMENT_METHOD_CREDITCARD_PSEUDO,  | 
            ||
| 934 | PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER,  | 
            ||
| 935 | ];  | 
            ||
| 936 | |||
| 937 |         if (in_array($paymentMethod, $whiteList)) { | 
            ||
| 938 | return false;  | 
            ||
| 939 | }  | 
            ||
| 940 | |||
| 941 | return true;  | 
            ||
| 942 | }  | 
            ||
| 943 | |||
| 944 | /**  | 
            ||
| 945 | * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer  | 
            ||
| 946 | * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse  | 
            ||
| 947 | *  | 
            ||
| 948 | * @return \Generated\Shared\Transfer\CheckoutResponseTransfer  | 
            ||
| 949 | */  | 
            ||
| 950 | public function postSaveHook(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse)  | 
            ||
| 951 |     { | 
            ||
| 952 | $apiLogsQuery = $this->queryContainer->createLastApiLogsByOrderId($quoteTransfer->getPayment()->getPayone()->getFkSalesOrder());  | 
            ||
| 953 | $apiLog = $apiLogsQuery->findOne();  | 
            ||
| 954 | |||
| 955 |         if ($apiLog) { | 
            ||
| 956 | $redirectUrl = $apiLog->getRedirectUrl();  | 
            ||
| 957 | |||
| 958 |             if ($redirectUrl !== null) { | 
            ||
| 959 | $checkoutResponse->setIsExternalRedirect(true);  | 
            ||
| 960 | $checkoutResponse->setRedirectUrl($redirectUrl);  | 
            ||
| 961 | }  | 
            ||
| 962 | |||
| 963 | $errorCode = $apiLog->getErrorCode();  | 
            ||
| 964 | |||
| 965 |             if ($errorCode) { | 
            ||
| 966 | $error = new CheckoutErrorTransfer();  | 
            ||
| 967 | $error->setMessage($apiLog->getErrorMessageUser());  | 
            ||
| 968 | $error->setErrorCode($errorCode);  | 
            ||
| 969 | $checkoutResponse->addError($error);  | 
            ||
| 970 | $checkoutResponse->setIsSuccess(false);  | 
            ||
| 971 | }  | 
            ||
| 972 | }  | 
            ||
| 973 | |||
| 974 | return $checkoutResponse;  | 
            ||
| 975 | }  | 
            ||
| 976 | |||
| 977 | /**  | 
            ||
| 978 | * @param \Generated\Shared\Transfer\PaymentDetailTransfer $paymentDataTransfer  | 
            ||
| 979 | * @param int $idOrder  | 
            ||
| 980 | *  | 
            ||
| 981 | * @return void  | 
            ||
| 982 | */  | 
            ||
| 983 | public function updatePaymentDetail(PaymentDetailTransfer $paymentDataTransfer, $idOrder)  | 
            ||
| 984 |     { | 
            ||
| 985 | $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne();  | 
            ||
| 986 | $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();  | 
            ||
| 987 | |||
| 988 | $paymentDetailEntity->fromArray($paymentDataTransfer->toArray());  | 
            ||
| 989 | |||
| 990 | $paymentDetailEntity->save();  | 
            ||
| 991 | }  | 
            ||
| 992 | |||
| 993 | /**  | 
            ||
| 994 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity  | 
            ||
| 995 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer  | 
            ||
| 996 | *  | 
            ||
| 997 | * @return void  | 
            ||
| 998 | */  | 
            ||
| 999 | protected function updatePaymentDetailAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer)  | 
            ||
| 1000 |     { | 
            ||
| 1001 | $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();  | 
            ||
| 1002 | |||
| 1003 | $paymentDetailEntity->setClearingBankAccountHolder($responseContainer->getClearingBankaccountholder());  | 
            ||
| 1004 | $paymentDetailEntity->setClearingBankCountry($responseContainer->getClearingBankcountry());  | 
            ||
| 1005 | $paymentDetailEntity->setClearingBankAccount($responseContainer->getClearingBankaccount());  | 
            ||
| 1006 | $paymentDetailEntity->setClearingBankCode($responseContainer->getClearingBankcode());  | 
            ||
| 1007 | $paymentDetailEntity->setClearingBankIban($responseContainer->getClearingBankiban());  | 
            ||
| 1008 | $paymentDetailEntity->setClearingBankBic($responseContainer->getClearingBankbic());  | 
            ||
| 1009 | $paymentDetailEntity->setClearingBankCity($responseContainer->getClearingBankcity());  | 
            ||
| 1010 | $paymentDetailEntity->setClearingBankName($responseContainer->getClearingBankname());  | 
            ||
| 1011 | |||
| 1012 |         if ($responseContainer->getMandateIdentification()) { | 
            ||
| 1013 | $paymentDetailEntity->setMandateIdentification($responseContainer->getMandateIdentification());  | 
            ||
| 1014 | }  | 
            ||
| 1015 | |||
| 1016 |         if ($paymentEntity->getPaymentMethod() == PayoneApiConstants::PAYMENT_METHOD_INVOICE) { | 
            ||
| 1017 | $paymentDetailEntity->setInvoiceTitle($this->getInvoiceTitle($paymentEntity->getTransactionId()));  | 
            ||
| 1018 | }  | 
            ||
| 1019 | |||
| 1020 | $paymentDetailEntity->save();  | 
            ||
| 1021 | }  | 
            ||
| 1022 | |||
| 1023 | /**  | 
            ||
| 1024 | * @param \Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer  | 
            ||
| 1025 | *  | 
            ||
| 1026 | * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer  | 
            ||
| 1027 | */  | 
            ||
| 1028 | public function initPaypalExpressCheckout(PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer)  | 
            ||
| 1029 |     { | 
            ||
| 1030 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(  | 
            ||
| 1031 | PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT  | 
            ||
| 1032 | );  | 
            ||
| 1033 | $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();  | 
            ||
| 1034 | $baseGenericPaymentContainer->getPaydata()->setAction(PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_SET_ACTION);  | 
            ||
| 1035 | $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment(  | 
            ||
| 1036 | $baseGenericPaymentContainer,  | 
            ||
| 1037 | $requestTransfer  | 
            ||
| 1038 | );  | 
            ||
| 1039 | $responseTransfer = $this->performGenericRequest($requestContainer);  | 
            ||
| 1040 | |||
| 1041 | return $responseTransfer;  | 
            ||
| 1042 | }  | 
            ||
| 1043 | |||
| 1044 | /**  | 
            ||
| 1045 | * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer  | 
            ||
| 1046 | *  | 
            ||
| 1047 | * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer  | 
            ||
| 1048 | */  | 
            ||
| 1049 | public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer)  | 
            ||
| 1050 |     { | 
            ||
| 1051 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(  | 
            ||
| 1052 | PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT  | 
            ||
| 1053 | );  | 
            ||
| 1054 | |||
| 1055 | $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer();  | 
            ||
| 1056 | $baseGenericPaymentContainer->getPaydata()->setAction(  | 
            ||
| 1057 | PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION  | 
            ||
| 1058 | );  | 
            ||
| 1059 | $requestContainer = $paymentMethodMapper->mapQuoteTransferToGenericPayment(  | 
            ||
| 1060 | $baseGenericPaymentContainer,  | 
            ||
| 1061 | $quoteTransfer  | 
            ||
| 1062 | );  | 
            ||
| 1063 | $responseTransfer = $this->performGenericRequest($requestContainer);  | 
            ||
| 1064 | |||
| 1065 | return $responseTransfer;  | 
            ||
| 1066 | }  | 
            ||
| 1067 | |||
| 1068 | /**  | 
            ||
| 1069 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $requestContainer  | 
            ||
| 1070 | *  | 
            ||
| 1071 | * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer  | 
            ||
| 1072 | */  | 
            ||
| 1073 | protected function performGenericRequest(GenericPaymentContainer $requestContainer)  | 
            ||
| 1074 |     { | 
            ||
| 1075 | $this->setStandardParameter($requestContainer);  | 
            ||
| 1076 | |||
| 1077 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer);  | 
            ||
| 1078 | $responseContainer = new GenericPaymentResponseContainer($rawResponse);  | 
            ||
| 1079 | $responseTransfer = new PayonePaypalExpressCheckoutGenericPaymentResponseTransfer();  | 
            ||
| 1080 | $responseTransfer->setRedirectUrl($responseContainer->getRedirectUrl());  | 
            ||
| 1081 | $responseTransfer->setWorkOrderId($responseContainer->getWorkOrderId());  | 
            ||
| 1082 | $responseTransfer->setRawResponse(json_encode($rawResponse));  | 
            ||
| 1083 | $responseTransfer->setStatus($responseContainer->getStatus());  | 
            ||
| 1084 | $responseTransfer->setCustomerMessage($responseContainer->getCustomermessage());  | 
            ||
| 1085 | $responseTransfer->setErrorMessage($responseContainer->getErrormessage());  | 
            ||
| 1086 | $responseTransfer->setErrorCode($responseContainer->getErrorcode());  | 
            ||
| 1087 | $responseTransfer->setEmail($responseContainer->getEmail());  | 
            ||
| 1088 | $responseTransfer->setShippingFirstName($responseContainer->getShippingFirstname());  | 
            ||
| 1089 | $responseTransfer->setShippingLastName($responseContainer->getShippingLastname());  | 
            ||
| 1090 | $responseTransfer->setShippingCompany($responseContainer->getShippingCompany());  | 
            ||
| 1091 | $responseTransfer->setShippingCountry($responseContainer->getShippingCountry());  | 
            ||
| 1092 | $responseTransfer->setShippingState($responseContainer->getShippingState());  | 
            ||
| 1093 | $responseTransfer->setShippingStreet($responseContainer->getShippingStreet());  | 
            ||
| 1094 | $responseTransfer->setShippingAddressAdition($responseContainer->getShippingAddressaddition());  | 
            ||
| 1095 | $responseTransfer->setShippingCity($responseContainer->getShippingCity());  | 
            ||
| 1096 | $responseTransfer->setShippingZip($responseContainer->getShippingZip());  | 
            ||
| 1097 | |||
| 1098 | return $responseTransfer;  | 
            ||
| 1099 | }  | 
            ||
| 1100 | |||
| 1101 | /**  | 
            ||
| 1102 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer  | 
            ||
| 1103 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container  | 
            ||
| 1104 | *  | 
            ||
| 1105 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer  | 
            ||
| 1106 | */  | 
            ||
| 1107 | protected function prepareOrderItems(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer  | 
            ||
| 1108 |     { | 
            ||
| 1109 | $arrayIt = [];  | 
            ||
| 1110 | $arrayId = [];  | 
            ||
| 1111 | $arrayPr = [];  | 
            ||
| 1112 | $arrayNo = [];  | 
            ||
| 1113 | $arrayDe = [];  | 
            ||
| 1114 | $arrayVa = [];  | 
            ||
| 1115 | |||
| 1116 | $key = 1;  | 
            ||
| 1117 | |||
| 1118 |         foreach ($orderTransfer->getItems() as $itemTransfer) { | 
            ||
| 1119 | $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;  | 
            ||
| 1120 | $arrayId[$key] = $itemTransfer->getSku();  | 
            ||
| 1121 | $arrayPr[$key] = $itemTransfer->getUnitGrossPrice();  | 
            ||
| 1122 | $arrayNo[$key] = $itemTransfer->getQuantity();  | 
            ||
| 1123 | $arrayDe[$key] = $itemTransfer->getName();  | 
            ||
| 1124 | $arrayVa[$key] = (int)$itemTransfer->getTaxRate();  | 
            ||
| 1125 | $key++;  | 
            ||
| 1126 | }  | 
            ||
| 1127 | |||
| 1128 | $container->setIt($arrayIt);  | 
            ||
| 1129 | $container->setId($arrayId);  | 
            ||
| 1130 | $container->setPr($arrayPr);  | 
            ||
| 1131 | $container->setNo($arrayNo);  | 
            ||
| 1132 | $container->setDe($arrayDe);  | 
            ||
| 1133 | $container->setVa($arrayVa);  | 
            ||
| 1134 | |||
| 1135 | return $container;  | 
            ||
| 1136 | }  | 
            ||
| 1137 | |||
| 1138 | /**  | 
            ||
| 1139 | * @param \Generated\Shared\Transfer\PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer  | 
            ||
| 1140 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container  | 
            ||
| 1141 | *  | 
            ||
| 1142 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer  | 
            ||
| 1143 | */  | 
            ||
| 1144 | protected function preparePartialRefundOrderItems(  | 
            ||
| 1145 | PayonePartialOperationRequestTransfer $payonePartialOperationRequestTransfer,  | 
            ||
| 1146 | AbstractRequestContainer $container  | 
            ||
| 1147 |     ): AbstractRequestContainer { | 
            ||
| 1148 | $arrayIt = [];  | 
            ||
| 1149 | $arrayId = [];  | 
            ||
| 1150 | $arrayPr = [];  | 
            ||
| 1151 | $arrayNo = [];  | 
            ||
| 1152 | $arrayDe = [];  | 
            ||
| 1153 | $arrayVa = [];  | 
            ||
| 1154 | |||
| 1155 | $key = 1;  | 
            ||
| 1156 | |||
| 1157 |         foreach ($payonePartialOperationRequestTransfer->getOrder()->getItems() as $itemTransfer) { | 
            ||
| 1158 |             if (!in_array($itemTransfer->getIdSalesOrderItem(), $payonePartialOperationRequestTransfer->getSalesOrderItemIds())) { | 
            ||
| 1159 | continue;  | 
            ||
| 1160 | }  | 
            ||
| 1161 | |||
| 1162 | $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;  | 
            ||
| 1163 | $arrayId[$key] = $itemTransfer->getSku();  | 
            ||
| 1164 | $arrayPr[$key] = $itemTransfer->getRefundableAmount();  | 
            ||
| 1165 | $arrayNo[$key] = $itemTransfer->getQuantity();  | 
            ||
| 1166 | $arrayDe[$key] = $itemTransfer->getName();  | 
            ||
| 1167 | $arrayVa[$key] = (int)$itemTransfer->getTaxRate();  | 
            ||
| 1168 | $key++;  | 
            ||
| 1169 | }  | 
            ||
| 1170 | |||
| 1171 | $container->setIt($arrayIt);  | 
            ||
| 1172 | $container->setId($arrayId);  | 
            ||
| 1173 | $container->setPr($arrayPr);  | 
            ||
| 1174 | $container->setNo($arrayNo);  | 
            ||
| 1175 | $container->setDe($arrayDe);  | 
            ||
| 1176 | $container->setVa($arrayVa);  | 
            ||
| 1177 | |||
| 1178 | return $container;  | 
            ||
| 1179 | }  | 
            ||
| 1180 | |||
| 1181 | /**  | 
            ||
| 1182 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer  | 
            ||
| 1183 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container  | 
            ||
| 1184 | *  | 
            ||
| 1185 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer  | 
            ||
| 1186 | */  | 
            ||
| 1187 | protected function prepareOrderShipment(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer  | 
            ||
| 1188 |     { | 
            ||
| 1189 | $arrayIt = $container->getIt() ?? [];  | 
            ||
| 1190 | $arrayId = $container->getId() ?? [];  | 
            ||
| 1191 | $arrayPr = $container->getPr() ?? [];  | 
            ||
| 1192 | $arrayNo = $container->getNo() ?? [];  | 
            ||
| 1193 | $arrayDe = $container->getDe() ?? [];  | 
            ||
| 1194 | $arrayVa = $container->getVa() ?? [];  | 
            ||
| 1195 | |||
| 1196 | $key = count($arrayId) + 1;  | 
            ||
| 1197 | $expenses = $orderTransfer->getExpenses();  | 
            ||
| 1198 | |||
| 1199 | $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;  | 
            ||
| 1200 | $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT;  | 
            ||
| 1201 | $arrayPr[$key] = $this->getDeliveryCosts($expenses);  | 
            ||
| 1202 | $arrayNo[$key] = 1;  | 
            ||
| 1203 | $arrayDe[$key] = 'Shipment';  | 
            ||
| 1204 | |||
| 1205 | $container->setIt($arrayIt);  | 
            ||
| 1206 | $container->setId($arrayId);  | 
            ||
| 1207 | $container->setPr($arrayPr);  | 
            ||
| 1208 | $container->setNo($arrayNo);  | 
            ||
| 1209 | $container->setDe($arrayDe);  | 
            ||
| 1210 | $container->setVa($arrayVa);  | 
            ||
| 1211 | |||
| 1212 | return $container;  | 
            ||
| 1213 | }  | 
            ||
| 1214 | |||
| 1215 | /**  | 
            ||
| 1216 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer  | 
            ||
| 1217 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container  | 
            ||
| 1218 | *  | 
            ||
| 1219 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer  | 
            ||
| 1220 | */  | 
            ||
| 1221 | protected function prepareOrderDiscount(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer  | 
            ||
| 1246 | }  | 
            ||
| 1247 | |||
| 1248 | /**  | 
            ||
| 1249 | * @param \ArrayObject $expenses  | 
            ||
| 1250 | *  | 
            ||
| 1251 | * @return string  | 
            ||
| 1252 | */  | 
            ||
| 1253 | protected function getDeliveryCosts(ArrayObject $expenses): string  | 
            ||
| 1254 |     { | 
            ||
| 1255 |         foreach ($expenses as $expense) { | 
            ||
| 1262 | }  | 
            ||
| 1263 | }  | 
            ||
| 1264 | 
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths