From 7851788f2871ed84603bf2e639c490f533b5ee6c Mon Sep 17 00:00:00 2001 From: "k.verschoor@pay.nl" Date: Tue, 24 Aug 2021 08:55:36 +0200 Subject: [PATCH 1/3] Fix PAY. connection data to be configured based on store --- Model/Config/Source/Available/Available.php | 27 +++++++++++++++++---- Model/Paymentmethod/Ideal.php | 3 ++- Model/Paymentmethod/Instore.php | 3 ++- Model/Paymentmethod/PaymentMethod.php | 14 +++++++++-- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Model/Config/Source/Available/Available.php b/Model/Config/Source/Available/Available.php index f75d825b..8deb0905 100644 --- a/Model/Config/Source/Available/Available.php +++ b/Model/Config/Source/Available/Available.php @@ -1,4 +1,5 @@ _config = $config; $this->_request = $request; $this->_scopeConfig = $scopeConfig; $this->_paymentmethodFactory = $paymentMethodFactory; + $this->_storeManager = $storeManager; } /** @@ -76,6 +84,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')]; @@ -89,13 +102,12 @@ public function toArray() } catch (\Exception $e) { return [0 => 'Error: ' . $e->getMessage()]; } - } protected function getPaymentOptionId() { $method = $this->_paymentmethodFactory->create($this->_class); - if($method instanceof PaymentMethod){ + if ($method instanceof PaymentMethod) { return $method->getPaymentOptionId(); } return null; @@ -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..a9e61180 100644 --- a/Model/Paymentmethod/Ideal.php +++ b/Model/Paymentmethod/Ideal.php @@ -42,7 +42,8 @@ public function getBanks() if (!$show_banks) return []; $cache = $this->getCache(); - $cacheName = 'paynl_banks_' . $this->getPaymentOptionId(); + $storeId = $this->storeManager->getStore()->getId(); + $cacheName = 'paynl_banks_' . $this->getPaymentOptionId() . '_' . $storeId; $banksJson = $cache->load($cacheName); if ($banksJson) { diff --git a/Model/Paymentmethod/Instore.php b/Model/Paymentmethod/Instore.php index 49467700..8414e038 100644 --- a/Model/Paymentmethod/Instore.php +++ b/Model/Paymentmethod/Instore.php @@ -80,7 +80,8 @@ public function assignData(\Magento\Framework\DataObject $data) public function getBanks() { $cache = $this->getCache(); - $cacheName = 'paynl_terminals_' . $this->getPaymentOptionId(); + $storeId = $this->storeManager->getStore()->getId(); + $cacheName = 'paynl_terminals_' . $this->getPaymentOptionId() . '_' . $storeId; $banksJson = $cache->load($cacheName); if ($banksJson) { $banks = json_decode($banksJson); 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(); From 03852ad0ae05ea704943be9af3978d6c5c1740c0 Mon Sep 17 00:00:00 2001 From: "k.verschoor@pay.nl" Date: Tue, 24 Aug 2021 14:24:34 +0200 Subject: [PATCH 2/3] Autoformat availeble.php --- Model/Config/Source/Available/Available.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Model/Config/Source/Available/Available.php b/Model/Config/Source/Available/Available.php index 8deb0905..d4dc5d34 100644 --- a/Model/Config/Source/Available/Available.php +++ b/Model/Config/Source/Available/Available.php @@ -1,5 +1,4 @@ _config = $config; $this->_request = $request; $this->_scopeConfig = $scopeConfig; @@ -85,8 +84,8 @@ public function toOptionArray() public function toArray() { $storeId = $this->_request->getParam('store'); - if($storeId){ - $store = $this->_storeManager->getStore($storeId); + if ($storeId) { + $store = $this->_storeManager->getStore($storeId); $this->_config->setStore($store); } $configured = $this->_config->configureSDK(); @@ -102,12 +101,13 @@ public function toArray() } catch (\Exception $e) { return [0 => 'Error: ' . $e->getMessage()]; } + } protected function getPaymentOptionId() { $method = $this->_paymentmethodFactory->create($this->_class); - if ($method instanceof PaymentMethod) { + if($method instanceof PaymentMethod){ return $method->getPaymentOptionId(); } return null; @@ -135,8 +135,8 @@ protected function getConfigValue($path) protected function _isAvailable() { $storeId = $this->_request->getParam('store'); - if($storeId){ - $store = $this->_storeManager->getStore($storeId); + if ($storeId) { + $store = $this->_storeManager->getStore($storeId); $this->_config->setStore($store); } $configured = $this->_config->configureSDK(); From 3f16af37dd7445f01e39e4179e137046c8fbe27b Mon Sep 17 00:00:00 2001 From: woutse Date: Tue, 24 Aug 2021 17:06:38 +0200 Subject: [PATCH 3/3] Added store --- Model/Paymentmethod/Ideal.php | 10 +++++++--- Model/Paymentmethod/Instore.php | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Model/Paymentmethod/Ideal.php b/Model/Paymentmethod/Ideal.php index a9e61180..36ec0d2b 100644 --- a/Model/Paymentmethod/Ideal.php +++ b/Model/Paymentmethod/Ideal.php @@ -39,16 +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(); - $storeId = $this->storeManager->getStore()->getId(); + $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()); @@ -73,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 8414e038..4f620ec0 100644 --- a/Model/Paymentmethod/Instore.php +++ b/Model/Paymentmethod/Instore.php @@ -80,7 +80,8 @@ public function assignData(\Magento\Framework\DataObject $data) public function getBanks() { $cache = $this->getCache(); - $storeId = $this->storeManager->getStore()->getId(); + $store = $this->storeManager->getStore(); + $storeId = $store->getId(); $cacheName = 'paynl_terminals_' . $this->getPaymentOptionId() . '_' . $storeId; $banksJson = $cache->load($cacheName); if ($banksJson) { @@ -88,6 +89,7 @@ public function getBanks() } else { $banks = []; try { + $this->paynlConfig->setStore($store); $this->paynlConfig->configureSDK(); $terminals = \Paynl\Instore::getAllTerminals();