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

Remove Cron controller should not be accessable from browser,

 remove exti and die statements what is not allowed, changed reservered PHP7 name resource to resourceModel following magento conventions and fix to use the right exeption class
parent 80266bd7
......@@ -34,7 +34,7 @@ class AbstractInfo extends \Magento\Payment\Block\Info
protected $_adyenHelper;
/**
* @var \Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory
* @var \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory
*/
protected $_adyenOrderPaymentCollectionFactory;
......@@ -42,13 +42,13 @@ class AbstractInfo extends \Magento\Payment\Block\Info
* AbstractInfo constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
* @param \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
* @param Template\Context $context
* @param array $data
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
\Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
Template\Context $context,
array $data = []
)
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Controller\Process;
use Symfony\Component\Config\Definition\Exception\Exception;
/**
* Class Json
* @package Adyen\Payment\Controller\Process
*/
class Cron extends \Magento\Framework\App\Action\Action
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
protected $_objectManager;
/**
* @var \Magento\Framework\Controller\Result\RawFactory
*/
protected $_resultFactory;
/**
* Cron constructor.
*
* @param \Magento\Framework\App\Action\Context $context
*/
public function __construct(
\Magento\Framework\App\Action\Context $context
) {
parent::__construct($context);
$this->_objectManager = $context->getObjectManager();
$this->_resultFactory = $context->getResultFactory();
}
/**
* Process Notification from Cron
*/
public function execute()
{
$cron = $this->_objectManager->create('Adyen\Payment\Model\Cron');
$cron->processNotification();
die();
}
}
\ No newline at end of file
......@@ -62,7 +62,8 @@ class Json extends \Magento\Framework\App\Action\Action
\Magento\Framework\App\Action\Context $context,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger
) {
)
{
parent::__construct($context);
$this->_objectManager = $context->getObjectManager();
$this->_resultFactory = $context->getResultFactory();
......@@ -100,6 +101,8 @@ class Json extends \Magento\Framework\App\Action\Action
if ($notificationMode != "" && $this->_validateNotificationMode($notificationMode)) {
foreach ($notificationItems['notificationItems'] as $notificationItem) {
$status = $this->_processNotification(
$notificationItem['NotificationRequestItem'], $notificationMode
);
......@@ -108,9 +111,10 @@ class Json extends \Magento\Framework\App\Action\Action
$this->_return401();
return;
}
}
$acceptedMessage = "[accepted]";
}
$cronCheckTest = $notificationItems['notificationItems'][0]['NotificationRequestItem']['pspReference'];
// Run the query for checking unprocessed notifications, do this only for test notifications coming from the Adyen Customer Area
......@@ -247,8 +251,7 @@ class Json extends \Magento\Framework\App\Action\Action
if (empty($submitedMerchantAccount) && empty($internalMerchantAccount)) {
if ($this->_isTestNotification($response['pspReference'])) {
echo 'merchantAccountCode is empty in magento settings';
exit();
$this->_returnResult('merchantAccountCode is empty in magento settings');
}
return false;
}
......@@ -256,8 +259,9 @@ class Json extends \Magento\Framework\App\Action\Action
// validate username and password
if ((!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW']))) {
if ($this->_isTestNotification($response['pspReference'])) {
echo 'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode';
exit();
$this->_returnResult(
'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode'
);
}
return false;
}
......@@ -275,11 +279,11 @@ class Json extends \Magento\Framework\App\Action\Action
// If notification is test check if fields are correct if not return error
if ($this->_isTestNotification($response['pspReference'])) {
if ($accountCmp != 0) {
echo 'MerchantAccount in notification is not the same as in Magento settings';
exit();
$this->_returnResult('MerchantAccount in notification is not the same as in Magento settings');
} elseif ($usernameCmp != 0 || $passwordCmp != 0) {
echo 'username (PHP_AUTH_USER) and\or password (PHP_AUTH_PW) are not the same as Magento settings';
exit();
$this->_returnResult(
'username (PHP_AUTH_USER) and\or password (PHP_AUTH_PW) are not the same as Magento settings'
);
}
}
return false;
......@@ -356,4 +360,18 @@ class Json extends \Magento\Framework\App\Action\Action
return false;
}
}
/**
* Returns the message to the browser
*
* @param $message
*/
protected function _returnResult($message)
{
$this->getResponse()
->clearHeader('Content-Type')
->setHeader('Content-Type', 'text/html')
->setBody($message);
return;
}
}
\ No newline at end of file
......@@ -37,18 +37,18 @@ class RefundDataBuilder implements BuilderInterface
private $adyenHelper;
/**
* @var \Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory
* @var \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory
*/
private $orderPaymentCollectionFactory;
/**
* RefundDataBuilder constructor.
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory $orderPaymentCollectionFactory
* @param \Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $orderPaymentCollectionFactory
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory $orderPaymentCollectionFactory
\Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $orderPaymentCollectionFactory
)
{
$this->adyenHelper = $adyenHelper;
......
......@@ -55,7 +55,7 @@ class Data extends AbstractHelper
protected $_moduleList;
/**
* @var \Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory
* @var \Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory
*/
protected $_billingAgreementCollectionFactory;
......@@ -69,6 +69,11 @@ class Data extends AbstractHelper
*/
protected $_assetSource;
/**
* @var \Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory
*/
protected $_notificationFactory;
/**
* Data constructor.
*
......@@ -77,7 +82,7 @@ class Data extends AbstractHelper
* @param \Magento\Framework\Config\DataInterface $dataStorage
* @param \Magento\Directory\Model\Config\Source\Country $country
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param \Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param \Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param \Magento\Framework\View\Asset\Repository $assetRepo
* @param \Magento\Framework\View\Asset\Source $assetSource
*/
......@@ -87,10 +92,10 @@ class Data extends AbstractHelper
\Magento\Framework\Config\DataInterface $dataStorage,
\Magento\Directory\Model\Config\Source\Country $country,
\Magento\Framework\Module\ModuleListInterface $moduleList,
\Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory,
\Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory,
\Magento\Framework\View\Asset\Repository $assetRepo,
\Magento\Framework\View\Asset\Source $assetSource,
\Adyen\Payment\Model\Resource\Notification\CollectionFactory $notificationFactory
\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory $notificationFactory
)
{
parent::__construct($context);
......
......@@ -41,7 +41,7 @@ class Cron
protected $_logger;
/**
* @var Resource\Notification\CollectionFactory
* @var ResourceModel\Notification\CollectionFactory
*/
protected $_notificationFactory;
......@@ -88,7 +88,7 @@ class Cron
protected $_billingAgreementFactory;
/**
* @var Resource\Billing\Agreement\CollectionFactory
* @var ResourceModel\Billing\Agreement\CollectionFactory
*/
protected $_billingAgreementCollectionFactory;
......@@ -168,7 +168,7 @@ class Cron
protected $_adyenOrderPaymentFactory;
/**
* @var Resource\Order\Payment\CollectionFactory
* @var ResourceModel\Order\Payment\CollectionFactory
*/
protected $_adyenOrderPaymentCollectionFactory;
......@@ -182,33 +182,33 @@ class Cron
*
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param Resource\Notification\CollectionFactory $notificationFactory
* @param ResourceModel\Notification\CollectionFactory $notificationFactory
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param OrderSender $orderSender
* @param InvoiceSender $invoiceSender
* @param \Magento\Framework\DB\TransactionFactory $transactionFactory
* @param Billing\AgreementFactory $billingAgreementFactory
* @param Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory
* @param Api\PaymentRequest $paymentRequest
* @param Order\PaymentFactory $adyenOrderPaymentFactory
* @param Resource\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
* @param ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory
* @param AreaList $areaList
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Model\Resource\Notification\CollectionFactory $notificationFactory,
\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory $notificationFactory,
\Magento\Sales\Model\OrderFactory $orderFactory,
\Adyen\Payment\Helper\Data $adyenHelper,
OrderSender $orderSender,
InvoiceSender $invoiceSender,
\Magento\Framework\DB\TransactionFactory $transactionFactory,
\Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory,
\Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory,
\Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory $billingAgreementCollectionFactory,
\Adyen\Payment\Model\Api\PaymentRequest $paymentRequest,
\Adyen\Payment\Model\Order\PaymentFactory $adyenOrderPaymentFactory,
\Adyen\Payment\Model\Resource\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
\Adyen\Payment\Model\ResourceModel\Order\Payment\CollectionFactory $adyenOrderPaymentCollectionFactory,
AreaList $areaList
) {
$this->_scopeConfig = $scopeConfig;
......
......@@ -96,7 +96,7 @@ class Adapter extends Method\Adapter
$agreement->getCustomerReference(),
$agreement->getStoreId()
);
} catch(Exception $e) {
} catch(\Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException(__('Failed to disable this contract'));
}
}
......
......@@ -76,7 +76,7 @@ class Notification extends \Magento\Framework\Model\AbstractModel
*/
protected function _construct()
{
$this->_init('Adyen\Payment\Model\Resource\Notification');
$this->_init('Adyen\Payment\Model\ResourceModel\Notification');
}
/**
......
......@@ -55,7 +55,7 @@ class Payment extends \Magento\Framework\Model\AbstractModel
*/
protected function _construct()
{
$this->_init('Adyen\Payment\Model\Resource\Order\Payment');
$this->_init('Adyen\Payment\Model\ResourceModel\Order\Payment');
}
/**
......
......@@ -21,7 +21,7 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Resource\Billing;
namespace Adyen\Payment\Model\ResourceModel\Billing;
/**
* Billing agreement resource model
......
......@@ -21,7 +21,7 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Resource\Billing\Agreement;
namespace Adyen\Payment\Model\ResourceModel\Billing\Agreement;
/**
* Billing agreements resource collection
......
......@@ -21,7 +21,7 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Resource;
namespace Adyen\Payment\Model\ResourceModel;
class Notification extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
......
......@@ -21,7 +21,7 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Resource\Notification;
namespace Adyen\Payment\Model\ResourceModel\Notification;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
......@@ -30,7 +30,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
*/
public function _construct()
{
$this->_init('Adyen\Payment\Model\Notification', 'Adyen\Payment\Model\Resource\Notification');
$this->_init('Adyen\Payment\Model\Notification', 'Adyen\Payment\Model\ResourceModel\Notification');
}
/**
......
......@@ -21,7 +21,7 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Resource\Order;
namespace Adyen\Payment\Model\ResourceModel\Order;
class Payment extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
......
......@@ -21,7 +21,7 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model\Resource\Order\Payment;
namespace Adyen\Payment\Model\ResourceModel\Order\Payment;
/**
* Billing agreements resource collection
......@@ -36,7 +36,7 @@ class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\Ab
*/
protected function _construct()
{
$this->_init('Adyen\Payment\Model\Order\Payment', 'Adyen\Payment\Model\Resource\Order\Payment');
$this->_init('Adyen\Payment\Model\Order\Payment', 'Adyen\Payment\Model\ResourceModel\Order\Payment');
}
/**
......
......@@ -44,10 +44,10 @@ class DataTest extends TestCase
$dataStorage = $this->getSimpleMock('\Magento\Framework\Config\DataInterface');
$country = $this->getSimpleMock('\Magento\Directory\Model\Config\Source\Country');
$moduleList = $this->getSimpleMock('\Magento\Framework\Module\ModuleListInterface');
$billingAgreementCollectionFactory = $this->getSimpleMock('\Adyen\Payment\Model\Resource\Billing\Agreement\CollectionFactory');
$billingAgreementCollectionFactory = $this->getSimpleMock('\Adyen\Payment\Model\ResourceModel\Billing\Agreement\CollectionFactory');
$assetRepo = $this->getSimpleMock('\Magento\Framework\View\Asset\Repository');
$assetSource = $this->getSimpleMock('\Magento\Framework\View\Asset\Source');
$notificationFactory = $this->getSimpleMock('\Adyen\Payment\Model\Resource\Notification\CollectionFactory');
$notificationFactory = $this->getSimpleMock('\Adyen\Payment\Model\ResourceModel\Notification\CollectionFactory');
$this->dataHelper = new Data($context, $encryptor, $dataStorage, $country, $moduleList,
$billingAgreementCollectionFactory, $assetRepo, $assetSource, $notificationFactory);
......
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