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 da872c02 authored by Rik ter Beek's avatar Rik ter Beek Committed by GitHub

Merge pull request #322 from Adyen/PW-563

PW-563 Add applicationInformation into M2 
parents 6cf953d5 ab8cdff6
......@@ -60,25 +60,7 @@ class TransactionAuthorization implements ClientInterface
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
// initialize client
$webserviceUsername = $this->_adyenHelper->getWsUsername();
$webservicePassword = $this->_adyenHelper->getWsPassword();
$client = new \Adyen\Client();
$client->setApplicationName("Magento 2 plugin");
$client->setUsername($webserviceUsername);
$client->setPassword($webservicePassword);
if ($this->_adyenHelper->isDemoMode()) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
}
// assign magento log
$client->setLogger($adyenLogger);
$this->_client = $client;
$this->_client = $this->_adyenHelper->initializeAdyenClient();
}
/**
......
......@@ -55,25 +55,7 @@ class TransactionCancel implements ClientInterface
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
// initialize client
$webserviceUsername = $this->_adyenHelper->getWsUsername();
$webservicePassword = $this->_adyenHelper->getWsPassword();
$client = new \Adyen\Client();
$client->setApplicationName("Magento 2 plugin");
$client->setUsername($webserviceUsername);
$client->setPassword($webservicePassword);
if ($this->_adyenHelper->isDemoMode()) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
}
// assign magento log
$client->setLogger($adyenLogger);
$this->_client = $client;
$this->_client = $this->_adyenHelper->initializeAdyenClient();
}
/**
......
......@@ -55,25 +55,7 @@ class TransactionCapture implements ClientInterface
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
// initialize client
$webserviceUsername = $this->_adyenHelper->getWsUsername();
$webservicePassword = $this->_adyenHelper->getWsPassword();
$client = new \Adyen\Client();
$client->setApplicationName("Magento 2 plugin");
$client->setUsername($webserviceUsername);
$client->setPassword($webservicePassword);
if ($this->_adyenHelper->isDemoMode()) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
}
// assign magento log
$client->setLogger($adyenLogger);
$this->_client = $client;
$this->_client = $this->_adyenHelper->initializeAdyenClient();
}
/**
......
......@@ -55,25 +55,7 @@ class TransactionRefund implements ClientInterface
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
// initialize client
$webserviceUsername = $this->_adyenHelper->getWsUsername();
$webservicePassword = $this->_adyenHelper->getWsPassword();
$client = new \Adyen\Client();
$client->setApplicationName("Magento 2 plugin");
$client->setUsername($webserviceUsername);
$client->setPassword($webservicePassword);
if ($this->_adyenHelper->isDemoMode()) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
}
// assign magento log
$client->setLogger($adyenLogger);
$this->_client = $client;
$this->_client = $this->_adyenHelper->initializeAdyenClient();
}
/**
......
......@@ -30,7 +30,7 @@ use Magento\Framework\App\Helper\AbstractHelper;
*/
class Data extends AbstractHelper
{
const MODULE_NAME = 'adyen-magento2';
const TEST = 'test';
const LIVE = 'live';
......@@ -84,6 +84,16 @@ class Data extends AbstractHelper
*/
protected $_taxCalculation;
/**
* @var \Magento\Framework\App\ProductMetadataInterface
*/
protected $productMetadata;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $adyenLogger;
/**
* Data constructor.
*
......@@ -95,6 +105,8 @@ class Data extends AbstractHelper
* @param \Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param \Magento\Framework\View\Asset\Repository $assetRepo
* @param \Magento\Framework\View\Asset\Source $assetSource
* @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
......@@ -107,7 +119,10 @@ class Data extends AbstractHelper
\Magento\Framework\View\Asset\Source $assetSource,
\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory $notificationFactory,
\Magento\Tax\Model\Config $taxConfig,
\Magento\Tax\Model\Calculation $taxCalculation
\Magento\Tax\Model\Calculation $taxCalculation,
\Magento\Framework\App\ProductMetadataInterface $productMetadata,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) {
parent::__construct($context);
$this->_encryptor = $encryptor;
......@@ -120,6 +135,8 @@ class Data extends AbstractHelper
$this->_notificationFactory = $notificationFactory;
$this->_taxConfig = $taxConfig;
$this->_taxCalculation = $taxCalculation;
$this->productMetadata = $productMetadata;
$this->adyenLogger = $adyenLogger;
}
/**
......@@ -729,6 +746,21 @@ class Data extends AbstractHelper
return $sepaCountries;
}
/**
* Get adyen magento module's name sent to Adyen
*
* @return string
*/
public function getModuleName()
{
return (string)self::MODULE_NAME;
}
/**
* Get adyen magento module's version
*
* @return string
*/
public function getModuleVersion()
{
return (string)$this->_moduleList->getOne("Adyen_Payment")['setup_version'];
......@@ -1131,4 +1163,37 @@ class Data extends AbstractHelper
}
return $formFields;
}
/**
* Initializes and returns Adyen Client and sets the required parameters of it
*
* @param $storeId
* @return \Adyen\Client
* @throws \Adyen\AdyenException
*/
public function initializeAdyenClient($storeId = null)
{
// initialize client
$webserviceUsername = $this->getWsUsername($storeId);
$webservicePassword = $this->getWsPassword($storeId);
$client = new \Adyen\Client();
$client->setApplicationName("Magento 2 plugin");
$client->setUsername($webserviceUsername);
$client->setPassword($webservicePassword);
$client->setAdyenPaymentSource($this->getModuleName(), $this->getModuleVersion());
$client->setExternalPlatform($this->productMetadata->getName(), $this->productMetadata->getVersion());
if ($this->isDemoMode($storeId)) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
}
$client->setLogger($this->adyenLogger);
return $client;
}
}
......@@ -78,25 +78,13 @@ class PaymentRequest extends DataObject
$this->_appState = $context->getAppState();
}
/**
* @param $storeId
* @return mixed
* @throws \Adyen\AdyenException
*/
private function createClient($storeId) {
// initialize client
$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($storeId)) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
}
// assign magento log
$client->setLogger($this->_adyenLogger);
$client = $this->_adyenHelper->initializeAdyenClient($storeId);
return $client;
}
......
......@@ -14,7 +14,7 @@
}
],
"require": {
"adyen/php-api-library": "*",
"adyen/php-api-library": ">=1.5.2",
"magento/framework": ">=100.1.0"
},
"autoload": {
......
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