Skip to content

Commit

Permalink
Payment limit fix
Browse files Browse the repository at this point in the history
  • Loading branch information
krzGablo committed Jan 12, 2024
1 parent 3be9b4b commit f2a25ad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Model/MethodListPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace tpaycom\magento2basic\Model;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Payment\Helper\Data;
use Magento\Payment\Model\MethodInterface;
use Magento\Payment\Model\MethodList;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use tpaycom\magento2basic\Api\TpayInterface;
Expand All @@ -31,25 +31,25 @@ class MethodListPlugin
/** @var Tpay */
private $tpay;

/** @var CartInterface */
private $cartInterface;
/** @var Session */
private $checkoutSession;

public function __construct(Data $data, ScopeConfigInterface $scopeConfig, OnsiteChannels $onsiteChannels, StoreManagerInterface $storeManager, Tpay $tpay, CartInterface $cartInterface)
public function __construct(Data $data, ScopeConfigInterface $scopeConfig, OnsiteChannels $onsiteChannels, StoreManagerInterface $storeManager, Tpay $tpay, Session $checkoutSession)
{
$this->data = $data;
$this->scopeConfig = $scopeConfig;
$this->onsiteChannels = $onsiteChannels;
$this->storeManager = $storeManager;
$this->tpay = $tpay;
$this->cartInterface = $cartInterface;
$this->checkoutSession = $checkoutSession;
}

public function afterGetAvailableMethods(MethodList $compiled, $result)
{
$onsiteChannels = $this->scopeConfig->getValue(self::CONFIG_PATH, ScopeInterface::SCOPE_STORE);
$channels = $onsiteChannels ? explode(',', $onsiteChannels) : [];

if (!$this->tpay->isAvailable($this->cartInterface)) {
if (!$this->tpay->isCartValid((float)$this->checkoutSession->getQuote()->getGrandTotal())) {
return $result;
}

Expand Down
16 changes: 16 additions & 0 deletions Model/Tpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,22 @@ public function getClientId(): ?string
return $this->getConfigData('client_id');
}

public function isCartValid(?float $grandTotal = null): bool
{
$minAmount = $this->getConfigData('min_order_total');
$maxAmount = $this->getConfigData('max_order_total');

if ($grandTotal && ($grandTotal < $minAmount || ($maxAmount && $grandTotal > $maxAmount))) {
return false;
}

if (!$this->getMerchantId()) {
return false;
}

return !is_null($grandTotal);
}

/** Check that the BLIK should be available for order/quote amount */
protected function checkBlikAmount(): bool
{
Expand Down

0 comments on commit f2a25ad

Please sign in to comment.