This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace Esun\OceanpaymentKlarna\Model;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;
class Config
{
public const METHOD_CODE = 'esun_oceanpayment_klarna';
public const METHODS_VALUE = 'Klarna';
public const SANDBOX_ENDPOINT = 'https://test-secure.oceanpayment.com/gateway/service/sendTrade';
public const PRODUCTION_ENDPOINT = 'https://secure.oceanpayment.com/gateway/service/sendTrade';
private const PATH_PREFIX = 'payment/' . self::METHOD_CODE . '/';
public function __construct(
private readonly ScopeConfigInterface $scopeConfig,
private readonly SecretValueDecoder $secretValueDecoder
) {
}
public function getValue(string $field, ?int $storeId = null): string
{
return trim((string)$this->scopeConfig->getValue(
self::PATH_PREFIX . $field,
ScopeInterface::SCOPE_STORE,
$storeId
));
}
public function getSecret(string $field, ?int $storeId = null): string
{
$prefix = $this->isSandbox($storeId) ? 'sandbox_' : 'production_';
return $this->secretValueDecoder->decode($this->getValue($prefix . $field, $storeId));
}
public function isSandbox(?int $storeId = null): bool
{
return $this->scopeConfig->isSetFlag(
self::PATH_PREFIX . 'sandbox',
ScopeInterface::SCOPE_STORE,
$storeId
);
}
public function isDebug(?int $storeId = null): bool
{
return $this->scopeConfig->isSetFlag(
self::PATH_PREFIX . 'debug',
ScopeInterface::SCOPE_STORE,
$storeId
);
}
public function getEndpoint(?int $storeId = null): string
{
return $this->isSandbox($storeId) ? self::SANDBOX_ENDPOINT : self::PRODUCTION_ENDPOINT;
}
public function isConfigured(?int $storeId = null): bool
{
return $this->getSecret('account', $storeId) !== ''
&& $this->getSecret('terminal', $storeId) !== ''
&& $this->getSecret('secure_code', $storeId) !== '';
}
}