Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-onufriichuk committed Dec 13, 2023
1 parent 4e9011b commit 0913521
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 9 deletions.
12 changes: 7 additions & 5 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -197,19 +198,20 @@ 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);
}

/**
* @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);
Expand Down
4 changes: 2 additions & 2 deletions Model/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ 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;

/**
* 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;
Expand Down
2 changes: 1 addition & 1 deletion Observer/ConfigSaveObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 35 additions & 0 deletions Service/Hash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Rvvup\Payments\Service;

use Magento\Quote\Model\Quote;

class Hash
{
public function saveQuoteHash(Quote $quote): void
{
$payment = $quote->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);
}

}
10 changes: 9 additions & 1 deletion Test/Unit/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -14,6 +15,9 @@ class Config extends TestCase
/** @var ScopeConfigInterface */
private $scopeConfigMock;

/** @var StoreManagerInterface */
private $storeManagerMock;

/** @var \Rvvup\Payments\Model\Config */
private $config;

Expand All @@ -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()
Expand Down

0 comments on commit 0913521

Please sign in to comment.