Skip to content
Draft
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
61 changes: 61 additions & 0 deletions Api/Config/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ interface RepositoryInterface extends System\DataInterface
public const XML_PATH_EXTENSION_VERSION = 'faslet_connect/general/version';
public const XML_PATH_EXTENSION_ENABLE = 'faslet_connect/general/enable';
public const XML_PATH_DEBUG = 'faslet_connect/general/debug';
public const XML_PATH_RMA_EXPORT_ENABLE = 'faslet_connect/rma/export_enabled';
public const XML_PATH_RMA_ENDPOINT_URL = 'faslet_connect/rma/endpoint_url';
public const XML_PATH_RMA_AUTH_TOKEN = 'faslet_connect/rma/auth_token';
public const XML_PATH_RMA_TIMEOUT = 'faslet_connect/rma/timeout';
public const XML_PATH_RMA_LIFECYCLE_EVENTS = 'faslet_connect/rma/lifecycle_events';
public const DEFAULT_RMA_TIMEOUT = 5;
public const MODULE_SUPPORT_LINK = 'https://faslet.me/faslet/contact';

/**
Expand Down Expand Up @@ -59,4 +65,59 @@ public function getSupportLink(): string;
* @return string
*/
public function getStoreUrl(): string;

/**
* Check if Commerce RMA export is enabled.
*
* @param int|null $storeId
*
* @return bool
*/
public function isRmaExportEnabled(?int $storeId = null): bool;

/**
* Get the Faslet RMA ingestion endpoint.
*
* @param int|null $storeId
*
* @return string|null
*/
public function getRmaEndpointUrl(?int $storeId = null): ?string;

/**
* Get the Faslet auth token used for RMA exports.
*
* @param int|null $storeId
*
* @return string|null
*/
public function getRmaAuthToken(?int $storeId = null): ?string;

/**
* Get the outbound request timeout for RMA exports.
*
* @param int|null $storeId
*
* @return int
*/
public function getRmaTimeout(?int $storeId = null): int;

/**
* Get the configured RMA lifecycle events that should be exported.
*
* @param int|null $storeId
*
* @return array
*/
public function getRmaLifecycleEvents(?int $storeId = null): array;

/**
* Check if a specific lifecycle event should be exported.
*
* @param string $eventCode
* @param int|null $storeId
*
* @return bool
*/
public function shouldExportRmaLifecycleEvent(string $eventCode, ?int $storeId = null): bool;
}
2 changes: 1 addition & 1 deletion Api/Config/System/DataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface DataInterface
/**
* @return string|null
*/
public function getShopId(): ?string;
public function getShopId(?int $storeId = null): ?string;

/**
* @return array
Expand Down
55 changes: 55 additions & 0 deletions Model/Config/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,59 @@ public function getStoreUrl(): string
{
return $this->getStore()->getBaseUrl();
}

/**
* @inheritDoc
*/
public function isRmaExportEnabled(?int $storeId = null): bool
{
return $this->isSetFlag(self::XML_PATH_RMA_EXPORT_ENABLE, $storeId);
}

/**
* @inheritDoc
*/
public function getRmaEndpointUrl(?int $storeId = null): ?string
{
return $this->getStoreValue(self::XML_PATH_RMA_ENDPOINT_URL, $storeId);
}

/**
* @inheritDoc
*/
public function getRmaAuthToken(?int $storeId = null): ?string
{
return $this->getDecryptedStoreValue(self::XML_PATH_RMA_AUTH_TOKEN, $storeId);
}

/**
* @inheritDoc
*/
public function getRmaTimeout(?int $storeId = null): int
{
$timeout = (int)$this->getStoreValue(self::XML_PATH_RMA_TIMEOUT, $storeId);

return $timeout > 0 ? $timeout : self::DEFAULT_RMA_TIMEOUT;
}

/**
* @inheritDoc
*/
public function getRmaLifecycleEvents(?int $storeId = null): array
{
$rawValue = (string)$this->getStoreValue(self::XML_PATH_RMA_LIFECYCLE_EVENTS, $storeId);
if ($rawValue === '') {
return [];
}

return array_values(array_filter(array_map('trim', explode(',', $rawValue))));
}

/**
* @inheritDoc
*/
public function shouldExportRmaLifecycleEvent(string $eventCode, ?int $storeId = null): bool
{
return in_array($eventCode, $this->getRmaLifecycleEvents($storeId), true);
}
}
30 changes: 29 additions & 1 deletion Model/Config/System/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ProductMetadata;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Serialize\Serializer\Json;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Model\ScopeInterface;
Expand All @@ -28,24 +29,31 @@ class BaseRepository
* @var StoreManagerInterface
*/
protected $storeManager;
/**
* @var EncryptorInterface
*/
protected $encryptor;

/**
* BaseRepository constructor.
* @param ScopeConfigInterface $scopeConfig
* @param Json $json
* @param ProductMetadata $metadata
* @param StoreManagerInterface $storeManager
* @param EncryptorInterface $encryptor
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
Json $json,
ProductMetadata $metadata,
StoreManagerInterface $storeManager
StoreManagerInterface $storeManager,
EncryptorInterface $encryptor
) {
$this->scopeConfig = $scopeConfig;
$this->json = $json;
$this->metadata = $metadata;
$this->storeManager = $storeManager;
$this->encryptor = $encryptor;
}

/**
Expand Down Expand Up @@ -82,6 +90,26 @@ protected function isSetFlag(string $path, ?int $storeId = null, ?string $scope
return $this->scopeConfig->isSetFlag($path, $scope, $storeId);
}

/**
* Retrieve and decrypt a config value by path, storeId and scope.
*
* @param string $path
* @param int|null $storeId
* @param string|null $scope
*
* @return string|null
*/
protected function getDecryptedStoreValue(string $path, ?int $storeId = null, ?string $scope = null): ?string
{
$value = $this->getStoreValue($path, $storeId, $scope);

if ($value === null || $value === '') {
return $value;
}

return $this->encryptor->decrypt($value);
}

/**
* @return StoreInterface
*/
Expand Down
4 changes: 2 additions & 2 deletions Model/Config/System/DataRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class DataRepository extends BaseRepository implements DataInterface
/**
* @inheritDoc
*/
public function getShopId(): ?string
public function getShopId(?int $storeId = null): ?string
{
return $this->getStoreValue(self::SHOP_ID);
return $this->getStoreValue(self::SHOP_ID, $storeId);
}

/**
Expand Down
Loading
Loading