Magento 2 Disable Payment method for frontend only.

Magento 2 You can disable payment method for frontend only using programmatically. You can show the payment method in the admin area only and disable in the frontend area.

You need to create a simple module for disable payment method in frontend. We disable the Cash on a delivery payment method from frontend and enable the payment method in admin only.

Magento contain Magento\Payment\Model\MethodList class and Class used getAvailableMethods() function to check available method on frontend.

Now start with basic module creation, Registration.php file is to register our module.  Create the registration.php file,

Full Path,  app/code/Rbj/DisableFrontPayment/registration.php,

Create a module.xml file, Path: app/code/Rbj/DisableFrontPayment/etc/module.xml,

Now create the di.xml file for global scope,
Path: app/code/Rbj/DisableFrontPayment/etc/di.xml

Now create MethodAvailable.php file at a location.
Path: app/code/Rbj/DisableFrontPayment/Plugin/Model/Method/MethodAvailable.php

Now run the command to enable module,

php bin/magento setup:upgrade

When you check the frontend you cant see cash on delivery method.