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 b582fae7 authored by rikterbeek's avatar rikterbeek

#37 optimizing code removed some duplicate code from core and added comment tags

parent 4bee6600
...@@ -193,10 +193,10 @@ interface NotificationInterface ...@@ -193,10 +193,10 @@ interface NotificationInterface
public function setAmountValue($amountValue); public function setAmountValue($amountValue);
/** /**
* Gets the AmountValue for the notification. * Gets the AmountValue for the notification.
* *
* @return int|null AmountValue. * @return int|null AmountValue.
*/ */
public function getAmountCurency(); public function getAmountCurency();
/** /**
......
...@@ -34,6 +34,12 @@ class Version extends \Magento\Config\Block\System\Config\Form\Field ...@@ -34,6 +34,12 @@ class Version extends \Magento\Config\Block\System\Config\Form\Field
*/ */
protected $_moduleList; protected $_moduleList;
/**
* Version constructor.
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param \Magento\Backend\Block\Template\Context $context
* @param array $data
*/
public function __construct( public function __construct(
\Magento\Framework\Module\ModuleListInterface $moduleList, \Magento\Framework\Module\ModuleListInterface $moduleList,
\Magento\Backend\Block\Template\Context $context, \Magento\Backend\Block\Template\Context $context,
...@@ -44,6 +50,10 @@ class Version extends \Magento\Config\Block\System\Config\Form\Field ...@@ -44,6 +50,10 @@ class Version extends \Magento\Config\Block\System\Config\Form\Field
$this->_moduleList = $moduleList; $this->_moduleList = $moduleList;
} }
/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{ {
return (string) $this->_moduleList->getOne("Adyen_Payment")['setup_version']; return (string) $this->_moduleList->getOne("Adyen_Payment")['setup_version'];
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
namespace Adyen\Payment\Block\Form; namespace Adyen\Payment\Block\Form;
class Cc extends \Magento\Payment\Block\Form class Cc extends \Magento\Payment\Block\Form\Cc
{ {
/** /**
* @var string * @var string
...@@ -64,14 +64,17 @@ class Cc extends \Magento\Payment\Block\Form ...@@ -64,14 +64,17 @@ class Cc extends \Magento\Payment\Block\Form
\Magento\Checkout\Model\Session $checkoutSession, \Magento\Checkout\Model\Session $checkoutSession,
array $data = [] array $data = []
) { ) {
parent::__construct($context, $data); parent::__construct($context, $paymentConfig);
$this->_paymentConfig = $paymentConfig;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_appState = $context->getAppState(); $this->_appState = $context->getAppState();
$this->_checkoutSession = $checkoutSession; $this->_checkoutSession = $checkoutSession;
} }
/**
* @return mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getCsePublicKey() public function getCsePublicKey()
{ {
// get storeId for admin // get storeId for admin
...@@ -90,62 +93,6 @@ class Cc extends \Magento\Payment\Block\Form ...@@ -90,62 +93,6 @@ class Cc extends \Magento\Payment\Block\Form
} }
return $cseKey; return $cseKey;
}
/**
* Retrieve availables credit card types
*
* @return array
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
public function getCcAvailableTypes()
{
$types = $this->_paymentConfig->getCcTypes();
if ($method = $this->getMethod()) {
$availableTypes = $method->getConfigData('cctypes');
if ($availableTypes) {
$availableTypes = explode(',', $availableTypes);
foreach ($types as $code => $name) {
if (!in_array($code, $availableTypes)) {
unset($types[$code]);
}
}
}
}
return $types;
}
/**
* Retrieve credit card expire months
*
* @return array
*/
public function getCcMonths()
{
$months = $this->getData('cc_months');
if ($months === null) {
$months[0] = __('Month');
$months = array_merge($months, $this->_paymentConfig->getMonths());
$this->setData('cc_months', $months);
}
return $months;
}
/**
* Retrieve credit card expire years
*
* @return array
*/
public function getCcYears()
{
$years = $this->getData('cc_years');
if ($years === null) {
$years = $this->_paymentConfig->getYears();
$years = [0 => __('Year')] + $years;
$this->setData('cc_years', $years);
}
return $years;
} }
/** /**
...@@ -157,7 +104,6 @@ class Cc extends \Magento\Payment\Block\Form ...@@ -157,7 +104,6 @@ class Cc extends \Magento\Payment\Block\Form
{ {
// if backend order and moto payments is turned on don't show cvc // if backend order and moto payments is turned on don't show cvc
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
$this->getCheckoutSession(); $this->getCheckoutSession();
$store = $this->_checkoutSession->getQuote()->getStore(); $store = $this->_checkoutSession->getQuote()->getStore();
$enableMoto = $this->_adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $store->getId()); $enableMoto = $this->_adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $store->getId());
...@@ -167,50 +113,4 @@ class Cc extends \Magento\Payment\Block\Form ...@@ -167,50 +113,4 @@ class Cc extends \Magento\Payment\Block\Form
} }
return true; return true;
} }
/**
* Whether switch/solo card type available
*
* @return bool
*/
public function hasSsCardType()
{
$availableTypes = explode(',', $this->getMethod()->getConfigData('cctypes'));
$ssPresenations = array_intersect(['SS', 'SM', 'SO'], $availableTypes);
if ($availableTypes && count($ssPresenations) > 0) {
return true;
}
return false;
}
/**
* Solo/switch card start year
*
* @return array
*/
public function getSsStartYears()
{
$years = [];
$first = date("Y");
for ($index = 5; $index >= 0; $index--) {
$year = $first - $index;
$years[$year] = $year;
}
$years = [0 => __('Year')] + $years;
return $years;
}
/**
* Render block HTML
*
* @return string
*/
protected function _toHtml()
{
$this->_eventManager->dispatch('payment_form_block_to_html_before', ['block' => $this]);
return parent::_toHtml();
}
} }
\ No newline at end of file
...@@ -124,18 +124,18 @@ class Json extends \Magento\Framework\App\Action\Action ...@@ -124,18 +124,18 @@ class Json extends \Magento\Framework\App\Action\Action
} }
return false; return false;
} }
/** /**
* $desc save notification into the database for cronjob to execute notificaiton * @desc save notification into the database for cronjob to execute notification
* @param $response * @param $response
* @param $notificationMode
* @return bool
* @throws \Magento\Framework\Exception\LocalizedException * @throws \Magento\Framework\Exception\LocalizedException
*/ */
protected function _processNotification($response, $notificationMode) protected function _processNotification($response, $notificationMode)
{ {
// validate the notification // validate the notification
if($this->authorised($response)) if ($this->authorised($response)) {
{
// check if notificaiton already exists // check if notificaiton already exists
if(!$this->_isDuplicate($response)) { if(!$this->_isDuplicate($response)) {
try { try {
......
...@@ -23,60 +23,10 @@ ...@@ -23,60 +23,10 @@
namespace Adyen\Payment\Logger\Handler; namespace Adyen\Payment\Logger\Handler;
use Magento\Framework\Filesystem\DriverInterface; use Magento\Framework\Logger\Handler\Base;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
class AdyenBase extends StreamHandler class AdyenBase extends Base
{ {
/**
* @var string
*/
protected $fileName;
/**
* @var int
*/
protected $loggerType = Logger::DEBUG;
/**
* @var DriverInterface
*/
protected $filesystem;
/**
* @param DriverInterface $filesystem
* @param string $filePath
*/
public function __construct(
DriverInterface $filesystem,
$filePath = null
) {
$this->filesystem = $filesystem;
parent::__construct(
$filePath ? $filePath . $this->fileName : BP . $this->fileName,
$this->loggerType
);
$this->setFormatter(new LineFormatter(null, null, true));
}
/**
* @{inheritDoc}
*
* @param $record array
* @return void
*/
public function write(array $record)
{
$logDir = $this->filesystem->getParentDirectory($this->url);
if (!$this->filesystem->isDirectory($logDir)) {
$this->filesystem->createDirectory($logDir, 0777);
}
parent::write($record);
}
/** /**
* overwrite core it needs to be the exact level otherwise use different handler * overwrite core it needs to be the exact level otherwise use different handler
* *
......
...@@ -358,14 +358,20 @@ class AdyenHppConfigProvider implements ConfigProviderInterface ...@@ -358,14 +358,20 @@ class AdyenHppConfigProvider implements ConfigProviderInterface
$hmacKey = $this->_adyenHelper->getHmac(); $hmacKey = $this->_adyenHelper->getHmac();
// create and add signature // create and add signature
$requestParams["merchantSig"] = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $requestParams); try {
$requestParams["merchantSig"] = \Adyen\Util\Util::calculateSha256Signature($hmacKey, $requestParams);
} catch (\Adyen\AdyenException $e) {
$this->_adyenLogger->error($e->getMessage());
// return empty result
return array();
}
// initialize service // initialize service
$service = new \Adyen\Service\DirectoryLookup($client); $service = new \Adyen\Service\DirectoryLookup($client);
try { try {
$responseData = $service->directoryLookup($requestParams); $responseData = $service->directoryLookup($requestParams);
}catch (Exception $e) { }catch (\Adyen\AdyenException $e) {
$this->_adyenLogger->error("The Directory Lookup response is empty check your Adyen configuration in Magento."); $this->_adyenLogger->error("The Directory Lookup response is empty check your Adyen configuration in Magento.");
// return empty result // return empty result
return array(); return array();
......
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