We have only one online payment service for the customer, how to enable bank transfer only for admin order creation?
-
do u want to enable a bank transfer payment method in frontend or backend – Divya Sekar Oct 2 '20 at 5:24
-
Backend only not for Customer – zus Oct 2 '20 at 5:27
To enable a "payment method" only for admin can you please refer the below link
Magento2: How to add a payment method to admin create order?
https://blog.e-zest.com/making-payment-method-visible-only-for-admin-in-magento-2
It's worked for me, Try the below one
app/code/Gta/AdminPay/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Gta_AdminPay',
__DIR__
);
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/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="gta_payment_filters" instance="\Gta\AdminPay\Observer\PaymentMethodAvailable" />
</event>
</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());
/* Enable All payment gateway exclude Your payment Gateway*/
if ($method_instance->getCode() == 'checkmo') {
$result->setData('is_available', false);
}
else
{
$result->setData('is_available', true);
}
}
}
-
The first point you shared second solution which file i need to edit for bank transfer – zus Oct 2 '20 at 5:52
-
-
After creating the module and enable Check / Money Order, It's showing on frond-end also. My module : app/code/Gta/AdminPay/etc/di.xml => justpaste.it/9jtbn, app/code/Gta/AdminPay/etc/module.xml => justpaste.it/2pupr, app/code/Gta/AdminPay/registration.php => justpaste.it/24mph, app/code/Gta/AdminPay/Plugin/Payment/Method/Checkmo/Available.php => justpaste.it/96fs0 Anything else i missed out? – zus Oct 2 '20 at 8:36
-
After running the upgrade and static content deploy command still Check / Money Order display on front-end – zus Oct 2 '20 at 9:21
-
If you need a payment option that is only available internally (admin area), we created an extension for that https://github.com/customgento/module-admin-payment-m2.