From 56acafe66e5ef00a053094f0bff83fe3644d28ff Mon Sep 17 00:00:00 2001 From: Andy Pieters Date: Wed, 26 Jul 2017 15:54:31 +0200 Subject: [PATCH] Catching error if instore is not activated. --- Model/Paymentmethod/Instore.php | 42 ++++++++++----------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/Model/Paymentmethod/Instore.php b/Model/Paymentmethod/Instore.php index 41f83a09..29284820 100644 --- a/Model/Paymentmethod/Instore.php +++ b/Model/Paymentmethod/Instore.php @@ -67,24 +67,27 @@ public function getBanks() $cache = $this->getCache(); $cacheName = 'paynl_terminals_' . $this->getPaymentOptionId(); - $banksJson = $cache->load($cacheName); if ($banksJson) { $banks = json_decode($banksJson); } else { + $banks = []; + try { + $config = new Config($this->_scopeConfig); - $config = new Config($this->_scopeConfig); + $config->configureSDK(); - $config->configureSDK(); + $terminals = \Paynl\Instore::getAllTerminals(); + $terminals = $terminals->getList(); - $terminals = \Paynl\Instore::getAllTerminals(); - $terminals = $terminals->getList(); - $banks = []; - foreach ($terminals as $terminal) { - $terminal['visibleName'] = $terminal['name']; - array_push($banks, $terminal); + foreach ($terminals as $terminal) { + $terminal['visibleName'] = $terminal['name']; + array_push($banks, $terminal); + } + $cache->save(json_encode($banks), $cacheName); + } catch (\Paynl\Error\Error $e) { + // Probably instore is not activated, no terminals present } - $cache->save(json_encode($banks), $cacheName); } array_unshift($banks, array( 'id' => '', @@ -105,23 +108,4 @@ private function getCache() $cache = $om->get('Magento\Framework\App\CacheInterface'); return $cache; } - - private function registerPayment(Order $order, Transaction $transaction) - { - $skipFraudDetection = false; - $payment = $order->getPayment(); - $payment->setTransactionId( - $transaction->getId() - ); - - $payment->setPreparedMessage('Pay.nl - '); - $payment->setIsTransactionClosed( - 0 - ); - $payment->registerCaptureNotification( - $transaction->getPaidCurrencyAmount(), $skipFraudDetection - ); - $order->save(); - - } } \ No newline at end of file