diff --git a/Model/Config/Source/Available/Available.php b/Model/Config/Source/Available/Available.php index f75d825b..d4dc5d34 100644 --- a/Model/Config/Source/Available/Available.php +++ b/Model/Config/Source/Available/Available.php @@ -40,17 +40,24 @@ abstract class Available implements ArrayInterface */ protected $_config; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $_storeManager; + public function __construct( Config $config, RequestInterface $request, ScopeConfigInterface $scopeConfig, - PaymentMethodFactory $paymentMethodFactory + PaymentMethodFactory $paymentMethodFactory, + \Magento\Store\Model\StoreManagerInterface $storeManager ) { $this->_config = $config; $this->_request = $request; $this->_scopeConfig = $scopeConfig; $this->_paymentmethodFactory = $paymentMethodFactory; + $this->_storeManager = $storeManager; } /** @@ -76,6 +83,11 @@ public function toOptionArray() */ public function toArray() { + $storeId = $this->_request->getParam('store'); + if ($storeId) { + $store = $this->_storeManager->getStore($storeId); + $this->_config->setStore($store); + } $configured = $this->_config->configureSDK(); if (!$configured) { return [0 => __('Enter your API-token and ServiceId first')]; @@ -122,6 +134,11 @@ protected function getConfigValue($path) protected function _isAvailable() { + $storeId = $this->_request->getParam('store'); + if ($storeId) { + $store = $this->_storeManager->getStore($storeId); + $this->_config->setStore($store); + } $configured = $this->_config->configureSDK(); if ($configured) { $paymentOptionId = $this->getPaymentOptionId(); diff --git a/Model/Paymentmethod/Ideal.php b/Model/Paymentmethod/Ideal.php index 1896dfba..36ec0d2b 100644 --- a/Model/Paymentmethod/Ideal.php +++ b/Model/Paymentmethod/Ideal.php @@ -39,15 +39,20 @@ public function assignData(\Magento\Framework\DataObject $data) public function getBanks() { $show_banks = $this->_scopeConfig->getValue('payment/' . $this->_code . '/bank_selection', 'store'); - if (!$show_banks) return []; + if (!$show_banks) { + return []; + } $cache = $this->getCache(); - $cacheName = 'paynl_banks_' . $this->getPaymentOptionId(); + $store = $this->storeManager->getStore(); + $storeId = $store->getId(); + $cacheName = 'paynl_banks_' . $this->getPaymentOptionId() . '_' . $storeId; $banksJson = $cache->load($cacheName); if ($banksJson) { $banks = json_decode($banksJson); } else { + $this->paynlConfig->setStore($store); $this->paynlConfig->configureSDK(); $banks = \Paynl\Paymentmethods::getBanks($this->getPaymentOptionId()); @@ -72,4 +77,4 @@ private function getCache() $cache = $om->get('Magento\Framework\App\CacheInterface'); return $cache; } -} \ No newline at end of file +} diff --git a/Model/Paymentmethod/Instore.php b/Model/Paymentmethod/Instore.php index 49467700..4f620ec0 100644 --- a/Model/Paymentmethod/Instore.php +++ b/Model/Paymentmethod/Instore.php @@ -80,13 +80,16 @@ public function assignData(\Magento\Framework\DataObject $data) public function getBanks() { $cache = $this->getCache(); - $cacheName = 'paynl_terminals_' . $this->getPaymentOptionId(); + $store = $this->storeManager->getStore(); + $storeId = $store->getId(); + $cacheName = 'paynl_terminals_' . $this->getPaymentOptionId() . '_' . $storeId; $banksJson = $cache->load($cacheName); if ($banksJson) { $banks = json_decode($banksJson); } else { $banks = []; try { + $this->paynlConfig->setStore($store); $this->paynlConfig->configureSDK(); $terminals = \Paynl\Instore::getAllTerminals(); diff --git a/Model/Paymentmethod/PaymentMethod.php b/Model/Paymentmethod/PaymentMethod.php index 6c90f0d7..f8da94bb 100644 --- a/Model/Paymentmethod/PaymentMethod.php +++ b/Model/Paymentmethod/PaymentMethod.php @@ -67,6 +67,11 @@ abstract class PaymentMethod extends AbstractMethod */ protected $messageManager; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + protected $storeManager; + public function __construct( Context $context, Registry $registry, @@ -95,6 +100,7 @@ public function __construct( $this->orderRepository = $orderRepository; $this->orderConfig = $orderConfig; $this->logger = $objectManager->get(\Psr\Log\LoggerInterface::class); + $this->storeManager = $objectManager->create('\Magento\Store\Model\StoreManagerInterface'); } protected function getState($status) @@ -211,6 +217,8 @@ public function initialize($paymentAction, $stateObject) public function refund(InfoInterface $payment, $amount) { + $order = $payment->getOrder(); + $this->paynlConfig->setStore($order->getStore()); $this->paynlConfig->configureSDK(); $transactionId = $payment->getParentTransactionId(); @@ -237,11 +245,11 @@ public function refund(InfoInterface $payment, $amount) public function capture(InfoInterface $payment, $amount) { - $this->paynlConfig->configureSDK(); - $payment->setAdditionalInformation('manual_capture', 'true'); $order = $payment->getOrder(); $order->save(); + $this->paynlConfig->setStore($order->getStore()); + $this->paynlConfig->configureSDK(); $transactionId = $payment->getParentTransactionId(); @@ -252,6 +260,8 @@ public function capture(InfoInterface $payment, $amount) public function void(InfoInterface $payment) { + $order = $payment->getOrder(); + $this->paynlConfig->setStore($order->getStore()); $this->paynlConfig->configureSDK(); $transactionId = $payment->getParentTransactionId();