I found two things that can cause this to happen.
The first thing to check is that the configuration option group in etc/adminhtml/system.xml
matches the name of the payment method in etc/payment.xml
For example, your files might look like this:
etc/payment.xml
<?xml version="1.0"?>
<payment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Payment:etc/payment.xsd">
<groups>
<group id="mymethodgroup">
<label>My payment group</label>
</group>
</groups>
<methods>
<!-- NOTE: method is called 'mymethodname' -->
<method name="mymethodname">
<allow_multiple_address>0</allow_multiple_address>
</method>
</methods>
</payment>
etc/adminhtml/system.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="payment">
<!-- NOTE the group id here matches the method name in etc/payment.xml -->
<group id="mymethodname" translate="label" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>My payment method</label>
<field id="active" translate="label" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
...
The second thing to check is that the etc/adminhtml/system.xml
defines the active
option in the correct place. Initially I had this inside a sub-group. This will not work. It must be at the top level. See the following example.
Example of a BAD etc/adminhtml/system.xml file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="payment">
<group id="mymethodname" translate="label" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>My payment method</label>
<group id="basic" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Basic settings</label>
<!-- NOTE the active option is in a sub-group. This will not work -->
<field id="active" translate="label" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
...