Total Complexity | 72 |
Total Lines | 1101 |
Duplicated Lines | 0 % |
Changes | 10 | ||
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 |
||
69 | class PaymentManager implements PaymentManagerInterface |
||
70 | { |
||
71 | public const LOG_TYPE_API_LOG = 'SpyPaymentPayoneApiLog'; |
||
72 | public const LOG_TYPE_TRANSACTION_STATUS_LOG = 'SpyPaymentPayoneTransactionStatusLog'; |
||
73 | public const ERROR_ACCESS_DENIED_MESSAGE = 'Access denied'; |
||
74 | |||
75 | /** |
||
76 | * @var \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface |
||
77 | */ |
||
78 | protected $executionAdapter; |
||
79 | |||
80 | /** |
||
81 | * @var \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface |
||
82 | */ |
||
83 | protected $queryContainer; |
||
84 | |||
85 | /** |
||
86 | * @var \Generated\Shared\Transfer\PayoneStandardParameterTransfer |
||
87 | */ |
||
88 | protected $standardParameter; |
||
89 | |||
90 | /** |
||
91 | * @var \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface |
||
92 | */ |
||
93 | protected $sequenceNumberProvider; |
||
94 | |||
95 | /** |
||
96 | * @var \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface |
||
97 | */ |
||
98 | protected $modeDetector; |
||
99 | |||
100 | /** |
||
101 | * @var \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface |
||
102 | */ |
||
103 | protected $hashGenerator; |
||
104 | |||
105 | /** |
||
106 | * @var \SprykerEco\Zed\Payone\Business\Key\UrlHmacGenerator |
||
107 | */ |
||
108 | protected $urlHmacGenerator; |
||
109 | |||
110 | /** |
||
111 | * @var \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface[] |
||
112 | */ |
||
113 | protected $registeredMethodMappers; |
||
114 | |||
115 | /** |
||
116 | * @param \SprykerEco\Zed\Payone\Business\Api\Adapter\AdapterInterface $executionAdapter |
||
117 | * @param \SprykerEco\Zed\Payone\Persistence\PayoneQueryContainerInterface $queryContainer |
||
118 | * @param \Generated\Shared\Transfer\PayoneStandardParameterTransfer $standardParameter |
||
119 | * @param \SprykerEco\Zed\Payone\Business\Key\HashGenerator $hashGenerator |
||
120 | * @param \SprykerEco\Zed\Payone\Business\SequenceNumber\SequenceNumberProviderInterface $sequenceNumberProvider |
||
121 | * @param \SprykerEco\Shared\Payone\Dependency\ModeDetectorInterface $modeDetector |
||
122 | * @param \SprykerEco\Zed\Payone\Business\Key\HmacGeneratorInterface $urlHmacGenerator |
||
123 | */ |
||
124 | public function __construct( |
||
125 | AdapterInterface $executionAdapter, |
||
126 | PayoneQueryContainerInterface $queryContainer, |
||
127 | PayoneStandardParameterTransfer $standardParameter, |
||
128 | HashGenerator $hashGenerator, |
||
129 | SequenceNumberProviderInterface $sequenceNumberProvider, |
||
130 | ModeDetectorInterface $modeDetector, |
||
131 | HmacGeneratorInterface $urlHmacGenerator |
||
132 | ) { |
||
133 | |||
134 | $this->executionAdapter = $executionAdapter; |
||
135 | $this->queryContainer = $queryContainer; |
||
136 | $this->standardParameter = $standardParameter; |
||
137 | $this->hashGenerator = $hashGenerator; |
||
138 | $this->sequenceNumberProvider = $sequenceNumberProvider; |
||
139 | $this->modeDetector = $modeDetector; |
||
140 | $this->urlHmacGenerator = $urlHmacGenerator; |
||
141 | } |
||
142 | |||
143 | /** |
||
144 | * @param \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface $paymentMethodMapper |
||
145 | * |
||
146 | * @return void |
||
147 | */ |
||
148 | public function registerPaymentMethodMapper(PaymentMethodMapperInterface $paymentMethodMapper) |
||
149 | { |
||
150 | $paymentMethodMapper->setStandardParameter($this->standardParameter); |
||
151 | $paymentMethodMapper->setSequenceNumberProvider($this->sequenceNumberProvider); |
||
152 | $paymentMethodMapper->setUrlHmacGenerator($this->urlHmacGenerator); |
||
153 | $this->registeredMethodMappers[$paymentMethodMapper->getName()] = $paymentMethodMapper; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param string $name |
||
158 | * |
||
159 | * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface|null |
||
160 | */ |
||
161 | protected function findPaymentMethodMapperByName($name) |
||
162 | { |
||
163 | if (array_key_exists($name, $this->registeredMethodMappers)) { |
||
164 | return $this->registeredMethodMappers[$name]; |
||
165 | } |
||
166 | |||
167 | return null; |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @param string $paymentMethodName |
||
172 | * |
||
173 | * @throws \SprykerEco\Zed\Payone\Business\Exception\InvalidPaymentMethodException |
||
174 | * |
||
175 | * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface |
||
176 | */ |
||
177 | protected function getRegisteredPaymentMethodMapper($paymentMethodName) |
||
178 | { |
||
179 | $paymentMethodMapper = $this->findPaymentMethodMapperByName($paymentMethodName); |
||
180 | if ($paymentMethodMapper === null) { |
||
181 | throw new InvalidPaymentMethodException( |
||
182 | sprintf('No registered payment method mapper found for given method name %s', $paymentMethodName) |
||
183 | ); |
||
184 | } |
||
185 | |||
186 | return $paymentMethodMapper; |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
191 | * |
||
192 | * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer |
||
193 | */ |
||
194 | public function authorizePayment(OrderTransfer $orderTransfer) |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @param int $idSalesOrder |
||
212 | * |
||
213 | * @return \Generated\Shared\Transfer\AuthorizationResponseTransfer |
||
214 | */ |
||
215 | public function preAuthorizePayment($idSalesOrder) |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
||
230 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface $requestContainer |
||
231 | * |
||
232 | * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer |
||
233 | */ |
||
234 | protected function performAuthorizationRequest(SpyPaymentPayone $paymentEntity, AuthorizationContainerInterface $requestContainer) |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
||
250 | * |
||
251 | * @return \SprykerEco\Zed\Payone\Business\Payment\PaymentMethodMapperInterface |
||
252 | */ |
||
253 | protected function getPaymentMethodMapper(SpyPaymentPayone $paymentEntity) |
||
254 | { |
||
255 | return $this->getRegisteredPaymentMethodMapper($paymentEntity->getPaymentMethod()); |
||
256 | } |
||
257 | |||
258 | /** |
||
259 | * @param int $orderId |
||
260 | * |
||
261 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone |
||
262 | */ |
||
263 | protected function getPaymentEntity($orderId) |
||
266 | } |
||
267 | |||
268 | /** |
||
269 | * @param \Generated\Shared\Transfer\PayoneCaptureTransfer $captureTransfer |
||
270 | * |
||
271 | * @return \Generated\Shared\Transfer\CaptureResponseTransfer |
||
272 | */ |
||
273 | public function capturePayment(PayoneCaptureTransfer $captureTransfer): CaptureResponseTransfer |
||
274 | { |
||
275 | $paymentEntity = $this->getPaymentEntity($captureTransfer->getPayment()->getFkSalesOrder()); |
||
276 | $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity); |
||
277 | |||
278 | $requestContainer = $paymentMethodMapper->mapPaymentToCapture($paymentEntity); |
||
279 | $requestContainer = $this->prepareOrderItems($captureTransfer->getOrder(), $requestContainer); |
||
280 | $requestContainer = $this->prepareOrderShipment($captureTransfer->getOrder(), $requestContainer); |
||
281 | $requestContainer = $this->prepareOrderDiscount($captureTransfer->getOrder(), $requestContainer); |
||
282 | $requestContainer = $this->prepareOrderHandling($captureTransfer->getOrder(), $requestContainer); |
||
283 | |||
284 | if (!empty($captureTransfer->getSettleaccount())) { |
||
285 | $businnessContainer = new BusinessContainer(); |
||
286 | $businnessContainer->setSettleAccount($captureTransfer->getSettleaccount()); |
||
287 | $requestContainer->setBusiness($businnessContainer); |
||
288 | } |
||
289 | |||
290 | $this->setStandardParameter($requestContainer); |
||
291 | |||
292 | $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer); |
||
293 | |||
294 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
295 | $responseContainer = new CaptureResponseContainer($rawResponse); |
||
296 | |||
297 | $this->updateApiLogAfterCapture($apiLogEntity, $responseContainer); |
||
298 | |||
299 | $responseMapper = new CaptureResponseMapper(); |
||
300 | $responseTransfer = $responseMapper->getCaptureResponseTransfer($responseContainer); |
||
301 | |||
302 | return $responseTransfer; |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * @param int $idPayment |
||
307 | * |
||
308 | * @return \Generated\Shared\Transfer\DebitResponseTransfer |
||
309 | */ |
||
310 | public function debitPayment($idPayment) |
||
311 | { |
||
312 | $paymentEntity = $this->getPaymentEntity($idPayment); |
||
313 | $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity); |
||
314 | |||
315 | $requestContainer = $paymentMethodMapper->mapPaymentToDebit($paymentEntity); |
||
316 | $this->setStandardParameter($requestContainer); |
||
317 | |||
318 | $paymentEntity = $this->findPaymentByTransactionId($paymentEntity->getTransactionId()); |
||
319 | $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer); |
||
320 | |||
321 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
322 | $responseContainer = new DebitResponseContainer($rawResponse); |
||
323 | |||
324 | $this->updateApiLogAfterDebit($apiLogEntity, $responseContainer); |
||
325 | |||
326 | $responseMapper = new DebitResponseMapper(); |
||
327 | $responseTransfer = $responseMapper->getDebitResponseTransfer($responseContainer); |
||
328 | |||
329 | return $responseTransfer; |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * @param \Generated\Shared\Transfer\PayoneCreditCardTransfer $creditCardData |
||
334 | * |
||
335 | * @return \Generated\Shared\Transfer\CreditCardCheckResponseTransfer |
||
336 | */ |
||
337 | public function creditCardCheck(PayoneCreditCardTransfer $creditCardData) |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * @param \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer $bankAccountCheckTransfer |
||
356 | * |
||
357 | * @return \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer |
||
358 | */ |
||
359 | public function bankAccountCheck(PayoneBankAccountCheckTransfer $bankAccountCheckTransfer) |
||
360 | { |
||
361 | /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */ |
||
362 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER); |
||
363 | $requestContainer = $paymentMethodMapper->mapBankAccountCheck($bankAccountCheckTransfer); |
||
364 | $this->setStandardParameter($requestContainer); |
||
365 | |||
366 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
367 | $responseContainer = new BankAccountCheckResponseContainer($rawResponse); |
||
368 | |||
369 | $bankAccountCheckTransfer->setErrorCode($responseContainer->getErrorcode()); |
||
370 | $bankAccountCheckTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage()); |
||
371 | $bankAccountCheckTransfer->setStatus($responseContainer->getStatus()); |
||
372 | $bankAccountCheckTransfer->setInternalErrorMessage($responseContainer->getErrormessage()); |
||
373 | |||
374 | return $bankAccountCheckTransfer; |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * @param \Generated\Shared\Transfer\PayoneManageMandateTransfer $manageMandateTransfer |
||
379 | * |
||
380 | * @return \Generated\Shared\Transfer\PayoneManageMandateTransfer |
||
381 | */ |
||
382 | public function manageMandate(PayoneManageMandateTransfer $manageMandateTransfer) |
||
383 | { |
||
384 | /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */ |
||
385 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT); |
||
386 | $requestContainer = $paymentMethodMapper->mapManageMandate($manageMandateTransfer); |
||
387 | $this->setStandardParameter($requestContainer); |
||
388 | |||
389 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
390 | $responseContainer = new ManageMandateResponseContainer($rawResponse); |
||
391 | |||
392 | $manageMandateTransfer->setErrorCode($responseContainer->getErrorcode()); |
||
393 | $manageMandateTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage()); |
||
394 | $manageMandateTransfer->setStatus($responseContainer->getStatus()); |
||
395 | $manageMandateTransfer->setInternalErrorMessage($responseContainer->getErrormessage()); |
||
396 | $manageMandateTransfer->setMandateIdentification($responseContainer->getMandateIdentification()); |
||
397 | $manageMandateTransfer->setMandateText($responseContainer->getMandateText()); |
||
398 | $manageMandateTransfer->setIban($responseContainer->getIban()); |
||
399 | $manageMandateTransfer->setBic($responseContainer->getBic()); |
||
400 | |||
401 | return $manageMandateTransfer; |
||
402 | } |
||
403 | |||
404 | /** |
||
405 | * @param \Generated\Shared\Transfer\PayoneGetFileTransfer $getFileTransfer |
||
406 | * |
||
407 | * @return \Generated\Shared\Transfer\PayoneGetFileTransfer |
||
408 | */ |
||
409 | public function getFile(PayoneGetFileTransfer $getFileTransfer) |
||
410 | { |
||
411 | $responseContainer = new GetFileResponseContainer(); |
||
412 | $paymentEntity = $this->findPaymentByFileReferenceAndCustomerId( |
||
413 | $getFileTransfer->getReference(), |
||
414 | $getFileTransfer->getCustomerId() |
||
415 | ); |
||
416 | |||
417 | if ($paymentEntity) { |
||
418 | /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\DirectDebit $paymentMethodMapper */ |
||
419 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_DIRECT_DEBIT); |
||
420 | $requestContainer = $paymentMethodMapper->mapGetFile($getFileTransfer); |
||
421 | $this->setStandardParameter($requestContainer); |
||
422 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
423 | $responseContainer->init($rawResponse); |
||
424 | } else { |
||
425 | $this->setAccessDeniedError($responseContainer); |
||
426 | } |
||
427 | |||
428 | $getFileTransfer->setRawResponse($responseContainer->getRawResponse()); |
||
429 | $getFileTransfer->setStatus($responseContainer->getStatus()); |
||
430 | $getFileTransfer->setErrorCode($responseContainer->getErrorcode()); |
||
431 | $getFileTransfer->setCustomerErrorMessage($responseContainer->getCustomermessage()); |
||
432 | $getFileTransfer->setInternalErrorMessage($responseContainer->getErrormessage()); |
||
433 | |||
434 | return $getFileTransfer; |
||
435 | } |
||
436 | |||
437 | /** |
||
438 | * @param \Generated\Shared\Transfer\PayoneGetInvoiceTransfer $getInvoiceTransfer |
||
439 | * |
||
440 | * @return \Generated\Shared\Transfer\PayoneGetInvoiceTransfer |
||
441 | */ |
||
442 | public function getInvoice(PayoneGetInvoiceTransfer $getInvoiceTransfer) |
||
443 | { |
||
444 | $responseContainer = new GetInvoiceResponseContainer(); |
||
445 | $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId( |
||
446 | $getInvoiceTransfer->getReference(), |
||
447 | $getInvoiceTransfer->getCustomerId() |
||
448 | ); |
||
449 | |||
450 | if ($paymentEntity) { |
||
451 | /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\Invoice $paymentMethodMapper */ |
||
452 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_INVOICE); |
||
453 | $requestContainer = $paymentMethodMapper->mapGetInvoice($getInvoiceTransfer); |
||
454 | $this->setStandardParameter($requestContainer); |
||
455 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
456 | $responseContainer->init($rawResponse); |
||
457 | } else { |
||
458 | $this->setAccessDeniedError($responseContainer); |
||
459 | } |
||
460 | |||
461 | $getInvoiceTransfer->setRawResponse($responseContainer->getRawResponse()); |
||
462 | $getInvoiceTransfer->setStatus($responseContainer->getStatus()); |
||
463 | $getInvoiceTransfer->setErrorCode($responseContainer->getErrorcode()); |
||
464 | $getInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage()); |
||
465 | |||
466 | return $getInvoiceTransfer; |
||
467 | } |
||
468 | |||
469 | /** |
||
470 | * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer |
||
471 | * |
||
472 | * @return \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer |
||
473 | */ |
||
474 | public function getSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer): PayoneGetSecurityInvoiceTransfer |
||
475 | { |
||
476 | $responseContainer = new GetSecurityInvoiceResponseContainer(); |
||
477 | $paymentEntity = $this->findPaymentByInvoiceTitleAndCustomerId( |
||
478 | $getSecurityInvoiceTransfer->getReference(), |
||
479 | $getSecurityInvoiceTransfer->getCustomerId() |
||
480 | ); |
||
481 | |||
482 | if (!$paymentEntity) { |
||
483 | $this->setAccessDeniedError($responseContainer); |
||
484 | |||
485 | return $getSecurityInvoiceTransfer; |
||
486 | } |
||
487 | |||
488 | /** @var \SprykerEco\Zed\Payone\Business\Payment\MethodMapper\SecurityInvoice $paymentMethodMapper */ |
||
489 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper(PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE); |
||
490 | $requestContainer = $paymentMethodMapper->mapGetSecurityInvoice($getSecurityInvoiceTransfer); |
||
491 | $this->setStandardParameter($requestContainer); |
||
492 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
493 | $responseContainer->init($rawResponse); |
||
494 | |||
495 | $getSecurityInvoiceTransfer->setRawResponse($responseContainer->getRawResponse()); |
||
496 | $getSecurityInvoiceTransfer->setStatus($responseContainer->getStatus()); |
||
497 | $getSecurityInvoiceTransfer->setErrorCode($responseContainer->getErrorcode()); |
||
498 | $getSecurityInvoiceTransfer->setInternalErrorMessage($responseContainer->getErrormessage()); |
||
499 | |||
500 | return $getSecurityInvoiceTransfer; |
||
501 | } |
||
502 | |||
503 | /** |
||
504 | * @param int $transactionId |
||
505 | * |
||
506 | * @return \SprykerEco\Zed\Payone\Business\Api\Response\Container\GetInvoiceResponseContainer |
||
507 | */ |
||
508 | public function getInvoiceTitle($transactionId) |
||
509 | { |
||
510 | return implode('-', [ |
||
511 | PayoneApiConstants::INVOICE_TITLE_PREFIX_INVOICE, |
||
512 | $transactionId, |
||
513 | 0, |
||
514 | ]); |
||
515 | } |
||
516 | |||
517 | /** |
||
518 | * @param \Generated\Shared\Transfer\PayoneRefundTransfer $refundTransfer |
||
519 | * |
||
520 | * @return \Generated\Shared\Transfer\RefundResponseTransfer |
||
521 | */ |
||
522 | public function refundPayment(PayoneRefundTransfer $refundTransfer) |
||
523 | { |
||
524 | $payonePaymentTransfer = $refundTransfer->getPayment(); |
||
525 | |||
526 | $paymentEntity = $this->getPaymentEntity($payonePaymentTransfer->getFkSalesOrder()); |
||
527 | $paymentMethodMapper = $this->getPaymentMethodMapper($paymentEntity); |
||
528 | $requestContainer = $paymentMethodMapper->mapPaymentToRefund($paymentEntity); |
||
529 | $requestContainer->setAmount(0 - $paymentEntity->getSpyPaymentPayoneDetail()->getAmount()); |
||
530 | $requestContainer = $this->prepareOrderItems($refundTransfer->getOrder(), $requestContainer); |
||
531 | $requestContainer = $this->prepareOrderShipment($refundTransfer->getOrder(), $requestContainer); |
||
532 | $requestContainer = $this->prepareOrderDiscount($refundTransfer->getOrder(), $requestContainer); |
||
533 | |||
534 | $this->setStandardParameter($requestContainer); |
||
535 | |||
536 | $apiLogEntity = $this->initializeApiLog($paymentEntity, $requestContainer); |
||
537 | |||
538 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
539 | $responseContainer = new RefundResponseContainer($rawResponse); |
||
540 | |||
541 | $this->updateApiLogAfterRefund($apiLogEntity, $responseContainer); |
||
542 | |||
543 | $responseMapper = new RefundResponseMapper(); |
||
544 | $responseTransfer = $responseMapper->getRefundResponseTransfer($responseContainer); |
||
545 | |||
546 | return $responseTransfer; |
||
547 | } |
||
548 | |||
549 | /** |
||
550 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
551 | * |
||
552 | * @return \Generated\Shared\Transfer\PayonePaymentTransfer |
||
553 | */ |
||
554 | protected function getPayment(OrderTransfer $orderTransfer) |
||
567 | } |
||
568 | |||
569 | /** |
||
570 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
||
571 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer |
||
572 | * |
||
573 | * @return void |
||
574 | */ |
||
575 | protected function updatePaymentAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer) |
||
576 | { |
||
577 | $paymentEntity->setTransactionId($responseContainer->getTxid()); |
||
578 | $paymentEntity->save(); |
||
579 | } |
||
580 | |||
581 | /** |
||
582 | * @param string $transactionId |
||
583 | * |
||
584 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayone |
||
585 | */ |
||
586 | protected function findPaymentByTransactionId($transactionId) |
||
587 | { |
||
588 | return $this->queryContainer->createPaymentByTransactionIdQuery($transactionId)->findOne(); |
||
589 | } |
||
590 | |||
591 | /** |
||
592 | * @param string $invoiceTitle |
||
593 | * @param int $customerId |
||
594 | * |
||
595 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery |
||
596 | */ |
||
597 | protected function findPaymentByInvoiceTitleAndCustomerId($invoiceTitle, $customerId) |
||
598 | { |
||
599 | return $this->queryContainer->createPaymentByInvoiceTitleAndCustomerIdQuery($invoiceTitle, $customerId)->findOne(); |
||
600 | } |
||
601 | |||
602 | /** |
||
603 | * @param string $fileReference |
||
604 | * @param int $customerId |
||
605 | * |
||
606 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneQuery |
||
607 | */ |
||
608 | protected function findPaymentByFileReferenceAndCustomerId($fileReference, $customerId) |
||
611 | } |
||
612 | |||
613 | /** |
||
614 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
||
615 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container |
||
616 | * |
||
617 | * @return \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog |
||
618 | */ |
||
619 | protected function initializeApiLog(SpyPaymentPayone $paymentEntity, AbstractRequestContainer $container) |
||
620 | { |
||
621 | $entity = new SpyPaymentPayoneApiLog(); |
||
622 | $entity->setSpyPaymentPayone($paymentEntity); |
||
623 | $entity->setRequest($container->getRequest()); |
||
624 | $entity->setMode($container->getMode()); |
||
625 | $entity->setMerchantId($container->getMid()); |
||
626 | $entity->setPortalId($container->getPortalid()); |
||
627 | if ($container instanceof CaptureContainer || $container instanceof RefundContainer || $container instanceof DebitContainer) { |
||
628 | $entity->setSequenceNumber($container->getSequenceNumber()); |
||
629 | } |
||
630 | // Logging request data for debug |
||
631 | $entity->setRawRequest(json_encode($container->toArray())); |
||
632 | $entity->save(); |
||
633 | |||
634 | return $entity; |
||
635 | } |
||
636 | |||
637 | /** |
||
638 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity |
||
639 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer |
||
640 | * |
||
641 | * @return void |
||
642 | */ |
||
643 | protected function updateApiLogAfterAuthorization(SpyPaymentPayoneApiLog $apiLogEntity, AuthorizationResponseContainer $responseContainer) |
||
644 | { |
||
645 | $apiLogEntity->setStatus($responseContainer->getStatus()); |
||
646 | $apiLogEntity->setUserId($responseContainer->getUserid()); |
||
647 | $apiLogEntity->setTransactionId($responseContainer->getTxid()); |
||
648 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage()); |
||
649 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage()); |
||
650 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode()); |
||
651 | $apiLogEntity->setRedirectUrl($responseContainer->getRedirecturl()); |
||
652 | $apiLogEntity->setSequenceNumber(0); |
||
653 | |||
654 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray())); |
||
655 | $apiLogEntity->save(); |
||
656 | } |
||
657 | |||
658 | /** |
||
659 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity |
||
660 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\CaptureResponseContainer $responseContainer |
||
661 | * |
||
662 | * @return void |
||
663 | */ |
||
664 | protected function updateApiLogAfterCapture(SpyPaymentPayoneApiLog $apiLogEntity, CaptureResponseContainer $responseContainer) |
||
665 | { |
||
666 | $apiLogEntity->setStatus($responseContainer->getStatus()); |
||
667 | $apiLogEntity->setTransactionId($responseContainer->getTxid()); |
||
668 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage()); |
||
669 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage()); |
||
670 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode()); |
||
671 | |||
672 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray())); |
||
673 | $apiLogEntity->save(); |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity |
||
678 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\DebitResponseContainer $responseContainer |
||
679 | * |
||
680 | * @return void |
||
681 | */ |
||
682 | protected function updateApiLogAfterDebit(SpyPaymentPayoneApiLog $apiLogEntity, DebitResponseContainer $responseContainer) |
||
683 | { |
||
684 | $apiLogEntity->setStatus($responseContainer->getStatus()); |
||
685 | $apiLogEntity->setTransactionId($responseContainer->getTxid()); |
||
686 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage()); |
||
687 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage()); |
||
688 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode()); |
||
689 | |||
690 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray())); |
||
691 | $apiLogEntity->save(); |
||
692 | } |
||
693 | |||
694 | /** |
||
695 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLogEntity |
||
696 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\RefundResponseContainer $responseContainer |
||
697 | * |
||
698 | * @return void |
||
699 | */ |
||
700 | protected function updateApiLogAfterRefund(SpyPaymentPayoneApiLog $apiLogEntity, RefundResponseContainer $responseContainer) |
||
701 | { |
||
702 | $apiLogEntity->setTransactionId($responseContainer->getTxid()); |
||
703 | $apiLogEntity->setStatus($responseContainer->getStatus()); |
||
704 | $apiLogEntity->setErrorMessageInternal($responseContainer->getErrormessage()); |
||
705 | $apiLogEntity->setErrorMessageUser($responseContainer->getCustomermessage()); |
||
706 | $apiLogEntity->setErrorCode($responseContainer->getErrorcode()); |
||
707 | |||
708 | $apiLogEntity->setRawResponse(json_encode($responseContainer->toArray())); |
||
709 | $apiLogEntity->save(); |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container |
||
714 | * |
||
715 | * @return void |
||
716 | */ |
||
717 | protected function setStandardParameter(AbstractRequestContainer $container) |
||
718 | { |
||
719 | $container->setApiVersion(PayoneApiConstants::API_VERSION_3_9); |
||
720 | $container->setEncoding($this->standardParameter->getEncoding()); |
||
721 | $container->setKey($this->hashGenerator->hash($this->standardParameter->getKey())); |
||
722 | $container->setMid($this->standardParameter->getMid()); |
||
723 | $container->setPortalid($this->standardParameter->getPortalId()); |
||
724 | $container->setMode($this->modeDetector->getMode()); |
||
725 | $container->setIntegratorName(PayoneApiConstants::INTEGRATOR_NAME_SPRYKER); |
||
726 | $container->setIntegratorVersion(PayoneApiConstants::INTEGRATOR_VERSION_3_0_0); |
||
727 | $container->setSolutionName(PayoneApiConstants::SOLUTION_NAME_SPRYKER); |
||
728 | $container->setSolutionVersion(PayoneApiConstants::SOLUTION_VERSION_3_0_0); |
||
729 | } |
||
730 | |||
731 | /** |
||
732 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AbstractResponseContainer $container |
||
733 | * |
||
734 | * @return void |
||
735 | */ |
||
736 | protected function setAccessDeniedError(AbstractResponseContainer $container) |
||
737 | { |
||
738 | $container->setStatus(PayoneApiConstants::RESPONSE_TYPE_ERROR); |
||
739 | $container->setErrormessage(static::ERROR_ACCESS_DENIED_MESSAGE); |
||
740 | $container->setCustomermessage(static::ERROR_ACCESS_DENIED_MESSAGE); |
||
741 | } |
||
742 | |||
743 | /** |
||
744 | * @param int $idOrder |
||
745 | * |
||
746 | * @return \Generated\Shared\Transfer\PaymentDetailTransfer |
||
747 | */ |
||
748 | public function getPaymentDetail($idOrder) |
||
749 | { |
||
750 | $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne(); |
||
751 | $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail(); |
||
752 | $paymentDetailTransfer = new PaymentDetailTransfer(); |
||
753 | $paymentDetailTransfer->fromArray($paymentDetailEntity->toArray(), true); |
||
754 | |||
755 | return $paymentDetailTransfer; |
||
756 | } |
||
757 | |||
758 | /** |
||
759 | * Gets payment logs (both api and transaction status) for specific orders in chronological order. |
||
760 | * |
||
761 | * @param \Propel\Runtime\Collection\ObjectCollection|\ArrayObject $orders |
||
762 | * |
||
763 | * @return \Generated\Shared\Transfer\PayonePaymentLogCollectionTransfer |
||
764 | */ |
||
765 | public function getPaymentLogs($orders) |
||
766 | { |
||
767 | $apiLogs = $this->queryContainer->createApiLogsByOrderIds($orders)->find()->getData(); |
||
768 | |||
769 | $transactionStatusLogs = $this->queryContainer->createTransactionStatusLogsByOrderIds($orders)->find()->getData(); |
||
770 | |||
771 | $logs = []; |
||
772 | /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneApiLog $apiLog */ |
||
773 | foreach ($apiLogs as $apiLog) { |
||
774 | $key = $apiLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 'a' . $apiLog->getIdPaymentPayoneApiLog(); |
||
775 | $payonePaymentLogTransfer = new PayonePaymentLogTransfer(); |
||
776 | $payonePaymentLogTransfer->fromArray($apiLog->toArray(), true); |
||
777 | $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_API_LOG); |
||
778 | $logs[$key] = $payonePaymentLogTransfer; |
||
779 | } |
||
780 | /** @var \Orm\Zed\Payone\Persistence\SpyPaymentPayoneTransactionStatusLog $transactionStatusLog */ |
||
781 | foreach ($transactionStatusLogs as $transactionStatusLog) { |
||
782 | $key = $transactionStatusLog->getCreatedAt()->format('Y-m-d\TH:i:s\Z') . 't' . $transactionStatusLog->getIdPaymentPayoneTransactionStatusLog(); |
||
783 | $payonePaymentLogTransfer = new PayonePaymentLogTransfer(); |
||
784 | $payonePaymentLogTransfer->fromArray($transactionStatusLog->toArray(), true); |
||
785 | $payonePaymentLogTransfer->setLogType(self::LOG_TYPE_TRANSACTION_STATUS_LOG); |
||
786 | $logs[$key] = $payonePaymentLogTransfer; |
||
787 | } |
||
788 | |||
789 | ksort($logs); |
||
790 | |||
791 | $payonePaymentLogCollectionTransfer = new PayonePaymentLogCollectionTransfer(); |
||
792 | |||
793 | foreach ($logs as $log) { |
||
794 | $payonePaymentLogCollectionTransfer->addPaymentLogs($log); |
||
795 | } |
||
796 | |||
797 | return $payonePaymentLogCollectionTransfer; |
||
798 | } |
||
799 | |||
800 | /** |
||
801 | * @param \Generated\Shared\Transfer\PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer |
||
802 | * |
||
803 | * @return array |
||
804 | */ |
||
805 | public function getCreditCardCheckRequestData(PayoneCreditCardCheckRequestDataTransfer $creditCardCheckRequestDataTransfer) |
||
806 | { |
||
807 | $this->standardParameter->fromArray($creditCardCheckRequestDataTransfer->toArray(), true); |
||
808 | |||
809 | $creditCardCheck = new CreditCardCheck($this->standardParameter, $this->hashGenerator, $this->modeDetector); |
||
810 | |||
811 | $data = $creditCardCheck->mapCreditCardCheckData(); |
||
812 | |||
813 | return $data->toArray(); |
||
814 | } |
||
815 | |||
816 | /** |
||
817 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
818 | * |
||
819 | * @return bool |
||
820 | */ |
||
821 | public function isRefundPossible(OrderTransfer $orderTransfer) |
||
822 | { |
||
823 | $paymentTransfer = $this->getPayment($orderTransfer); |
||
824 | |||
825 | if (!$this->isPaymentDataRequired($orderTransfer)) { |
||
826 | return true; |
||
827 | } |
||
828 | |||
829 | $paymentDetailTransfer = $paymentTransfer->getPaymentDetail(); |
||
830 | |||
831 | return $paymentDetailTransfer->getBic() && $paymentDetailTransfer->getIban(); |
||
832 | } |
||
833 | |||
834 | /** |
||
835 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
836 | * |
||
837 | * @return bool |
||
838 | */ |
||
839 | public function isPaymentDataRequired(OrderTransfer $orderTransfer) |
||
840 | { |
||
841 | $paymentTransfer = $this->getPayment($orderTransfer); |
||
842 | |||
843 | // Return early if we don't need the iban or bic data |
||
844 | $paymentMethod = $paymentTransfer->getPaymentMethod(); |
||
845 | $whiteList = [ |
||
846 | PayoneApiConstants::PAYMENT_METHOD_E_WALLET, |
||
847 | PayoneApiConstants::PAYMENT_METHOD_CREDITCARD_PSEUDO, |
||
848 | PayoneApiConstants::PAYMENT_METHOD_ONLINE_BANK_TRANSFER, |
||
849 | ]; |
||
850 | |||
851 | if (in_array($paymentMethod, $whiteList)) { |
||
852 | return false; |
||
853 | } |
||
854 | |||
855 | return true; |
||
856 | } |
||
857 | |||
858 | /** |
||
859 | * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
||
860 | * @param \Generated\Shared\Transfer\CheckoutResponseTransfer $checkoutResponse |
||
861 | * |
||
862 | * @return \Generated\Shared\Transfer\CheckoutResponseTransfer |
||
863 | */ |
||
864 | public function postSaveHook(QuoteTransfer $quoteTransfer, CheckoutResponseTransfer $checkoutResponse) |
||
865 | { |
||
866 | $apiLogsQuery = $this->queryContainer->createLastApiLogsByOrderId($quoteTransfer->getPayment()->getPayone()->getFkSalesOrder()); |
||
867 | $apiLog = $apiLogsQuery->findOne(); |
||
868 | |||
869 | if ($apiLog) { |
||
870 | $redirectUrl = $apiLog->getRedirectUrl(); |
||
871 | |||
872 | if ($redirectUrl !== null) { |
||
873 | $checkoutResponse->setIsExternalRedirect(true); |
||
874 | $checkoutResponse->setRedirectUrl($redirectUrl); |
||
875 | } |
||
876 | |||
877 | $errorCode = $apiLog->getErrorCode(); |
||
878 | |||
879 | if ($errorCode) { |
||
880 | $error = new CheckoutErrorTransfer(); |
||
881 | $error->setMessage($apiLog->getErrorMessageUser()); |
||
882 | $error->setErrorCode($errorCode); |
||
883 | $checkoutResponse->addError($error); |
||
884 | $checkoutResponse->setIsSuccess(false); |
||
885 | } |
||
886 | } |
||
887 | |||
888 | return $checkoutResponse; |
||
889 | } |
||
890 | |||
891 | /** |
||
892 | * @param \Generated\Shared\Transfer\PaymentDetailTransfer $paymentDataTransfer |
||
893 | * @param int $idOrder |
||
894 | * |
||
895 | * @return void |
||
896 | */ |
||
897 | public function updatePaymentDetail(PaymentDetailTransfer $paymentDataTransfer, $idOrder) |
||
898 | { |
||
899 | $paymentEntity = $this->queryContainer->createPaymentByOrderId($idOrder)->findOne(); |
||
900 | $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail(); |
||
901 | |||
902 | $paymentDetailEntity->fromArray($paymentDataTransfer->toArray()); |
||
903 | |||
904 | $paymentDetailEntity->save(); |
||
905 | } |
||
906 | |||
907 | /** |
||
908 | * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
||
909 | * @param \SprykerEco\Zed\Payone\Business\Api\Response\Container\AuthorizationResponseContainer $responseContainer |
||
910 | * |
||
911 | * @return void |
||
912 | */ |
||
913 | protected function updatePaymentDetailAfterAuthorization(SpyPaymentPayone $paymentEntity, AuthorizationResponseContainer $responseContainer) |
||
914 | { |
||
915 | $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail(); |
||
916 | |||
917 | $paymentDetailEntity->setClearingBankAccountHolder($responseContainer->getClearingBankaccountholder()); |
||
918 | $paymentDetailEntity->setClearingBankCountry($responseContainer->getClearingBankcountry()); |
||
919 | $paymentDetailEntity->setClearingBankAccount($responseContainer->getClearingBankaccount()); |
||
920 | $paymentDetailEntity->setClearingBankCode($responseContainer->getClearingBankcode()); |
||
921 | $paymentDetailEntity->setClearingBankIban($responseContainer->getClearingBankiban()); |
||
922 | $paymentDetailEntity->setClearingBankBic($responseContainer->getClearingBankbic()); |
||
923 | $paymentDetailEntity->setClearingBankCity($responseContainer->getClearingBankcity()); |
||
924 | $paymentDetailEntity->setClearingBankName($responseContainer->getClearingBankname()); |
||
925 | |||
926 | if ($responseContainer->getMandateIdentification()) { |
||
927 | $paymentDetailEntity->setMandateIdentification($responseContainer->getMandateIdentification()); |
||
928 | } |
||
929 | |||
930 | if ($paymentEntity->getPaymentMethod() == PayoneApiConstants::PAYMENT_METHOD_INVOICE) { |
||
931 | $paymentDetailEntity->setInvoiceTitle($this->getInvoiceTitle($paymentEntity->getTransactionId())); |
||
932 | } |
||
933 | |||
934 | $paymentDetailEntity->save(); |
||
935 | } |
||
936 | |||
937 | /** |
||
938 | * @param \Generated\Shared\Transfer\PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer |
||
939 | * |
||
940 | * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer |
||
941 | */ |
||
942 | public function initPaypalExpressCheckout(PayoneInitPaypalExpressCheckoutRequestTransfer $requestTransfer) |
||
943 | { |
||
944 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper( |
||
945 | PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT |
||
946 | ); |
||
947 | $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer(); |
||
948 | $baseGenericPaymentContainer->getPaydata()->setAction(PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_SET_ACTION); |
||
949 | $requestContainer = $paymentMethodMapper->mapRequestTransferToGenericPayment( |
||
950 | $baseGenericPaymentContainer, |
||
951 | $requestTransfer |
||
952 | ); |
||
953 | $responseTransfer = $this->performGenericRequest($requestContainer); |
||
954 | |||
955 | return $responseTransfer; |
||
956 | } |
||
957 | |||
958 | /** |
||
959 | * @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
||
960 | * |
||
961 | * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer |
||
962 | */ |
||
963 | public function getPaypalExpressCheckoutDetails(QuoteTransfer $quoteTransfer) |
||
964 | { |
||
965 | $paymentMethodMapper = $this->getRegisteredPaymentMethodMapper( |
||
966 | PayoneApiConstants::PAYMENT_METHOD_PAYPAL_EXPRESS_CHECKOUT |
||
967 | ); |
||
968 | |||
969 | $baseGenericPaymentContainer = $paymentMethodMapper->createBaseGenericPaymentContainer(); |
||
970 | $baseGenericPaymentContainer->getPaydata()->setAction( |
||
971 | PayoneApiConstants::PAYONE_EXPRESS_CHECKOUT_GET_DETAILS_ACTION |
||
972 | ); |
||
973 | $requestContainer = $paymentMethodMapper->mapQuoteTransferToGenericPayment( |
||
974 | $baseGenericPaymentContainer, |
||
975 | $quoteTransfer |
||
976 | ); |
||
977 | $responseTransfer = $this->performGenericRequest($requestContainer); |
||
978 | |||
979 | return $responseTransfer; |
||
980 | } |
||
981 | |||
982 | /** |
||
983 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\GenericPaymentContainer $requestContainer |
||
984 | * |
||
985 | * @return \Generated\Shared\Transfer\PayonePaypalExpressCheckoutGenericPaymentResponseTransfer |
||
986 | */ |
||
987 | protected function performGenericRequest(GenericPaymentContainer $requestContainer) |
||
988 | { |
||
989 | $this->setStandardParameter($requestContainer); |
||
990 | |||
991 | $rawResponse = $this->executionAdapter->sendRequest($requestContainer); |
||
992 | $responseContainer = new GenericPaymentResponseContainer($rawResponse); |
||
993 | $responseTransfer = new PayonePaypalExpressCheckoutGenericPaymentResponseTransfer(); |
||
994 | $responseTransfer->setRedirectUrl($responseContainer->getRedirectUrl()); |
||
995 | $responseTransfer->setWorkOrderId($responseContainer->getWorkOrderId()); |
||
996 | $responseTransfer->setRawResponse(json_encode($rawResponse)); |
||
997 | $responseTransfer->setStatus($responseContainer->getStatus()); |
||
998 | $responseTransfer->setCustomerMessage($responseContainer->getCustomermessage()); |
||
999 | $responseTransfer->setErrorMessage($responseContainer->getErrormessage()); |
||
1000 | $responseTransfer->setErrorCode($responseContainer->getErrorcode()); |
||
1001 | $responseTransfer->setEmail($responseContainer->getEmail()); |
||
1002 | $responseTransfer->setShippingFirstName($responseContainer->getShippingFirstname()); |
||
1003 | $responseTransfer->setShippingLastName($responseContainer->getShippingLastname()); |
||
1004 | $responseTransfer->setShippingCompany($responseContainer->getShippingCompany()); |
||
1005 | $responseTransfer->setShippingCountry($responseContainer->getShippingCountry()); |
||
1006 | $responseTransfer->setShippingState($responseContainer->getShippingState()); |
||
1007 | $responseTransfer->setShippingStreet($responseContainer->getShippingStreet()); |
||
1008 | $responseTransfer->setShippingAddressAdition($responseContainer->getShippingAddressaddition()); |
||
1009 | $responseTransfer->setShippingCity($responseContainer->getShippingCity()); |
||
1010 | $responseTransfer->setShippingZip($responseContainer->getShippingZip()); |
||
1011 | |||
1012 | return $responseTransfer; |
||
1013 | } |
||
1014 | |||
1015 | /** |
||
1016 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
1017 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container |
||
1018 | * |
||
1019 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer |
||
1020 | */ |
||
1021 | protected function prepareOrderItems(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer |
||
1022 | { |
||
1023 | $arrayIt = []; |
||
1024 | $arrayId = []; |
||
1025 | $arrayPr = []; |
||
1026 | $arrayNo = []; |
||
1027 | $arrayDe = []; |
||
1028 | $arrayVa = []; |
||
1029 | |||
1030 | $key = 1; |
||
1031 | |||
1032 | foreach ($orderTransfer->getItems() as $itemTransfer) { |
||
1033 | $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS; |
||
1034 | $arrayId[$key] = $itemTransfer->getSku(); |
||
1035 | $arrayPr[$key] = $itemTransfer->getUnitGrossPrice(); |
||
1036 | $arrayNo[$key] = $itemTransfer->getQuantity(); |
||
1037 | $arrayDe[$key] = $itemTransfer->getName(); |
||
1038 | $arrayVa[$key] = (int)$itemTransfer->getTaxRate(); |
||
1039 | $key++; |
||
1040 | } |
||
1041 | |||
1042 | $container->setIt($arrayIt); |
||
1043 | $container->setId($arrayId); |
||
1044 | $container->setPr($arrayPr); |
||
1045 | $container->setNo($arrayNo); |
||
1046 | $container->setDe($arrayDe); |
||
1047 | $container->setVa($arrayVa); |
||
1048 | |||
1049 | return $container; |
||
1050 | } |
||
1051 | |||
1052 | /** |
||
1053 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
1054 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container |
||
1055 | * |
||
1056 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer |
||
1057 | */ |
||
1058 | protected function prepareOrderShipment(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer |
||
1059 | { |
||
1060 | $arrayIt = $container->getIt() ?? []; |
||
1061 | $arrayId = $container->getId() ?? []; |
||
1062 | $arrayPr = $container->getPr() ?? []; |
||
1063 | $arrayNo = $container->getNo() ?? []; |
||
1064 | $arrayDe = $container->getDe() ?? []; |
||
1065 | $arrayVa = $container->getVa() ?? []; |
||
1066 | |||
1067 | $key = count($arrayId) + 1; |
||
1068 | $expenses = $orderTransfer->getExpenses(); |
||
1069 | |||
1070 | $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT; |
||
1071 | $arrayId[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT; |
||
1072 | $arrayPr[$key] = $this->getDeliveryCosts($expenses); |
||
1073 | $arrayNo[$key] = 1; |
||
1074 | $arrayDe[$key] = 'Shipment'; |
||
1075 | |||
1076 | $container->setIt($arrayIt); |
||
1077 | $container->setId($arrayId); |
||
1078 | $container->setPr($arrayPr); |
||
1079 | $container->setNo($arrayNo); |
||
1080 | $container->setDe($arrayDe); |
||
1081 | $container->setVa($arrayVa); |
||
1082 | |||
1083 | return $container; |
||
1084 | } |
||
1085 | |||
1086 | /** |
||
1087 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
1088 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container |
||
1089 | * |
||
1090 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer |
||
1091 | */ |
||
1092 | protected function prepareOrderDiscount(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer |
||
1117 | } |
||
1118 | |||
1119 | /** |
||
1120 | * @param \ArrayObject $expenses |
||
1121 | * |
||
1122 | * @return string |
||
1123 | */ |
||
1124 | protected function getDeliveryCosts(ArrayObject $expenses): string |
||
1125 | { |
||
1126 | foreach ($expenses as $expense) { |
||
1127 | if ($expense->getType() === ShipmentConstants::SHIPMENT_EXPENSE_TYPE) { |
||
1128 | return $expense->getSumGrossPrice(); |
||
1129 | } |
||
1130 | } |
||
1131 | return 0; |
||
1132 | } |
||
1133 | |||
1134 | /** |
||
1135 | * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
||
1136 | * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer $container |
||
1137 | * |
||
1138 | * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer |
||
1139 | */ |
||
1140 | protected function prepareOrderHandling(OrderTransfer $orderTransfer, AbstractRequestContainer $container): AbstractRequestContainer |
||
1170 | } |
||
1171 | } |
||
1172 |
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