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 04e48bfb authored by Ángel Campos's avatar Ángel Campos Committed by GitHub

[PW-1942] Notifications Overview (#639)

* [PW-1942]: Admin notifications overview for adyen_notification table

* [PW-1942]: Added notifications overview link to cron information message

* [PW-1942]: Added notifications overview link to cron information message

* [PW-1942]: Adjusted columns, filters and formatting on notifications overview
Moved PSP search URL function to helper since it is now being used in multiple places

* [PW-1942]: Changed virtualType classname to avoid conflicts with Notifications Collection

* [PW-1942]: Implemented getPspReferenceSearchUrl() from library

* [PW-1942]: Unit testing

* [PW-1942]: Applying recommended changes:
* Renamed XML files to adyen_notifications_overview
* Applied PSR2 code styling to CronMessage.php
* Updated Copyright year
* Early return and replaced switch with if and default value in NotificationColumn.php. Also, docs state that success can only be true/false so got rid of third CSS class
* Moved getPspReferenceSearchUrl() method from PHP Lib to Data helper, and added if/else to receive liveEnvironment from notification record instead of receiving test/live string

* [PW-1942]: Code styling

* [PW-1942]: Applying recommended changes:
* Inverted live/test if check
* Removed unnecessary constructor
Co-authored-by: default avatarcyattilakiss <42297201+cyattilakiss@users.noreply.github.com>
parent a510e037
......@@ -31,17 +31,20 @@ class CronMessage implements \Magento\Framework\Notification\MessageInterface
protected $_dateChecked;
protected $_adyenHelper;
protected $_timezoneInterface;
protected $backendHelper;
public function __construct(
\Magento\Backend\Model\Auth\Session $authSession,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezoneInterface
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezoneInterface,
\Magento\Backend\Helper\Data $backendHelper
) {
$this->_authSession = $authSession;
$this->_cronCheck = $this->getSessionData("cronCheck");
$this->_dateChecked = $this->getSessionData("dateChecked");
$this->_adyenHelper = $adyenHelper;
$this->_timezoneInterface = $timezoneInterface;
$this->backendHelper = $backendHelper;
}
/**
......@@ -89,7 +92,8 @@ class CronMessage implements \Magento\Framework\Notification\MessageInterface
*/
public function getText()
{
$message = __('You have ' . $this->_cronCheck . ' unprocessed notification(s). Please check your Cron');
$urlNotificationsOverview = $this->backendHelper->getUrl("adyen/NotificationsOverview/index");
$message = __('You have <a href="%1">%2 unprocessed notification(s)</a>. Please check your Cron', $urlNotificationsOverview, $this->_cronCheck);
$urlMagento = "http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.html";
$urlAdyen = "https://docs.adyen.com/developers/plugins/magento-2/set-up-the-plugin-in-magento#step2runcron";
$message .= __(
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Controller\Adminhtml\Notifications;
class Overview extends \Magento\Backend\App\Action
{
/**
* Load the page defined in corresponding layout XML
*
* @return \Magento\Framework\View\Result\Page
*/
public function execute()
{
$resultPage = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_PAGE);
$resultPage->setActiveMenu('Adyen_Payment::notifications_overview')
->getConfig()->getTitle()->prepend(__('Adyen Notifications Overview'));
return $resultPage;
}
}
\ No newline at end of file
......@@ -1853,4 +1853,27 @@ class Data extends AbstractHelper
return $localeCode;
}
/**
* Get the Customer Area PSP Search URL with a preset PSP Reference
*
* @param string $pspReference
* @param string $liveEnvironment
* @return string
*/
public function getPspReferenceSearchUrl($pspReference, $liveEnvironment)
{
if ($liveEnvironment === "true") {
$checkoutEnvironment = "live";
} else {
$checkoutEnvironment = "test";
}
return sprintf(
"https://ca-%s.adyen.com/ca/ca/accounts/showTx.shtml?pspReference=%s",
$checkoutEnvironment,
$pspReference
);
}
}
......@@ -1886,11 +1886,13 @@ class Cron
*
* @return void
*/
protected function addRefundFailedNotice(){
protected function addRefundFailedNotice()
{
$this->notifierPool->addNotice(
__("Adyen: Refund for order #%1 has failed", $this->_merchantReference),
__("Reason: %1 | PSPReference: %2 | You can go to Adyen Customer Area and trigger this refund manually or contact our support.", $this->_reason, $this->_pspReference),
sprintf("https://ca-%s.adyen.com/ca/ca/accounts/showTx.shtml?pspReference=%s", $this->_live === 'true' ? 'live' : 'test', $this->_pspReference)
__("Reason: %1 | PSPReference: %2 | You can go to Adyen Customer Area and trigger this refund manually or contact our support.",
$this->_reason, $this->_pspReference),
$this->_adyenHelper->getPspReferenceSearchUrl($this->_pspReference, $this->_live)
);
}
}
......@@ -105,4 +105,33 @@ class DataTest extends \PHPUnit\Framework\TestCase
$this->assertEquals(false, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('ideal'));
$this->assertEquals(true, $this->dataHelper->isPaymentMethodOpenInvoiceMethod('test_klarna'));
}
/**
* @param string $expectedResult
* @param string $pspReference
* @param string $checkoutEnvironment
* @dataProvider checkoutEnvironmentsProvider
*
*/
public function testGetPspReferenceSearchUrl($expectedResult, $pspReference, $checkoutEnvironment)
{
$pspSearchUrl = $this->dataHelper->getPspReferenceSearchUrl($pspReference, $checkoutEnvironment);
$this->assertEquals($expectedResult, $pspSearchUrl);
}
public static function checkoutEnvironmentsProvider()
{
return array(
array(
'https://ca-test.adyen.com/ca/ca/accounts/showTx.shtml?pspReference=7914073381342284',
'7914073381342284',
'false'
),
array(
'https://ca-live.adyen.com/ca/ca/accounts/showTx.shtml?pspReference=883580976999434D',
'883580976999434D',
'true'
)
);
}
}
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Ui\Component\Listing\Column;
class NotificationColumn extends \Magento\Ui\Component\Listing\Columns\Column
{
/**
* @var \Magento\Sales\Api\Data\OrderInterface
*/
protected $orderInterface;
/**
* @var \Magento\Backend\Helper\Data
*/
protected $backendHelper;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $adyenHelper;
public function __construct(
\Magento\Sales\Api\Data\OrderInterface $orderInterface,
\Magento\Backend\Helper\Data $backendHelper,
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\View\Element\UiComponent\ContextInterface $context,
\Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory,
array $components = [],
array $data = []
) {
$this->orderInterface = $orderInterface;
$this->backendHelper = $backendHelper;
$this->adyenHelper = $adyenHelper;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
/**
* Style and format Adyen notification columns
*
* @param array $dataSource
* @return array
*/
public function prepareDataSource(array $dataSource)
{
if (empty($dataSource['data']['items'])) {
return $dataSource;
}
foreach ($dataSource['data']['items'] as & $item) {
$class = "grid-severity-critical";
if ($item["success"] == "true") {
$class = "grid-severity-notice";
}
$item["success"] = sprintf('<span class="%s">%s</span>', $class, $item["success"]);
//Setting Status "fake" column value based on processing and done values
if ($item["processing"] == 0) {
if ($item["done"] == 0) {
$item["status"] = __("Queued");
} else {
$item["status"] = __("Processed");
}
} else {
$item["status"] = __("In progress");
}
//Adding anchor link to order number and PSP reference if order number exists
$this->orderInterface->unsetData();
$order = $this->orderInterface->loadByIncrementId($item["merchant_reference"]);
if ($order->getId()) {
$orderUrl = $this->backendHelper->getUrl("sales/order/view", ["order_id" => $order->getId()]);
$item["merchant_reference"] = sprintf(
'<a href="%s">%s</a>',
$orderUrl,
$item["merchant_reference"]
);
$item["pspreference"] = sprintf(
'<a href="%s" target="_blank">%s</a>',
$this->adyenHelper->getPspReferenceSearchUrl(
$item["pspreference"],
$item["live"]
),
$item["pspreference"]
);
}
}
return $dataSource;
}
}
\ No newline at end of file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Backend/etc/menu.xsd">
<menu>
<add id="Adyen_Payment::adyen" title="Adyen" module="Adyen_Payment" sortOrder="100" parent="Magento_Backend::system" resource="Adyen_Payment::adyen"/>
<add id="Adyen_Payment::notifications_overview" title="Notifications Overview" module="Adyen_Payment" sortOrder="10" parent="Adyen_Payment::adyen" action="adyen/notifications/overview" resource="Adyen_Payment::notifications_overview"/>
</menu>
</config>
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="admin">
<route id="adyen" frontName="adyen">
<module name="Adyen_Payment"/>
</route>
</router>
</config>
......@@ -1035,4 +1035,20 @@
<type name="Magento\Checkout\Api\GuestPaymentInformationManagementInterface">
<plugin name="AdyenGuestPaymentInformationManagementAddPaymentInfo" type="Adyen\Payment\Plugin\GuestPaymentInformationManagement" sortOrder="10"/>
</type>
<!--Notifications overview-->
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="adyen_notifications_overview_data_source" xsi:type="string">Adyen\Payment\Model\ResourceModel\Notification\UiComponentCollection</item>
</argument>
</arguments>
</type>
<virtualType name="Adyen\Payment\Model\ResourceModel\Notification\UiComponentCollection" type="Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult">
<arguments>
<argument name="mainTable" xsi:type="string">adyen_notification</argument>
<argument name="resourceModel" xsi:type="string">Adyen\Payment\Model\ResourceModel\Notification</argument>
</arguments>
</virtualType>
</config>
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<title>
Adyen Notifications Overview
</title>
</head>
<body>
<referenceContainer name="content">
<uiComponent name="adyen_notifications_overview"/>
</referenceContainer>
</body>
</page>
\ No newline at end of file
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<argument name="data" xsi:type="array">
<item name="js_config" xsi:type="array">
<item name="provider" xsi:type="string">adyen_notifications_overview.adyen_notifications_overview_data_source</item>
<item name="deps" xsi:type="string">adyen_notifications_overview.adyen_notifications_overview_data_source</item>
</item>
<item name="spinner" xsi:type="string">spinner_columns</item>
</argument>
<listingToolbar name="listing_top">
<columnsControls name="columns_controls"/>
<paging name="listing_paging"/>
<filters name="listing_filters" />
</listingToolbar>
<dataSource name="nameOfDataSource">
<argument name="dataProvider" xsi:type="configurableObject">
<argument name="class" xsi:type="string">Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider</argument>
<argument name="name" xsi:type="string">adyen_notifications_overview_data_source</argument>
<argument name="primaryFieldName" xsi:type="string">entity_id</argument>
<argument name="requestFieldName" xsi:type="string">id</argument>
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/provider</item>
<item name="update_url" xsi:type="url" path="mui/index/render"/>
<item name="storageConfig" xsi:type="array">
<item name="indexField" xsi:type="string">entity_id</item>
</item>
</item>
</argument>
</argument>
</dataSource>
<columns name="spinner_columns">
<column name="entity_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">textRange</item>
<item name="sorting" xsi:type="string">desc</item>
<item name="label" xsi:type="string" translate="true">ID</item>
</item>
</argument>
</column>
<column name="processing">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Yesno</item>
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
<item name="filter" xsi:type="string">select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="editor" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Processing</item>
</item>
</argument>
</column>
<column name="done">
<argument name="data" xsi:type="array">
<item name="options" xsi:type="object">Magento\Config\Model\Config\Source\Yesno</item>
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/select</item>
<item name="filter" xsi:type="string">select</item>
<item name="dataType" xsi:type="string">select</item>
<item name="editor" xsi:type="string">select</item>
<item name="label" xsi:type="string" translate="true">Done</item>
</item>
</argument>
</column>
<column name="status" class="Adyen\Payment\Ui\Component\Listing\Column\NotificationColumn">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Status</item>
<item name="sortable" xsi:type="boolean">false</item>
</item>
</argument>
</column>
<column name="success">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">true</item>
<item name="label" xsi:type="string" translate="true">Success</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
<column name="pspreference">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">PSP Reference</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
<column name="event_code">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Event Code</item>
</item>
</argument>
</column>
<column name="merchant_reference">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">Order</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
<column name="created_at" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">dateRange</item>
<item name="label" xsi:type="string" translate="true">Creation Date</item>
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="dataType" xsi:type="string">date</item>
</item>
</argument>
</column>
</columns>
</listing>
\ 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