Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSF-22 - Set 'enhanced_data_mode' to false by default #110

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
31 changes: 28 additions & 3 deletions Observer/ConfigObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +33,12 @@ class ConfigObserver implements \Magento\Framework\Event\ObserverInterface
* @var WriterInterface
*/
protected $writeInterface;

/**
* @var TypeListInterface
*/
protected $cacheTypeList;

/**
* ConfigObserver constructor.
* @param AbstractApi $abstractApi
Expand All @@ -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;
}

/**
Expand All @@ -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;
Expand All @@ -73,6 +82,9 @@ public function execute(Observer $observer)
$scopeData['scope_id'] = $store;
}

$changedPaths = $observer->getChangedPaths();
$this->syncEnhancedDataModeWithSandboxMode($scopeData, $changedPaths);

$this->validateCredentials();

$json = [
Expand Down Expand Up @@ -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);
}
Expand All @@ -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']);
}
}
}
}
71 changes: 39 additions & 32 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
<label>Extension Version</label>
<frontend_model>Forter\Forter\Block\Adminhtml\System\Config\ModuleVersion</frontend_model>
</field>
<field id="sandbox_mode" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sandbox mode</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
Please toggle this option to "Yes" if you want to debug in Sandbox Environment.
</comment>
</field>
<field id="debug_mode" translate="label" type="select" sortOrder="6" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Debug Mode</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down Expand Up @@ -234,7 +241,7 @@
<field id="verification_results_map" translate="label comment" type="textarea" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Verification Results Mapping</label>
<comment>
<![CDATA[
<![CDATA[
<p>Map Forter fields to your local payment fields.<br>Example:
<pre>{
"payment_method_code_1":{
Expand All @@ -251,41 +258,41 @@
}</pre><p>]]>
</comment>
</field>
</group>
<group id="advanced_settings_cc_listener" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Advanced Settings Pre Auth</label>
<field id="enabled_cc_listener" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable CreditCard Listener</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
Enable Javascript Listener For CreditCard field in order to get bin and last4cc
</comment>
</field>
<field id="enabled_cc_listener_last4cc" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Listener for last4cc</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
Enable Javascript Listener For CreditCard Last4cc
</comment>
</field>
<field id="enabled_cc_listener_bin" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Listener for bin</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
Enable Javascript Listener For CreditCard Bin
</comment>
</field>
<field id="class_id_identifier" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Class or Id identifier for the Listener</label>
<comment>
<![CDATA[
</group>
<group id="advanced_settings_cc_listener" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Advanced Settings Pre Auth</label>
<field id="enabled_cc_listener" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable CreditCard Listener</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
Enable Javascript Listener For CreditCard field in order to get bin and last4cc
</comment>
</field>
<field id="enabled_cc_listener_last4cc" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Listener for last4cc</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
Enable Javascript Listener For CreditCard Last4cc
</comment>
</field>
<field id="enabled_cc_listener_bin" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enable Listener for bin</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>
Enable Javascript Listener For CreditCard Bin
</comment>
</field>
<field id="class_id_identifier" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Class or Id identifier for the Listener</label>
<comment>
<![CDATA[
Please add the CSS selector of the CC input you want to observe.<br>
Example selector: <i>.cc-number-field-wrapper input</i><br>
How to use: <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector">https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector</a>.
]]>
</comment>
</field>
</group>
</comment>
</field>
</group>
</section>
</system>
</config>
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<enabled>0</enabled>
<debug_mode>1</debug_mode>
<api_version>2.17</api_version>
<enhanced_data_mode>1</enhanced_data_mode>
<enhanced_data_mode>0</enhanced_data_mode>
<sandbox_mode>0</sandbox_mode>
</settings>
<immediate_post_pre_decision>
Expand Down