diff --git a/Model/MethodListPlugin.php b/Model/MethodListPlugin.php index fcad9ed..bbdf8a9 100644 --- a/Model/MethodListPlugin.php +++ b/Model/MethodListPlugin.php @@ -72,12 +72,10 @@ public function afterGetAvailableMethods(MethodList $compiled, $result) return $result; } - $onsiteChannels = $this->scopeConfig->getValue(self::CONFIG_PATH, ScopeInterface::SCOPE_STORE); - $channelList = $onsiteChannels ? explode(',', $onsiteChannels) : []; - $channels = $this->transactions->channels(); - $conutryId = $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId(); + $countryId = $this->checkoutSession->getQuote()->getBillingAddress()->getCountryId(); + [$channelList, $channels] = $this->getChannels(); - if ($conutryId && $this->constraintValidator->isClientCountryValid($this->tpayConfig->isAllowSpecific(), $conutryId, $this->tpayConfig->getSpecificCountry())) { + if ($countryId && $this->constraintValidator->isClientCountryValid($this->tpayConfig->isAllowSpecific(), $countryId, $this->tpayConfig->getSpecificCountry())) { return []; } @@ -146,4 +144,18 @@ private function filterTransaction(array $result): array return 'Tpay_Magento2' !== $method->getCode(); }); } + + private function getChannels(): array + { + $onsiteChannels = $this->scopeConfig->getValue(self::CONFIG_PATH, ScopeInterface::SCOPE_STORE); + $channelList = $onsiteChannels ? explode(',', $onsiteChannels) : []; + $channels = $this->transactions->channels(); + + $flippedChannels = array_flip(array_keys($channels)); + $channelList = array_filter($channelList, function ($value) use ($flippedChannels) { + return isset($flippedChannels[$value]); + }); + + return [$channelList, $channels]; + } }