We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit d7691ceb authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #126 from Adyen/cron-multistore

Use the correct credentials when creating billing agreements from cronjob
parents 97734102 7247e115
......@@ -480,9 +480,9 @@ class Data extends AbstractHelper
* @desc Check if configuration is set to demo mode
* @return mixed
*/
public function isDemoMode()
public function isDemoMode($storeId = null)
{
return $this->getAdyenAbstractConfigDataFlag('demo_mode');
return $this->getAdyenAbstractConfigDataFlag('demo_mode', $storeId);
}
/**
......@@ -498,12 +498,12 @@ class Data extends AbstractHelper
* @desc Retrieve the webserver username
* @return string
*/
public function getWsUsername()
public function getWsUsername($storeId = null)
{
if ($this->isDemoMode()) {
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_test'));
if ($this->isDemoMode($storeId)) {
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_test', $storeId));
} else {
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_live'));
$wsUsername = trim($this->getAdyenAbstractConfigData('ws_username_live', $storeId));
}
return $wsUsername;
}
......@@ -512,30 +512,16 @@ class Data extends AbstractHelper
* @desc Retrieve the webserver password
* @return string
*/
public function getWsPassword()
public function getWsPassword($storeId = null)
{
if ($this->isDemoMode()) {
$wsPassword = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData('ws_password_test')));
if ($this->isDemoMode($storeId)) {
$wsPassword = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData('ws_password_test', $storeId)));
} else {
$wsPassword = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData('ws_password_live')));
$wsPassword = $this->_encryptor->decrypt(trim($this->getAdyenAbstractConfigData('ws_password_live', $storeId)));
}
return $wsPassword;
}
/**
* @desc Retrieve the webserver url defined in the config.xlm only
* @return string
*/
public function getWsUrl()
{
if ($this->isDemoMode()) {
$url = $this->getAdyenAbstractConfigData('ws_url_test');
} else {
$url = $this->getAdyenAbstractConfigData('ws_url_live');
}
return $url;
}
/**
* @desc Cancels the order
* @param $order
......
......@@ -43,11 +43,6 @@ class PaymentRequest extends DataObject
*/
protected $_adyenLogger;
/**
* @var \Adyen\Client
*/
protected $_client;
/**
* @var \Adyen\Payment\Model\RecurringType
*/
......@@ -81,26 +76,28 @@ class PaymentRequest extends DataObject
$this->_adyenLogger = $adyenLogger;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
}
private function createClient($storeId) {
// initialize client
$webserviceUsername = $this->_adyenHelper->getWsUsername();
$webservicePassword = $this->_adyenHelper->getWsPassword();
$webserviceUsername = $this->_adyenHelper->getWsUsername($storeId);
$webservicePassword = $this->_adyenHelper->getWsPassword($storeId);
$client = new \Adyen\Client();
$client->setApplicationName("Magento 2 plugin");
$client->setUsername($webserviceUsername);
$client->setPassword($webservicePassword);
if ($this->_adyenHelper->isDemoMode()) {
if ($this->_adyenHelper->isDemoMode($storeId)) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
}
// assign magento log
$client->setLogger($adyenLogger);
$client->setLogger($this->_adyenLogger);
$this->_client = $client;
return $client;
}
/**
......@@ -128,7 +125,8 @@ class PaymentRequest extends DataObject
];
try {
$service = new \Adyen\Service\Payment($this->_client);
$client = $this->createClient($storeId);
$service = new \Adyen\Service\Payment($client);
$result = $service->authorise3D($request);
} catch(\Adyen\AdyenException $e) {
throw new \Magento\Framework\Exception\LocalizedException(__('3D secure failed'));
......@@ -203,7 +201,8 @@ class PaymentRequest extends DataObject
];
// call lib
$service = new \Adyen\Service\Recurring($this->_client);
$client = $this->createClient($storeId);
$service = new \Adyen\Service\Recurring($client);
$result = $service->listRecurringDetails($request);
return $result;
......@@ -229,7 +228,8 @@ class PaymentRequest extends DataObject
];
// call lib
$service = new \Adyen\Service\Recurring($this->_client);
$client = $this->createClient($storeId);
$service = new \Adyen\Service\Recurring($client);
try {
$result = $service->disable($request);
......
Markdown is supported
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