3

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?
  • I'm facing same error...how to solve it @Manuel – Mahi M Mar 7 '18 at 8:04
  • @PriyaM did you try to create a payment.xml or setting a title in etc/config.xml (see answers)? – Manuel M Mar 8 '18 at 7:15
  • <?xml version="1.0"?> <config xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <default> <payment> <fee_config> <fee_enabled>1</fee_enabled> <fee_title>codfee</fee_title> </fee_config> </payment> </default> </config> – Mahi M Mar 8 '18 at 7:16
  • Yes.....this is my config.xml file.but still not getting config values – Mahi M Mar 8 '18 at 7:16
  • Hi @ManuelM Did you get the solution for this? I am struggling – Daniel_12 Mar 27 '19 at 12:42
2

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.

| improve this answer | |
  • 1
    I disagree with this answer. See my own answer for details. – peedee Nov 16 '16 at 10:14
  • I'm facing same error...but it not works for me.how to solve it – Mahi M Mar 7 '18 at 7:04
8

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).

| improve this answer | |
4

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>
| improve this answer | |
0

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

| improve this answer | |
0
php bin/magento setup:di:compile
| improve this answer | |
0

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.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.