diff --git a/Model/Config.php b/Model/Config.php index d94f289a..bc8b14cb 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -3,6 +3,7 @@ namespace Rvvup\Payments\Model; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Store\Model\ScopeInterface; use Magento\Store\Model\StoreManagerInterface; use stdClass; @@ -60,7 +61,7 @@ public function isActive(string $scopeType = ScopeInterface::SCOPE_STORE): bool */ public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE): bool { - $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : 'default'; + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; return (bool) $this->scopeConfig->getValue(self::RVVUP_CONFIG . self::XML_PATH_ACTIVE, $scopeType, $scopeCode); } @@ -72,7 +73,7 @@ public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE) */ public function getJwtConfig(string $scopeType = ScopeInterface::SCOPE_STORE): ?string { - $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : 'default'; + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; $value = $this->scopeConfig->getValue(self::RVVUP_CONFIG . self::XML_PATH_JWT, $scopeType, $scopeCode); @@ -145,7 +146,7 @@ public function getAuthToken(string $scopeType = ScopeInterface::SCOPE_STORE): s */ public function isDebugEnabled(string $scopeType = ScopeInterface::SCOPE_STORE): bool { - $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : 'default'; + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; return (bool) $this->scopeConfig->getValue(self::RVVUP_CONFIG . self::XML_PATH_DEBUG, $scopeType, $scopeCode); } @@ -197,7 +198,7 @@ public function getPayPalBlockConfig( string $scopeType = ScopeInterface::SCOPE_STORE ): string { $config = self::RVVUP_CONFIG . self::XML_PATH_PAYPAL_BLOCK . $config; - $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : 'default'; + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; return $this->scopeConfig->getValue($config, $scopeType, $scopeCode); } @@ -205,11 +206,12 @@ public function getPayPalBlockConfig( /** * @param string $scopeType * @return bool + * @throws NoSuchEntityException */ public function getValidProductTypes( string $scopeType = ScopeInterface::SCOPE_STORE ): array { - $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : 'default'; + $scopeCode = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; $path = self::RVVUP_CONFIG . self::PRODUCT_RESTRICTIONS . self::XML_PATH_PRODUCT_TYPES_ENABLED; $types = $this->scopeConfig->getValue($path, $scopeType, $scopeCode); return explode(',', $types); diff --git a/Model/ConfigInterface.php b/Model/ConfigInterface.php index 45760adc..1a0c6fe4 100644 --- a/Model/ConfigInterface.php +++ b/Model/ConfigInterface.php @@ -32,7 +32,7 @@ public function isActive(string $scopeType = ScopeInterface::SCOPE_STORE): bool; /** * Get the active value from the config. * - * @param string $scopeType + * @param string $scopeType * @return bool */ public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE): bool; @@ -40,7 +40,7 @@ public function getActiveConfig(string $scopeType = ScopeInterface::SCOPE_STORE) /** * Get the JWT value from the config. * - * @param string $scopeType + * @param string $scopeType * @return string|null */ public function getJwtConfig(string $scopeType = ScopeInterface::SCOPE_STORE): ?string; diff --git a/Observer/ConfigSaveObserver.php b/Observer/ConfigSaveObserver.php index 21834f11..aa16a9c0 100644 --- a/Observer/ConfigSaveObserver.php +++ b/Observer/ConfigSaveObserver.php @@ -108,7 +108,7 @@ private function sendApiDataOnMethodDisabled(Event $event): void )) { return; } - $scope = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : 'default'; + $scope = $this->storeManager->getStore() ? $this->storeManager->getStore()->getCode() : null; // No action if it was activated. if ($this->config->getActiveConfig() === true) { diff --git a/Service/Hash.php b/Service/Hash.php new file mode 100644 index 00000000..a261ffbc --- /dev/null +++ b/Service/Hash.php @@ -0,0 +1,35 @@ +getPayment(); + $payment->setAdditionalInformation('quote_hash', $this->getHashForData($quote->getData())); + } + + public function getHashForData(array $data): string + { + $hashedValues = []; + foreach ($data as $key => $value) { + if (is_string($value)) { + $hashedValues[$key] = $value; + } + } + + $output = implode(', ', array_map( + function ($v, $k) { return sprintf("%s='%s'", $k, $v); }, + $hashedValues, + array_keys($hashedValues) + )); + + return hash('sha256',$output); + } + +} diff --git a/Test/Unit/Model/Config.php b/Test/Unit/Model/Config.php index 7ab89921..d793a1c9 100644 --- a/Test/Unit/Model/Config.php +++ b/Test/Unit/Model/Config.php @@ -6,6 +6,7 @@ use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Store\Model\ScopeInterface; +use Magento\Store\Model\StoreManagerInterface; use PHPUnit\Framework\TestCase; use Rvvup\Payments\Model\ConfigInterface; @@ -14,6 +15,9 @@ class Config extends TestCase /** @var ScopeConfigInterface */ private $scopeConfigMock; + /** @var StoreManagerInterface */ + private $storeManagerMock; + /** @var \Rvvup\Payments\Model\Config */ private $config; @@ -22,7 +26,11 @@ protected function setUp(): void $this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) ->disableOriginalConstructor()->getMock(); - $this->config = new \Rvvup\Payments\Model\Config($this->scopeConfigMock); + $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) + ->disableOriginalConstructor()->getMock(); + $this->storeManagerMock->method('getStore')->willReturn(null); + + $this->config = new \Rvvup\Payments\Model\Config($this->scopeConfigMock, $this->storeManagerMock); } public function testPaypalBlockDefaultStyling()