Because I want to send Notification with response error code by Payment Gateway) when transactions are isValid. And I found the Magento\Payment\Gateway\Command\GatewayCommand do the command with Payment Gateway.
below is my app\code\My\PaymentFaildNotification\Gateway\Command\GatewayCommand.php file.
public function execute(array $commandSubject)
{
// @TODO implement exceptions catching
$transferO = $this->transferFactory->create(
$this->requestBuilder->build($commandSubject)
);
$response = $this->client->placeRequest($transferO);
if ($this->validator !== null) {
$result = $this->validator->validate(
array_merge($commandSubject, ['response' => $response])
);
if (!$result->isValid()) {
$this->doNotification($transferO->getBody(), $response)
$this->processErrors($result);
}
}
if ($this->handler) {
$this->handler->handle(
$commandSubject,
$response
);
}
}
private function doNotification($request, $result)
{
.......
}
And My app\code\My\PaymentFaildNotification\etc\di.xml is just like below:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Payment\Gateway\Command\GatewayCommand"
type="My\PaymentFaildNotification\Gateway\Command\GatewayCommand"/>
</config>
And app\code\My\PaymentFaildNotification\etc\module.xml is just like below:
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="My_PaymentFaildNotification" setup_version="1.0.2" >
<sequence>
<module name="Magento_Payment"/>
</sequence>
</module>
And app\code\My\PaymentFaildNotification\registration.php is just like below:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'My_PaymentFaildNotification',
__DIR__);
After setup:upgrade and setup:di:compile and .... It does'n work. Are there anything setting wrong ? or it can not be override with GatewayCommand ?
Thank you.