Skip to content

Commit

Permalink
BP-2132 - BP-2813 - code review
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianTuriacArnia committed Aug 16, 2023
1 parent 9296707 commit f73ec9e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
7 changes: 5 additions & 2 deletions Model/Push/PushProcessorsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.')
);
Expand Down
61 changes: 29 additions & 32 deletions Model/Push/RefundProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -74,7 +72,6 @@ public function __construct(
parent::__construct($orderRequestService, $pushTransactionType, $logging, $helper, $transaction,
$groupTransaction, $buckarooStatusCode,$orderStatusFactory, $configAccount);
$this->refundPush = $refundPush;

}

/**
Expand All @@ -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);
Expand All @@ -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;
}
}

0 comments on commit f73ec9e

Please sign in to comment.