Commit 8ad9af9d authored by Vincent Mrose's avatar Vincent Mrose 💬
Browse files

Fixes #4 - SecureFields URL is not based on configured environment


Signed-off-by: Vincent Mrose's avatarVincent Mrose <v.mrose@crefopay.de>
parent a5099b2e
......@@ -28,6 +28,11 @@ class Config extends \Magento\Payment\Gateway\Config\Config
*/
private $baseUrl;
/**
* @var string
*/
private $secureFieldsUrl;
/**
* Initialize dependencies.
*
......@@ -109,7 +114,32 @@ class Config extends \Magento\Payment\Gateway\Config\Config
*/
public function getPublicToken(): string
{
return (string)$this->getValue(self::KEY_PUBLIC_TOKEN);
return (string) $this->getValue(self::KEY_PUBLIC_TOKEN);
}
/**
* @return string
*/
public function getSecureFieldsUrl(): string
{
if ($this->secureFieldsUrl) {
return $this->secureFieldsUrl;
}
$environment = self::KEY_ENVIRONMENT;
switch ($this->getValue($environment)) {
case Environment::ENVIRONMENT_PRODUCTION:
$this->secureFieldsUrl = 'https://api.crefopay.de/secureFields/';
break;
case Environment::ENVIRONMENT_SANDBOX:
$this->secureFieldsUrl = 'https://sandbox.crefopay.de/secureFields/';
break;
default:
throw new \InvalidArgumentException(sprintf('Invalid value for CrefoPay environment: %s', $environment));
}
return $this->secureFieldsUrl;
}
/**
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -40,6 +40,7 @@ class ConfigProvider implements ConfigProviderInterface
self::CODE => [
'isActive' => $this->config->isActive(),
'publicToken' => $this->config->getPublicToken(),
'secureFieldsUrl' => $this->config->getSecureFieldsUrl(),
'crefoPayMethodCode' => PaymentMethodsCodesMap::getCrefoPayLibraryCode(self::CODE)
]
]
......
......@@ -50,7 +50,7 @@ define([
return {
apiClient: null,
configuration: {
url: "https://sandbox.crefopay.de/secureFields/",
url: window.checkoutConfig.payment['crefopay_paypal'].secureFieldsUrl,
placeholders: {}
},
......@@ -93,7 +93,7 @@ define([
createClient: function(crefoPayOrderId)
{
// @todo remove dependency from concrete payment method
var publicToken = window.checkoutConfig.payment['crefopay_bill'].publicToken;
var publicToken = window.checkoutConfig.payment['crefopay_paypal'].publicToken;
console.log(crefoPayOrderId);
this.crefoPayOrderId = crefoPayOrderId;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment