From 3c37fa3999ce7d6f61a7285fe902be54389d2bbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Patrick=20M=C3=BCller?= <p.mueller@pcsg.de>
Date: Wed, 7 Mar 2018 09:37:57 +0100
Subject: [PATCH] refactor: moved isApiSetUp() from PaymentDisplay to Provider
 class; fix: isApiSetup()

---
 .../ERP/Payments/Amazon/PaymentDisplay.php    | 35 +++----------------
 src/QUI/ERP/Payments/Amazon/Provider.php      | 33 +++++++++++++++++
 2 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/src/QUI/ERP/Payments/Amazon/PaymentDisplay.php b/src/QUI/ERP/Payments/Amazon/PaymentDisplay.php
index 7d455d8..ea37f2f 100644
--- a/src/QUI/ERP/Payments/Amazon/PaymentDisplay.php
+++ b/src/QUI/ERP/Payments/Amazon/PaymentDisplay.php
@@ -20,7 +20,7 @@ class PaymentDisplay extends QUI\Control
      *
      * @param array $attributes
      */
-    public function __construct(array $attributes = array())
+    public function __construct(array $attributes = [])
     {
         parent::__construct($attributes);
 
@@ -47,12 +47,12 @@ class PaymentDisplay extends QUI\Control
         $Order            = $this->getAttribute('Order');
         $PriceCalculation = $Order->getPriceCalculation();
 
-        $Engine->assign(array(
+        $Engine->assign([
             'btn_size'      => Provider::getWidgetsSetting('btn_size'),
             'btn_color'     => Provider::getWidgetsSetting('btn_color'),
             'display_price' => $PriceCalculation->getSum()->formatted(),
-            'apiSetUp'      => $this->isApiSetUp()
-        ));
+            'apiSetUp'      => Provider::isApiSetUp()
+        ]);
 
         $this->setJavaScriptControlOption('orderhash', $Order->getHash());
 
@@ -61,31 +61,4 @@ class PaymentDisplay extends QUI\Control
 
         return $Engine->fetch(dirname(__FILE__) . '/PaymentDisplay.html');
     }
-
-    /**
-     * Check if the Amazon Pay API settings are correct
-     *
-     * @return bool
-     * @throws QUI\Exception
-     */
-    protected function isApiSetUp()
-    {
-        $Conf        = QUI::getPackage('quiqqer/payment-amazon')->getConfig();
-        $apiSettings = $Conf->getSection('api');
-
-        foreach ($apiSettings as $k => $v) {
-            if (empty($v)) {
-                QUI\System\Log::addError(
-                    'Your Amazon Pay API credentials seem to be (partially) missing.'
-                    . ' Amazon Pay CAN NOT be used at the moment. Please enter all your'
-                    . ' API credentials. See https://dev.quiqqer.com/quiqqer/payment-amazon/wikis/api-configuration'
-                    . ' for further instructions.'
-                );
-
-                return false;
-            }
-        }
-
-        return true;
-    }
 }
diff --git a/src/QUI/ERP/Payments/Amazon/Provider.php b/src/QUI/ERP/Payments/Amazon/Provider.php
index b2613e9..0531c78 100644
--- a/src/QUI/ERP/Payments/Amazon/Provider.php
+++ b/src/QUI/ERP/Payments/Amazon/Provider.php
@@ -79,4 +79,37 @@ class Provider extends AbstractPaymentProvider
 
         return $Conf->get('widgets', $setting);
     }
+
+    /**
+     * Check if the Amazon Pay API settings are correct
+     *
+     * @return bool
+     * @throws QUI\Exception
+     */
+    public static function isApiSetUp()
+    {
+        $Conf        = QUI::getPackage('quiqqer/payment-amazon')->getConfig();
+        $apiSettings = $Conf->getSection('api');
+
+        foreach ($apiSettings as $k => $v) {
+            switch ($k) {
+                case 'sandbox':
+                    continue 2;
+                    break;
+            }
+
+            if (empty($v)) {
+                QUI\System\Log::addError(
+                    'Your Amazon Pay API credentials seem to be (partially) missing.'
+                    . ' Amazon Pay CAN NOT be used at the moment. Please enter all your'
+                    . ' API credentials. See https://dev.quiqqer.com/quiqqer/payment-amazon/wikis/api-configuration'
+                    . ' for further instructions.'
+                );
+
+                return false;
+            }
+        }
+
+        return true;
+    }
 }
-- 
GitLab