I want to show Check/Money order Payment Method only for admin not for the website customers, how to achieve using can_use_internal. I am just trying Event observer
Event Observer:
app/code/Gta/AdminPay/etc/events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="payment_method_is_active">
<observer name="payment_only_for_admin" instance="\Gta\AdminPay\Observer\PaymentMethodAvailable" />
</event>
</config>
app/code/Gta/AdminPay/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Gta_AdminPay" setup_version="1.0.1"></module>
</config>
app/code/Gta/AdminPay/Observer/PaymentMethodAvailable.php
<?php
namespace Gta\AdminPay\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;
class PaymentMethodAvailable implements ObserverInterface
{
public function __construct(\Psr\Log\LoggerInterface $logger
)
{
$this->_logger = $logger;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$result = $observer->getEvent()->getResult();
$method_instance = $observer->getEvent()->getMethodInstance();
$quote = $observer->getEvent()->getQuote();
$this->_logger->info($method_instance->getCode());
if ($method_instance->getCode() == 'checkmo') {
$result->setData('is_available', false);
}
else
{
$result->setData('is_available', true);
}
}
}
app/code/Gta/AdminPay/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Gta_AdminPay',
__DIR__
);
Note: Hiding both frontend & backend, how to visible only on the backend?
Source : Thank you Divya Sekar