From 3be9b4b0dca8aef66e713571de8c96097b61f16d Mon Sep 17 00:00:00 2001 From: kGablo Date: Fri, 12 Jan 2024 15:12:51 +0100 Subject: [PATCH] Payment limit --- Model/MethodListPlugin.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Model/MethodListPlugin.php b/Model/MethodListPlugin.php index 7c9e412..ac7a93f 100644 --- a/Model/MethodListPlugin.php +++ b/Model/MethodListPlugin.php @@ -6,6 +6,7 @@ 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; @@ -27,12 +28,20 @@ class MethodListPlugin /** @var StoreManagerInterface */ private $storeManager; - public function __construct(Data $data, ScopeConfigInterface $scopeConfig, OnsiteChannels $onsiteChannels, StoreManagerInterface $storeManager) + /** @var Tpay */ + private $tpay; + + /** @var CartInterface */ + private $cartInterface; + + public function __construct(Data $data, ScopeConfigInterface $scopeConfig, OnsiteChannels $onsiteChannels, StoreManagerInterface $storeManager, Tpay $tpay, CartInterface $cartInterface) { $this->data = $data; $this->scopeConfig = $scopeConfig; $this->onsiteChannels = $onsiteChannels; $this->storeManager = $storeManager; + $this->tpay = $tpay; + $this->cartInterface = $cartInterface; } public function afterGetAvailableMethods(MethodList $compiled, $result) @@ -40,6 +49,10 @@ 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)) { + return $result; + } + $result[] = $this->getMethodInstance('tpay.com - Płatność kartą', 'tpaycom_magento2basic_cards'); $result = $this->filterResult($result);