Question

I have an extension that has some config fields in the payment section. The extension does not supply a payment method, I just want to have the settings in the Payment Methods section.

module.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Example_MyExtension" setup_version="0.1">
    </module>
</config>

The system.xmllooks like this:

<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="myextension" translate="label" type="text" sortOrder="99" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>MyExtension</label>
        <field id="activate_export" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
          <label>Export Orders</label>
          <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
        </field>
      </group>
    </section>
  </system>
</config>

And thats what it looks like: MyExtension

So everything's fine until now. Now I want to have a default value, so I create config.xml.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
  <default>
    <payment>
      <myextension>
        <activate_export>1</activate_export>
      </myextension>
    </payment>
  </default>
</config>

When I try to open the configuration, I see nothing and get the following error in system.log:

Payment model name is not provided in config!

The error is thrown in /vendor/magento/module-payment/Helper/Data.php in getMethodInstance(). As far as I can tell, the code tries to load a payment method named myextension and fails.

When I place the configuration under section sales, everything works as expected.

Questions:

  1. Is this a bug?
  2. If not, is it not only allowed to put configuration for payment modules in payment?
Was it helpful?

Solution

I also had this problem when I removed my module and reinstall again. Just solved it a few second ago. You need to create a payment.xml since you are creating a payment module.

By the way the payment.xml can be created using CedCommerce payment module creator. I think the link has been shared by the savior above.

<methods>
    <method name="(here type in your module name in lower case)">
        <allow_multiple_address>0</allow_multiple_address>
    </method>

</methods>

Put this payment.xml in your module etc directory and it should able to be solved. You may use the method name to register a configprovider in model if you wish.

OTHER TIPS

I disagree with the accepted answer. I found myself in a similar situation as OP and made my own experiments to get rid of this error, and what solved it for me was setting a title in etc/config.xml.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <payment>
            <my-method>
                <title>My method</title>   <!-- backend will show errors if TITLE isn't set to a value here -->

                <merchant_id backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
                <security_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
            </my-method>
        </payment>
    </default>
</config>

The accepted answer talk about etc/payment.xml but that made no difference for me (the backend works even when that file does not exist).

You need to provide <model> node in your config.xml file. See example from Authorize.net module:

<default>
        <payment>
            <authorizenet_directpost>
                ...
                <model>Magento\Authorizenet\Model\Directpost</model>
                ...
            </authorizenet_directpost>
        </payment>
    </default>
php bin/magento setup:di:compile

to create payment module with 3ed party api website follow the below post if it helps accept the answer which help others Payment module redirect to payment website url in magento2

As of Magento 2.3 and 2.4, the only place this message is created is within vendor/magento/module-payment/Helper/Data.php as follows:

    public function getMethodInstance($code)
    {
        $class = $this->scopeConfig->getValue(
            $this->getMethodModelConfigName($code),
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE
        );

        if (!$class) {
            throw new \UnexpectedValueException('Payment model name is not provided in config!');
        }

        return $this->_methodFactory->create($class);
    }

And getMethodModelConfigName is declared just before this one:

    protected function getMethodModelConfigName($code)
    {
        return sprintf('%s/%s/model', self::XML_PATH_PAYMENT_METHODS, $code);
    }

Which means both @Bery's and @Antoine's responses are correct.

However, for those like me, you may have been fooled by opcache. Opcache caches the things when in use and the model may not exist after you've installed your module because Magento is still reading it from the cache generated prior to that.

That said, the solution would be:

  1. Make sure you've cleaned your opcache (or restart php-fpm and nginx/apache)
  2. Make sure your payment module have defined the model as stated by @Bery
  3. Do bin/magento setup:di:compile.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top