We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 7247e115 authored by Giorgos Adam's avatar Giorgos Adam

Use the correct credentials when creating billing agreements from cron job in...

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