diff --git a/Model/Config.php b/Model/Config.php index 744f728..40c24c5 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -325,6 +325,18 @@ public function isSandboxMode($scope = null, $scopeId = null) return (bool)$this->getConfigValue('settings/enhanced_data_mode', $scope, $scopeId); } + /** + * Return bool value depends of that if payment method sandbox mode + * is enabled or not. + * + * @return bool + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function getSandboxMode($scope = null, $scopeId = null) + { + return (bool)$this->getConfigValue('settings/sandbox_mode', $scope, $scopeId); + } + /** * @method getCurrentStore */ diff --git a/Observer/ConfigObserver.php b/Observer/ConfigObserver.php index cdddbb3..63a377b 100644 --- a/Observer/ConfigObserver.php +++ b/Observer/ConfigObserver.php @@ -7,6 +7,7 @@ use Magento\Framework\App\Config\Storage\WriterInterface; use Magento\Framework\Event\Observer; use Magento\Store\Model\StoreManagerInterface; +use Magento\Framework\App\Cache\TypeListInterface; /** * Class ConfigObserver @@ -32,6 +33,12 @@ class ConfigObserver implements \Magento\Framework\Event\ObserverInterface * @var WriterInterface */ protected $writeInterface; + + /** + * @var TypeListInterface + */ + protected $cacheTypeList; + /** * ConfigObserver constructor. * @param AbstractApi $abstractApi @@ -41,12 +48,14 @@ public function __construct( WriterInterface $writeInterface, AbstractApi $abstractApi, Config $forterConfig, - StoreManagerInterface $storeManagerInterface + StoreManagerInterface $storeManagerInterface, + TypeListInterface $cacheTypeList ) { $this->writeInterface = $writeInterface; $this->abstractApi = $abstractApi; $this->forterConfig = $forterConfig; $this->storeManagerInterface = $storeManagerInterface; + $this->cacheTypeList = $cacheTypeList; } /** @@ -60,8 +69,8 @@ public function execute(Observer $observer) try { $website = $observer->getWebsite(); $store = $observer->getStore(); - $scopeData['scope'] = null; - $scopeData['scope_id'] = null; + $scopeData['scope'] = 'default'; + $scopeData['scope_id'] = 0; if ($website) { $scopeData['scope'] = \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES; @@ -73,6 +82,9 @@ public function execute(Observer $observer) $scopeData['scope_id'] = $store; } + $changedPaths = $observer->getChangedPaths(); + $this->syncEnhancedDataModeWithSandboxMode($scopeData, $changedPaths); + $this->validateCredentials(); $json = [ @@ -135,6 +147,7 @@ public function execute(Observer $observer) $url = self::SETTINGS_API_ENDPOINT; $this->abstractApi->sendApiRequest($url, json_encode($json)); + $this->cacheTypeList->cleanType(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER); } catch (\Exception $e) { $this->abstractApi->reportToForterOnCatch($e); } @@ -149,4 +162,16 @@ private function validateCredentials() throw new \Exception('Site ID and Secret Key are incorrect'); } } + + private function syncEnhancedDataModeWithSandboxMode($scopeData, $changedPaths) + { + if (in_array('forter/settings/sandbox_mode', $changedPaths)) { + $sandboxMode = $this->forterConfig->getSandboxMode($scopeData['scope'], $scopeData['scope_id']); + if ($sandboxMode) { + $this->writeInterface->save('forter/settings/enhanced_data_mode', 1, $scopeData['scope'], $scopeData['scope_id']); + } else { + $this->writeInterface->save('forter/settings/enhanced_data_mode', 0, $scopeData['scope'], $scopeData['scope_id']); + } + } + } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 0edfd08..3a2ef89 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -31,6 +31,13 @@ Extension Version Forter\Forter\Block\Adminhtml\System\Config\ModuleVersion + + Sandbox mode + Magento\Config\Model\Config\Source\Yesno + + Please toggle this option to "Yes" if you want to debug in Sandbox Environment. + + Debug Mode Magento\Config\Model\Config\Source\Yesno @@ -234,7 +241,7 @@ Verification Results Mapping -Map Forter fields to your local payment fields.Example: { "payment_method_code_1":{ @@ -251,41 +258,41 @@ }]]> - - - Advanced Settings Pre Auth - - Enable CreditCard Listener - Magento\Config\Model\Config\Source\Yesno - - Enable Javascript Listener For CreditCard field in order to get bin and last4cc - - - - Enable Listener for last4cc - Magento\Config\Model\Config\Source\Yesno - - Enable Javascript Listener For CreditCard Last4cc - - - - Enable Listener for bin - Magento\Config\Model\Config\Source\Yesno - - Enable Javascript Listener For CreditCard Bin - - - - Class or Id identifier for the Listener - - + + Advanced Settings Pre Auth + + Enable CreditCard Listener + Magento\Config\Model\Config\Source\Yesno + + Enable Javascript Listener For CreditCard field in order to get bin and last4cc + + + + Enable Listener for last4cc + Magento\Config\Model\Config\Source\Yesno + + Enable Javascript Listener For CreditCard Last4cc + + + + Enable Listener for bin + Magento\Config\Model\Config\Source\Yesno + + Enable Javascript Listener For CreditCard Bin + + + + Class or Id identifier for the Listener + + Example selector: .cc-number-field-wrapper input How to use: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector. ]]> - - - + + + diff --git a/etc/config.xml b/etc/config.xml index 5db4869..fc70315 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -6,7 +6,7 @@ 0 1 2.17 - 1 + 0 0
{ "payment_method_code_1":{ @@ -251,41 +258,41 @@ }
]]>