From f73ec9e6ccc94e6c7f4086323d3b1df95e0349c6 Mon Sep 17 00:00:00 2001 From: Lucian Turiac Date: Wed, 16 Aug 2023 13:36:12 +0300 Subject: [PATCH] BP-2132 - BP-2813 - code review --- Model/Push/PushProcessorsFactory.php | 7 +++- Model/Push/RefundProcessor.php | 61 +++++++++++++--------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Model/Push/PushProcessorsFactory.php b/Model/Push/PushProcessorsFactory.php index cb3f0778..c5f03b23 100644 --- a/Model/Push/PushProcessorsFactory.php +++ b/Model/Push/PushProcessorsFactory.php @@ -108,8 +108,9 @@ private function getPushProcessorClass(?PushTransactionType $pushTransactionType // Set Push Processor by Payment Method $paymentMethod = $pushTransactionType->getPaymentMethod(); $pushProcessorClass = $this->pushProcessors[$paymentMethod] ?? $pushProcessorClass; + if ($pushTransactionType->isFromPayPerEmail()) { - return $this->pushProcessors['group_transaction']; + return $this->pushProcessors['payperemail']; } // Check if is Group Transaction Push @@ -121,7 +122,9 @@ private function getPushProcessorClass(?PushTransactionType $pushTransactionType $pushType = $pushTransactionType->getPushType(); if ($pushType == PushTransactionType::BUCK_PUSH_TYPE_INVOICE) { return $this->pushProcessors['credit_managment']; - } elseif ($pushType == PushTransactionType::BUCK_PUSH_TYPE_INVOICE_INCOMPLETE) { + } + + if ($pushType == PushTransactionType::BUCK_PUSH_TYPE_INVOICE_INCOMPLETE) { throw new BuckarooException( __('Skipped handling this invoice push because it is too soon.') ); diff --git a/Model/Push/RefundProcessor.php b/Model/Push/RefundProcessor.php index 73292f1f..ccf34a2a 100644 --- a/Model/Push/RefundProcessor.php +++ b/Model/Push/RefundProcessor.php @@ -21,7 +21,6 @@ namespace Buckaroo\Magento2\Model\Push; -use Buckaroo\Magento2\Api\PushProcessorInterface; use Buckaroo\Magento2\Api\PushRequestInterface; use Buckaroo\Magento2\Exception as BuckarooException; use Buckaroo\Magento2\Helper\Data; @@ -31,7 +30,6 @@ use Buckaroo\Magento2\Model\ConfigProvider\Account; use Buckaroo\Magento2\Model\OrderStatusFactory; use Buckaroo\Magento2\Model\Refund\Push as RefundPush; -use Buckaroo\Magento2\Model\Validator\Push as ValidatorPush; use Buckaroo\Magento2\Service\Push\OrderRequestService; use Magento\Sales\Api\Data\TransactionInterface; @@ -74,7 +72,6 @@ public function __construct( parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction, $groupTransaction, $buckarooStatusCode,$orderStatusFactory, $configAccount); $this->refundPush = $refundPush; - } /** @@ -91,22 +88,20 @@ public function processPush(PushRequestInterface $pushRequest): bool return true; } - if ($this->pushTransactionType->getStatusKey() !== 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS' - && !$this->order->hasInvoices() - ) { - throw new BuckarooException( - __('Refund failed ! Status : %1 and the order does not contain an invoice', - $this->pushTransactionType->getStatusKey()) - ); - } elseif ($this->pushTransactionType->getStatusKey() !== 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS' - && $this->order->hasInvoices() - ) { - //don't proceed failed refund push - $this->logging->addDebug(__METHOD__ . '|10|'); - $this->orderRequestService->setOrderNotificationNote( - __('Push notification for refund has no success status, ignoring.') - ); - return true; + if ($this->pushTransactionType->getStatusKey() !== 'BUCKAROO_MAGENTO2_STATUSCODE_SUCCESS') { + if ($this->order->hasInvoices()) { + //don't proceed failed refund push + $this->logging->addDebug(__METHOD__ . '|10|'); + $this->orderRequestService->setOrderNotificationNote( + __('Push notification for refund has no success status, ignoring.') + ); + return true; + } else { + throw new BuckarooException( + __('Refund failed ! Status : %1 and the order does not contain an invoice', + $this->pushTransactionType->getStatusKey()) + ); + } } return $this->refundPush->receiveRefundPush($this->pushRequest, true, $this->order); @@ -121,22 +116,24 @@ public function processPush(PushRequestInterface $pushRequest): bool */ private function skipPendingRefundPush(PushRequestInterface $pushRequest): bool { - if ($pushRequest->hasAdditionalInformation('initiated_by_magento', 1) - && $pushRequest->hasAdditionalInformation('service_action_from_magento', ['refund']) + if (!$pushRequest->hasAdditionalInformation('initiated_by_magento', 1) + || !$pushRequest->hasAdditionalInformation('service_action_from_magento', ['refund']) ) { - if ($pushRequest->hasPostData('statuscode', BuckarooStatusCode::SUCCESS) - && !empty($pushRequest->getRelatedtransactionRefund()) - && $this->receivePushCheckDuplicates( - BuckarooStatusCode::PENDING_APPROVAL, - $pushRequest->getRelatedtransactionRefund() - )) { - $this->logging->addDebug(__METHOD__ . '|4|'); - return false; - } $this->logging->addDebug(__METHOD__ . '|5|'); - return true; + return false; } - return false; + if ($pushRequest->hasPostData('statuscode', BuckarooStatusCode::SUCCESS) + && !empty($pushRequest->getRelatedtransactionRefund()) + && $this->receivePushCheckDuplicates( + BuckarooStatusCode::PENDING_APPROVAL, + $pushRequest->getRelatedtransactionRefund() + )) { + $this->logging->addDebug(__METHOD__ . '|4|'); + return false; + } + + + return true; } } \ No newline at end of file