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

[PW-2199]: Add configuration to toggle order cancellation on notification processing (#692)

* [PW-2199]: New can_cancel config value that avoids all order cancellations

* [PW-2199]: Removed can_cancel check from files not related to notification processing

* [PW-2199]: Renamed config value for clarity

* [PW-2199]: Fixing adyenHelper object

* [PW-2199]: Checking config value before changing order status to NEW

* Newline at the end of Config.php

* [PW-2199]: Removing dependency on AbstractHelper
parent 45c79d64
<?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\Helper;
use Magento\Framework\App\Config\ScopeConfigInterface;
class Config
{
const XML_PAYMENT_PREFIX = "payment";
const XML_ADYEN_ABSTRACT_PREFIX = "adyen_abstract";
const XML_NOTIFICATIONS_CAN_CANCEL_FIELD = "notifications_can_cancel";
/**
* @var Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* Config constructor.
* @param Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}
/**
* Retrieve flag for notifications_can_cancel
*
* @param int $storeId
* @return bool
*/
public function getNotificationsCanCancel($storeId = null)
{
return (bool)$this->getConfigData(
self::XML_NOTIFICATIONS_CAN_CANCEL_FIELD,
self::XML_ADYEN_ABSTRACT_PREFIX,
$storeId,
true
);
}
/**
* Retrieve information from payment configuration
*
* @param string $field
* @param string $xmlPrefix
* @param int $storeId
* @param bool|false $flag
* @return bool|mixed
*/
private function getConfigData($field, $xmlPrefix, $storeId, $flag = false)
{
$path = implode("/", [self::XML_PAYMENT_PREFIX, $xmlPrefix, $field]);
if (!$flag) {
return $this->scopeConfig->getValue($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
} else {
return $this->scopeConfig->isSetFlag($path, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
}
}
}
......@@ -235,6 +235,11 @@ class Cron
*/
private $timezone;
/**
* @var \Adyen\Payment\Helper\Config
*/
protected $configHelper;
/**
* Cron constructor.
*
......@@ -282,7 +287,8 @@ class Cron
\Magento\Sales\Model\Order\Payment\Transaction\Builder $transactionBuilder,
\Magento\Framework\Serialize\SerializerInterface $serializer,
\Magento\Framework\Notification\NotifierInterface $notifierPool,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
\Adyen\Payment\Helper\Config $configHelper
) {
$this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger;
......@@ -307,6 +313,7 @@ class Cron
$this->serializer = $serializer;
$this->notifierPool = $notifierPool;
$this->timezone = $timezone;
$this->configHelper = $configHelper;
}
/**
......@@ -432,7 +439,9 @@ class Cron
$this->_eventCode == Notification::ORDER_CLOSED
) {
// Move the order from PAYMENT_REVIEW to NEW, so that can be cancelled
if ($this->_order->getState() === \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW) {
if ($this->_order->getState() === \Magento\Sales\Model\Order::STATE_PAYMENT_REVIEW &&
$this->configHelper->getNotificationsCanCancel($this->_order->getStoreId())
) {
$this->_order->setState(\Magento\Sales\Model\Order::STATE_NEW);
}
$this->_holdCancelOrder(false);
......@@ -829,6 +838,11 @@ class Cron
*/
protected function _holdCancelOrder($ignoreHasInvoice)
{
if (!$this->configHelper->getNotificationsCanCancel($this->_order->getStoreId())) {
$this->_adyenLogger->addAdyenNotificationCronjob('Order can not be canceled based on the plugin configuration');
return;
}
$orderStatus = $this->_getConfigData(
'payment_cancelled',
'adyen_abstract',
......@@ -992,7 +1006,7 @@ class Cron
break;
}
if (!$this->_order->canCancel()) {
if (!$this->_order->canCancel() && $this->configHelper->getNotificationsCanCancel($this->_order->getStoreId())) {
// Move the order from PAYMENT_REVIEW to NEW, so that can be cancelled
$this->_order->setState(\Magento\Sales\Model\Order::STATE_NEW);
}
......
......@@ -38,6 +38,7 @@
<enable_oneclick>1</enable_oneclick>
<enable_recurring>0</enable_recurring>
<group>adyen</group>
<notifications_can_cancel>1</notifications_can_cancel>
</adyen_abstract>
<adyen_cc>
<active>1</active>
......
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