Magento 2 Set Payment Method Availability for Frontend (website) vs Backend (admin)

Magento admin configuration doesn’t allow you to control if a payment method is available in just the frontend or backend (admin).

Thankfully they did offer some pre-built methods for configuring this via the codebase.

Control payment methods in Magento to – enabling and disabling for frontend or backend as needed.

If you take a look at vendor/magento/module-payment/Model/Method/AbstractMethod.php you’ll see there are several protected methods that can be set in a payment method model.

The two of these that are relevant to the topic at hand are $_canUseInternal and $_canUseCheckout

$_canUseInternal – Enable/Disable for Backend (admin)

This method specifies if the payment method is available in the Magento Admin or not.

A good example of how this is used is PayPal. The PayPal payment method is ONLY available for the customer to use on the frontend – not when placing an order in the Magento admin.

$_canUseCheckout – Enable/Disable for Frontend (website)

This method specifies if the payment method is available in the public facing frontend or not.

One example here is to accept the Check / Money Order payment method is accessible only in the Magento admin but not for public customers to use.

Example Module to Disable Check / Money Order (checkmo) on Frontend (available to Admin only)

Here is a quick example module to set the Magento default Check / Money Order (checkmo) payment method to be used in the admin only. This allows for accepting payments via check, money order, or a virtual terminal with a payment gateway but not giving this option to your customers on the frontend.

First define your module.

Then extend the payment model, setting the $_canUseCheckout method to false.

As a bonus touch, add a note in the admin on the Check / Money Order settings section that this change has been made.

Lastly, you just need to tell Magneto to install this module.

And that’s it. Now the Check / Money Order (checkmo) payment method will no longer be available on the frontend but will work without issue in the admin.