Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
[change] (MAGE2-311) Add measures to avoid unexpected errors due fore…
Browse files Browse the repository at this point in the history
…ign payment type.
  • Loading branch information
sixer1182 committed May 8, 2020
1 parent eca525b commit 426e244
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Controller/Index/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public function execute()
}

// Check whether order was loaded correctly
if($order === null || $order->isEmpty()) {
$hasHeidelpayPayment = $this->orderHelper->hasHeidelpayPayment($order);
if($order === null || $order->isEmpty() || $order->isCanceled() || !$hasHeidelpayPayment) {
$this->_logger->error(
'Heidelpay - Redirect: Cannot receive order. Order creation might have failed.'
);
Expand Down
23 changes: 21 additions & 2 deletions Helper/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Heidelpay\Gateway\Helper;


use Heidelpay\Gateway\PaymentMethods\HeidelpayAbstractPaymentMethod;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Data\Collection;
Expand Down Expand Up @@ -145,6 +145,25 @@ protected function fetchOrdersByQuoteId($quoteId): Collection
}


return $orderList->getFirstItem();
/**
* Returns true if the payment of the order is part of this payment module.
*
* @param MagentoOrder $order
* @return bool
*/
public function hasHeidelpayPayment(MagentoOrder $order): bool
{
$payment = $order->getPayment();
$returnVal = true;

if ($payment === null) {
$this->_logger->error('heidelpay - Empty payment.');
$returnVal = false;
} elseif (!$payment->getMethodInstance() instanceof HeidelpayAbstractPaymentMethod) {
$this->_logger->error('heidelpay - Not heidelpay payment.');
$returnVal = false;
}

return $returnVal;
}
}

0 comments on commit 426e244

Please sign in to comment.