Total Complexity | 80 |
Total Lines | 1226 |
Duplicated Lines | 0 % |
Changes | 12 | ||
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) |
||
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) |
||
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) |
||
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 |
||
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 |
||
357 | */ |
||
358 | public function creditCardCheck(PayoneCreditCardTransfer $creditCardData) |
||
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) { |
||
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) { |
||
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) { |
||
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('-', [ |
||
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) |
||
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(); |
||
676 | } |
||
677 | |||
678 | /** |
||
679 | * @param string $invoiceTitle |
||
680 | * @param int $customerId |
||
681 | * |
||
682 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery |
||
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) |
||
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())); |
||
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(); |
||
855 | |||
856 | $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds($orders)->find()->getData(); |
||
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); |
||
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(); |
||
1035 | $baseGenericPaymentContainer->getPaydata()->setAction(PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_SET_ACTION); |
||
1036 | $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment( |
||
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( |
||
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 |
||
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 |
||
1301 | } |
||
1302 | } |
||
1303 |
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