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 0a01254f authored by attilak's avatar attilak

Resolve comments during code review

parent a73e2010
......@@ -24,7 +24,6 @@
namespace Adyen\Payment\Api;
interface AdyenInitiateTerminalApiInterface
{
/**
......@@ -32,4 +31,4 @@ interface AdyenInitiateTerminalApiInterface
* @return mixed
*/
public function initiate();
}
\ No newline at end of file
}
......@@ -24,7 +24,6 @@
namespace Adyen\Payment\Block\Form;
class PosCloud extends \Magento\Payment\Block\Form
{
/**
......@@ -32,4 +31,4 @@ class PosCloud extends \Magento\Payment\Block\Form
*/
protected $_template = 'Adyen_Payment::form/pos_cloud.phtml';
}
\ No newline at end of file
}
......@@ -24,7 +24,6 @@
namespace Adyen\Payment\Block\Info;
class PosCloud extends AbstractInfo
{
/**
......
......@@ -35,34 +35,43 @@ class TransactionPosCloudSync implements ClientInterface
*/
protected $storeId;
/**
* @var \Adyen\Client
*/
protected $client;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $adyenHelper;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $adyenLogger;
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Model\RecurringType $recurringType,
\Magento\Store\Model\StoreManagerInterface $storeManager,
array $data = []
) {
$this->_encryptor = $encryptor;
$this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
$this->adyenHelper = $adyenHelper;
$this->adyenLogger = $adyenLogger;
$this->storeId = $storeManager->getStore()->getId();
// initialize client
$client = $this->_adyenHelper->initializeAdyenClient($this->storeId);
$apiKey = $this->_adyenHelper->getPosApiKey($this->storeId);
$client = $this->adyenHelper->initializeAdyenClient($this->storeId);
$apiKey = $this->adyenHelper->getPosApiKey($this->storeId);
$client->setXApiKey($apiKey);
//Set configurable option in M2
$posTimeout = $this->_adyenHelper->getAdyenPosCloudConfigData('pos_timeout', $this->storeId);
$posTimeout = $this->adyenHelper->getAdyenPosCloudConfigData('pos_timeout', $this->storeId);
if (!empty($posTimeout)) {
$client->setTimeout($posTimeout);
}
$this->_client = $client;
$this->client = $client;
}
......@@ -82,15 +91,15 @@ class TransactionPosCloudSync implements ClientInterface
return $paymentResponse;
}
//always do status call and return the response of the status call
$service = new \Adyen\Service\PosPayment($this->_client);
$service = $this->adyenHelper->createAdyenPosPaymentService($this->client);
$poiId = $this->_adyenHelper->getPoiId($this->storeId);
$poiId = $this->adyenHelper->getPoiId($this->storeId);
$newServiceID = date("dHis");
$statusDate = date("U");
$timeDiff = (int)$statusDate - (int)$request['initiateDate'];
$totalTimeout = $this->_adyenHelper->getAdyenPosCloudConfigData('total_timeout', $this->storeId);
$totalTimeout = $this->adyenHelper->getAdyenPosCloudConfigData('total_timeout', $this->storeId);
if ($timeDiff > $totalTimeout) {
throw new \Magento\Framework\Exception\LocalizedException(__("Pos Timeout."));
}
......
......@@ -28,34 +28,6 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
class PosCloudBuilder implements BuilderInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* @var
*/
private $_adyenLogger;
protected $_quoteRepository;
/**
* PaymentDataBuilder constructor.
*
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository
) {
$this->_adyenLogger = $adyenLogger;
$this->adyenHelper = $adyenHelper;
$this->_quoteRepository = $quoteRepository;
}
/**
* @param array $buildSubject
* @return array
......@@ -72,4 +44,4 @@ class PosCloudBuilder implements BuilderInterface
"initiateDate" => $payment->getAdditionalInformation("initiateDate")
];
}
}
\ No newline at end of file
}
......@@ -35,9 +35,9 @@ class PaymentPosCloudHandler implements HandlerInterface
*/
private $adyenHelper;
/**
* @var
*/
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
private $adyenLogger;
/**
......@@ -64,7 +64,7 @@ class PaymentPosCloudHandler implements HandlerInterface
*/
public function handle(array $handlingSubject, array $paymentResponse)
{
$payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject);
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject);
/** @var OrderPaymentInterface $payment */
$payment = $payment->getPayment();
......@@ -76,7 +76,7 @@ class PaymentPosCloudHandler implements HandlerInterface
$payment->getOrder()->setCanSendNewEmailFlag(false);
// set transaction(status)
if (!empty($paymentResponse) && !empty($paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'])) {
if (!empty($paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'])) {
$pspReference = $paymentResponse['PaymentResult']['PaymentAcquirerData']['AcquirerTransactionID']['TransactionID'];
$payment->setTransactionId($pspReference);
// set transaction(payment)
......
......@@ -40,11 +40,13 @@ class PosCloudResponseValidator extends AbstractValidator
*/
private $adyenHelper;
/**
* PosCloudResponseValidator constructor.
* @param \Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
*/
/**
* PosCloudResponseValidator constructor.
*
* @param \Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
......
......@@ -426,7 +426,7 @@ class Data extends AbstractHelper
/**
* @desc Gives back adyen_pos configuration values
* @param $field
* @param null $storeId
* @param int|null $storeId
* @return mixed
*/
public function getAdyenPosConfigData($field, $storeId = null)
......@@ -437,7 +437,7 @@ class Data extends AbstractHelper
/**
* @desc Gives back adyen_pos configuration values as flag
* @param $field
* @param null $storeId
* @param int|null $storeId
* @return mixed
*/
public function getAdyenPosConfigDataFlag($field, $storeId = null)
......@@ -447,7 +447,7 @@ class Data extends AbstractHelper
/**
* @param $field
* @param null $storeId
* @param int|null $storeId
* @return bool|mixed
*/
public function getAdyenPosCloudConfigData($field, $storeId = null)
......@@ -457,7 +457,7 @@ class Data extends AbstractHelper
/**
* @param $field
* @param null $storeId
* @param int|null $storeId
* @return bool|mixed
*/
public function getAdyenPosCloudConfigDataFlag($field, $storeId = null)
......@@ -468,7 +468,7 @@ class Data extends AbstractHelper
/**
* @desc Gives back adyen_pay_by_mail configuration values
* @param $field
* @param null $storeId
* @param int|null $storeId
* @return mixed
*/
public function getAdyenPayByMailConfigData($field, $storeId = null)
......@@ -479,7 +479,7 @@ class Data extends AbstractHelper
/**
* @desc Gives back adyen_pay_by_mail configuration values as flag
* @param $field
* @param null $storeId
* @param int|null $storeId
* @return mixed
*/
public function getAdyenPayByMailConfigDataFlag($field, $storeId = null)
......@@ -1185,7 +1185,7 @@ class Data extends AbstractHelper
}
/**
* @param integer|null $storeId
* @param int|null $storeId
* @return string the X API Key for the specified or current store
*/
public function getPosApiKey($storeId = null)
......@@ -1206,8 +1206,7 @@ class Data extends AbstractHelper
*/
public function getPoiId($storeId = null)
{
$poiId = $this->getAdyenPosCloudConfigData('pos_terminal_id', $storeId);
return $poiId;
return $this->getAdyenPosCloudConfigData('pos_terminal_id', $storeId);
}
/**
......@@ -1266,20 +1265,21 @@ class Data extends AbstractHelper
/**
* Initializes and returns Adyen Client and sets the required parameters of it
*
* @param $storeId
* @param int|null $storeId
* @param string|null $apiKey
* @return \Adyen\Client
* @throws \Adyen\AdyenException
*/
public function initializeAdyenClient($storeId = null)
public function initializeAdyenClient($storeId = null, $apiKey = null)
{
// initialize client
$webserviceUsername = $this->getWsUsername($storeId);
$webservicePassword = $this->getWsPassword($storeId);
if (!$apiKey) {
$apiKey = $this->getAPIKey($storeId);
}
$client = new \Adyen\Client();
// initialize client
$client = $this->createAdyenClient();
$client->setApplicationName("Magento 2 plugin");
$client->setUsername($webserviceUsername);
$client->setPassword($webservicePassword);
$client->setXApiKey($apiKey);
$client->setAdyenPaymentSource($this->getModuleName(), $this->getModuleVersion());
......@@ -1288,11 +1288,23 @@ class Data extends AbstractHelper
if ($this->isDemoMode($storeId)) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
$client->setEnvironment(\Adyen\Environment::LIVE);
$client->setEnvironment(\Adyen\Environment::LIVE, $this->getLiveEndpointPrefix($storeId));
}
$client->setLogger($this->adyenLogger);
return $client;
}
/**
* @param \Adyen\Clien $client
* @return \Adyen\Service\PosPayment
* @throws \Adyen\AdyenException
*/
public function createAdyenPosPaymentService($client)
{
return new \Adyen\Service\PosPayment($client);
}
}
......@@ -30,12 +30,20 @@ use Adyen\Util\Util;
class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
private $_encryptor;
private $_adyenHelper;
private $_adyenLogger;
private $_recurringType;
private $_appState;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
private $adyenLogger;
/**
* @var \Adyen\Client
*/
protected $client;
/**
* @var int
......@@ -45,7 +53,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
/**
* @var \Magento\Checkout\Model\Session
*/
protected $_checkoutSession;
protected $checkoutSession;
/**
* AdyenInitiateTerminalApi constructor.
......@@ -57,23 +65,22 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Checkout\Model\Session $_checkoutSession,
\Magento\Checkout\Model\Session $checkoutSession,
\Magento\Store\Model\StoreManagerInterface $storeManager,
array $data = []
)
{
$this->_adyenHelper = $adyenHelper;
$this->_adyenLogger = $adyenLogger;
$this->_checkoutSession = $_checkoutSession;
$this->adyenHelper = $adyenHelper;
$this->adyenLogger = $adyenLogger;
$this->checkoutSession = $checkoutSession;
$this->storeId = $storeManager->getStore()->getId();
// initialize client
$client = $this->_adyenHelper->initializeAdyenClient($this->storeId);
$apiKey = $this->_adyenHelper->getPosApiKey($this->storeId);
$client->setXApiKey($apiKey);
$apiKey = $this->adyenHelper->getPosApiKey($this->storeId);
$client = $this->adyenHelper->initializeAdyenClient($this->storeId, $apiKey);
//Set configurable option in M2
$posTimeout = $this->_adyenHelper->getAdyenPosCloudConfigData('pos_timeout', $this->storeId);
$posTimeout = $this->adyenHelper->getAdyenPosCloudConfigData('pos_timeout', $this->storeId);
if (!empty($posTimeout)) {
$client->setTimeout($posTimeout);
}
......@@ -81,7 +88,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
// assign magento log
$client->setLogger($adyenLogger);
$this->_client = $client;
$this->client = $client;
}
/**
......@@ -91,14 +98,14 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
*/
public function initiate()
{
$quote = $this->_checkoutSession->getQuote();
$quote = $this->checkoutSession->getQuote();
$payment = $quote->getPayment();
$payment->setMethod(AdyenPosCloudConfigProvider::CODE);
$reference = $quote->reserveOrderId()->getReservedOrderId();
$service = new \Adyen\Service\PosPayment($this->_client);
$service = $this->adyenHelper->createAdyenPosPaymentService($this->client);
$transactionType = \Adyen\TransactionType::NORMAL;
$poiId = $this->_adyenHelper->getPoiId($this->storeId);
$poiId = $this->adyenHelper->getPoiId($this->storeId);
$serviceID = date("dHis");
$initiateDate = date("U");
$timeStamper = date("Y-m-d") . "T" . date("H:i:s+00:00");
......@@ -147,9 +154,9 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
// If customer exists add it into the request to store request
if (!empty($customerId)) {
$shopperEmail = $quote->getCustomerEmail();
$recurringContract = $this->_adyenHelper->getAdyenPosCloudConfigData('recurring_type', $this->storeId);
$recurringContract = $this->adyenHelper->getAdyenPosCloudConfigData('recurring_type', $this->storeId);
if (!empty($recurringContract) && !empty($shopperEmail) && !empty($customerId)) {
if (!empty($recurringContract) && !empty($shopperEmail)) {
$recurringDetails = [
'shopperEmail' => $shopperEmail,
'shopperReference' => strval($customerId),
......@@ -168,7 +175,7 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
$response = $service->runTenderSync($request);
} catch (\Adyen\AdyenException $e) {
//Not able to perform a payment
$this->_adyenLogger->addAdyenDebug("adyenexception");
$this->adyenLogger->addAdyenDebug("adyenexception");
$response['error'] = $e->getMessage();
} catch (\Exception $e) {
//Probably timeout
......
......@@ -22,10 +22,8 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
class AdyenPaymentInformationManagement extends \Magento\Checkout\Model\PaymentInformationManagement
{
......@@ -45,4 +43,4 @@ class AdyenPaymentInformationManagement extends \Magento\Checkout\Model\PaymentI
}
return $orderId;
}
}
\ No newline at end of file
}
......@@ -25,37 +25,23 @@
namespace Adyen\Payment\Model\Ui;
use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Directory\Helper\Data;
class AdyenPosCloudConfigProvider implements ConfigProviderInterface
{
const CODE = 'adyen_pos_cloud';
protected $_adyenLogger;
/**
* @var PaymentHelper
*/
protected $_paymentHelper;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $_adyenHelper;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
protected $request;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $_urlBuilder;
protected $urlBuilder;
/**
* AdyenHppConfigProvider constructor.
......@@ -64,18 +50,11 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
\Magento\Framework\UrlInterface $urlBuilder
) {
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_urlBuilder = $urlBuilder;
$this->_adyenLogger = $adyenLogger;
$this->request = $request;
$this->urlBuilder = $urlBuilder;
}
/**
......@@ -90,8 +69,8 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'/checkout/onepage/success/', ['_secure' => $this->_getRequest()->isSecure()])
'redirectUrl' => $this->urlBuilder->getUrl(
'/checkout/onepage/success/', ['_secure' => $this->getRequest()->isSecure()])
]
]
];
......@@ -104,8 +83,8 @@ class AdyenPosCloudConfigProvider implements ConfigProviderInterface
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
protected function getRequest()
{
return $this->_request;
return $this->request;
}
}
\ No newline at end of file
}
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