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

[PW 1949]: Notifications error_count and error_message (#645)

* [PW-1949]: Added Notification error count and message columns to adyen_notification and Notification Overview
* Upgrade script to add new columns, changing setup_version
* New columns in UI Component
* Adjusted collection so notifications with 5 errors do not get processed (DB column reset required. Reset functionality here https://youtrack.is.adyen.com/issue/PW-2103)
* ACL for menu element

* [PW-1949]: Error message column formatting

* [PW-1949]: Code styling

* [PW-1949]: Code styling

* Changing protected method to private Model/Cron.php
Co-Authored-By: default avatarMarcos Garcia <marcos.asgarcia@gmail.com>

* Changing protected method to private Model/Cron.php
Co-Authored-By: default avatarMarcos Garcia <marcos.asgarcia@gmail.com>

* Changing protected method to private Model/Cron.php
Co-Authored-By: default avatarMarcos Garcia <marcos.asgarcia@gmail.com>

* Updating release version
Co-Authored-By: default avatarcyattilakiss <42297201+cyattilakiss@users.noreply.github.com>

* Updating release version
Co-authored-by: default avatarMarcos Garcia <marcos.asgarcia@gmail.com>
Co-authored-by: default avatarcyattilakiss <42297201+cyattilakiss@users.noreply.github.com>
parent 04e48bfb
......@@ -81,6 +81,18 @@ interface NotificationInterface
* Additional data
*/
const ADDITIONAL_DATA = 'additional_data';
/*
* Processing
*/
const PROCESSING = 'processing';
/*
* Error count
*/
const ERROR_COUNT = 'error_count';
/*
* Error message
*/
const ERROR_MESSAGE = 'error_message';
/*
* Created-at timestamp.
*/
......
......@@ -230,6 +230,11 @@ class Cron
*/
private $notifierPool;
/**
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
*/
private $timezone;
/**
* Cron constructor.
*
......@@ -276,7 +281,8 @@ class Cron
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel,
\Magento\Sales\Model\Order\Payment\Transaction\Builder $transactionBuilder,
\Magento\Framework\Serialize\SerializerInterface $serializer,
\Magento\Framework\Notification\NotifierInterface $notifierPool
\Magento\Framework\Notification\NotifierInterface $notifierPool,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
) {
$this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger;
......@@ -300,6 +306,7 @@ class Cron
$this->transactionBuilder = $transactionBuilder;
$this->serializer = $serializer;
$this->notifierPool = $notifierPool;
$this->timezone = $timezone;
}
/**
......@@ -339,6 +346,7 @@ class Cron
$notifications->addFieldToFilter('done', 0);
$notifications->addFieldToFilter('processing', 0);
$notifications->addFieldToFilter('created_at', $dateRange);
$notifications->addFieldToFilter('error_count', ['lt' => Notification::MAX_ERROR_COUNT]);
foreach ($notifications as $notification) {
// set Cron processing to true
......@@ -464,6 +472,7 @@ class Cron
++$count;
} catch (\Exception $e) {
$this->_updateNotification($notification, false, false);
$this->handleNotificationError($notification, $e->getMessage());
$this->_adyenLogger->addAdyenNotificationCronjob(
sprintf("Notification %s had an error: %s \n %s", $notification->getEntityId(), $e->getMessage(),
$e->getTraceAsString())
......@@ -1895,4 +1904,54 @@ class Cron
$this->_adyenHelper->getPspReferenceSearchUrl($this->_pspReference, $this->_live)
);
}
/**
* Add/update info on notification processing errors
*
* @param \Adyen\Payment\Model\Notification $notification
* @param string $errorMessage
* @return void
*/
private function handleNotificationError($notification, $errorMessage)
{
$this->setNotificationError($notification, $errorMessage);
$this->addNotificationErrorComment($errorMessage);
}
/**
* Increases error count and appends error message to notification
*
* @param \Adyen\Payment\Model\Notification $notification
* @param string $errorMessage
* @return void
*/
private function setNotificationError($notification, $errorMessage)
{
$notification->setErrorCount($notification->getErrorCount() + 1);
$oldMessage = $notification->getErrorMessage();
$newMessage = sprintf(
"[%s]: %s",
$this->timezone->formatDateTime($notification->getUpdatedAt()),
$errorMessage
);
if (empty($oldMessage)) {
$notification->setErrorMessage($newMessage);
} else {
$notification->setErrorMessage($oldMessage . "\n" . $newMessage);
}
$notification->save();
}
/**
* Adds a comment to the order history with the notification processing error
*
* @param string $errorMessage
* @return void
*/
private function addNotificationErrorComment($errorMessage)
{
$comment = __('The order failed to update: %1', $errorMessage);
$this->_order->addStatusHistoryComment($comment);
$this->_order->save();
}
}
......@@ -49,6 +49,7 @@ class Notification extends \Magento\Framework\Model\AbstractModel implements Not
const REPORT_AVAILABLE = "REPORT_AVAILABLE";
const ORDER_CLOSED = "ORDER_CLOSED";
const OFFER_CLOSED = "OFFER_CLOSED";
const MAX_ERROR_COUNT = 5;
/**
* Notification constructor.
......@@ -94,7 +95,7 @@ class Notification extends \Magento\Framework\Model\AbstractModel implements Not
$result = $this->getResource()->getNotification($pspReference, $eventCode, $success, $originalReference, $done);
return (empty($result)) ? false : true;
}
/**
* @return mixed
*/
......@@ -359,6 +360,69 @@ class Notification extends \Magento\Framework\Model\AbstractModel implements Not
return $this->setData(self::DONE, $done);
}
/**
* Gets the Processing flag for the notification.
*
* @return bool Processing.
*/
public function getProcessing()
{
return $this->getData(self::PROCESSING);
}
/**
* Sets Processing flag.
*
* @param bool $processing
* @return $this
*/
public function setProcessing($processing)
{
return $this->setData(self::PROCESSING, $processing);
}
/**
* Gets the Error Count for the notification.
*
* @return bool|null ErrorCount.
*/
public function getErrorCount()
{
return $this->getData(self::ERROR_COUNT);
}
/**
* Sets Error Count.
*
* @param bool $errorCount
* @return $this
*/
public function setErrorCount($errorCount)
{
return $this->setData(self::ERROR_COUNT, $errorCount);
}
/**
* Gets the Error Message for the notification.
*
* @return string|null ErrorMessage
*/
public function getErrorMessage()
{
return $this->getData(self::ERROR_MESSAGE);
}
/**
* Sets Error Message.
*
* @param string $errorMessage
* @return $this
*/
public function setErrorMessage($errorMessage)
{
return $this->setData(self::ERROR_MESSAGE, $errorMessage);
}
/**
* Gets the created-at timestamp for the notification.
*
......
......@@ -68,6 +68,10 @@ class UpgradeSchema implements UpgradeSchemaInterface
$this->updateSchemaVersion221($setup);
}
if (version_compare($context->getVersion(), '5.4.0', '<')) {
$this->updateSchemaVersion540($setup);
}
$setup->endSetup();
}
......@@ -359,4 +363,46 @@ class UpgradeSchema implements UpgradeSchemaInterface
$setup->getConnection()->createTable($table);
}
/**
* Upgrade to 5.4.0
*
* @param SchemaSetupInterface $setup
* @return void
*/
public function updateSchemaVersion540(SchemaSetupInterface $setup)
{
$connection = $setup->getConnection();
$tableName = $setup->getTable('adyen_notification');
$adyenNotificationErrorCountColumn = [
'type' => Table::TYPE_INTEGER,
'length' => 1,
'nullable' => true,
'default' => 0,
'comment' => 'Adyen Notification Process Error Count',
'after' => \Adyen\Payment\Model\Notification::PROCESSING
];
$adyenNotificationErrorMessageColumn = [
'type' => Table::TYPE_TEXT,
'length' => null,
'nullable' => true,
'default' => null,
'comment' => 'Adyen Notification Process Error Message',
'after' => \Adyen\Payment\Model\Notification::ERROR_COUNT
];
$connection->addColumn(
$tableName,
\Adyen\Payment\Model\Notification::ERROR_COUNT,
$adyenNotificationErrorCountColumn
);
$connection->addColumn(
$tableName,
\Adyen\Payment\Model\Notification::ERROR_MESSAGE,
$adyenNotificationErrorMessageColumn
);
}
}
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_Backend::system">
<resource id="Adyen_Payment::adyen" title="Adyen" translate="title" sortOrder="10">
<resource id="Adyen_Payment::notifications_overview" title="Notifications Overview" translate="title" sortOrder="10"/>
</resource>
</resource>
</resource>
</resources>
</acl>
</config>
\ No newline at end of file
......@@ -24,7 +24,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Adyen_Payment" setup_version="4.5.4">
<module name="Adyen_Payment" setup_version="5.4.0">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Quote"/>
......
<?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>
<css src="Adyen_Payment::css/notifications_overview_styles.css"/>
<title>
Adyen Notifications Overview
</title>
......
......@@ -105,6 +105,27 @@
</item>
</argument>
</column>
<column name="error_count">
<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">Error Count</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
<column name="error_message">
<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">Error Message</item>
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
<item name="fieldClass" xsi:type="string">adyen-notification-error-messages</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">
......
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* 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>
*/
.adyen-notification-error-messages div {
white-space: pre-wrap;
}
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