0

I'm trying to create a custom payment model, a simple one without database changes, but I have a problem, when I select it in the checkout it said:

The request Payment Method is not available

Now, the debug:

  • In Mage_Payment_Model_Method_Abstract with $this->getCode(), I can't see my custom method

  • In a observer, like above, I can't see my method

  • In template/checkout/onepage/payment/methods.phtml I can see it

I suppose my config.xml and system.xml are working because:

  • I can see it in the admin area and save it
  • I can see the value in core_config_data
  • I can see it in the checkout
  • I compare with other extensions and it looks the same

Now in Mage/Payment/Model/Method/Abstract.php inside function isAvailable I put some logs and:

$isActive == 1
$isAvailable == 1
$isDeniedInConfig == ''

But still doesn't work.

My code:

config.xml

<config>
    <modules>
        <Namespace_Pay>
            <module>0.0.1</module>
        </Namespace_Pay>
    </modules>
    <global>
        <helpers>
            <pay>
                <class>Namespace_Pay_Helper</class>
            </pay>
        </helpers>
        <models>
            <pay>
                <class>Namespace_Pay_Model</class>
            </pay>
        </models>
    </global>
    <default>
        <payment>
            <namespace_pay>
                <active>1</active>
                <title>Title</title>
                <model>pay/store</model>
                <order_status>processing</order_status>
                <allowspecific>0</allowspecific>
                <payment_action>sale</payment_action>
            </namespace_pay>
        </payment>
    </default>
</config>

system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <payment>
            <groups>
                <pay translate="label" module="pay">
                    <label>Label</label>
                    <sort_order>670</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>1</show_in_store>
                    <fields>
                        <active translate="label">
                            <label>Enabled</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_yesno</source_model>
                            <sort_order>1</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </active>
                        <order_status translate="label">
                            <label>New order status</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_order_status_processing</source_model>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </order_status>
                        <allowspecific translate="label">
                            <label>Payment from applicable countries</label>
                            <frontend_type>allowspecific</frontend_type>
                            <sort_order>40</sort_order>
                            <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </allowspecific>
                        <specificcountry translate="label">
                            <label>Payment from Specific countries</label>
                            <frontend_type>multiselect</frontend_type>
                            <sort_order>50</sort_order>
                            <source_model>adminhtml/system_config_source_country</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </specificcountry>
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </title>
                    </fields>
                </pay>
            </groups>
        </payment>
    </sections>
</config>

Store.php (Model)

<?php
class Namespace_Pay_Model_Store
    extends Mage_Payment_Model_Method_Abstract
{
    protected $_code = 'pay';
}
  • Why you have written this ` if($quote->getAllVisibleItems() <= 2){ retur false;}` ? try to remove this and check – Keyur Shah Jan 15 '18 at 12:07
  • Yes, sorry, I have this part commented all the time in my code, I don't understand why I fount it in this way, but I think it's wrong too – oootramas Jan 15 '18 at 12:19
  • please post your full code here which you have done for payment method so peoples can understand – Keyur Shah Jan 15 '18 at 12:44
0

The child node in <payment> in your config.xml is incorrect since you're referring to you model as pay (not namespace_pay).

<config>
    <modules>
        <Namespace_Pay>
            <module>0.0.1</module>
        </Namespace_Pay>
    </modules>
    <global>
        <helpers>
            <pay>
                <class>Namespace_Pay_Helper</class>
            </pay>
        </helpers>
        <models>
            <pay>
                <class>Namespace_Pay_Model</class>
            </pay>
        </models>
    </global>
    <default>
        <payment>
            <pay> <!-- "namespace_pay" is incorrect -->
                <active>1</active>
                <title>Title</title>
                <model>pay/store</model>
                <order_status>processing</order_status>
                <allowspecific>0</allowspecific>
                <payment_action>sale</payment_action>
            </pay>
        </payment>
    </default>
</config>
0

I think it's not the correct answer, and I can't explain why, but for me works.

-In system.xml put module="namespace_pay"

-In config.xml inside helpers and models tags put namespace_pay:

<helpers>
    <namespace_pay>
        <class>Namespace_Pay_Helper</class>

<models>
    <namespace_pay>
        <class>Namespace_Pay_Model</class>

and:

<default>
    <payment>
        <pay>
           <model>namespace_pay/store</model>
  • That's exactly what I'm telling you. But obviously it doesn't matter whether you change ALL model alias to fit one wrong line (from pay to namespace_pay) or change one line to fit ALL others (from namespace_pay to pay)... – Christoph Farnleitner Jan 17 '18 at 15:31
  • With your answer only it doesn't work... in my code at least – oootramas Jan 17 '18 at 16:01
  • 1
    ok, sorry, it's true – oootramas Jan 17 '18 at 17:14
  • Don't worry - as said, both ways are valid. Since there is no 100% definition as per what your alias should look like I however would dent to to say that namespace_pay is anyway more preferable than just pay (since that will give a better hint of where the model is coming from) – Christoph Farnleitner Jan 17 '18 at 17:19

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.