Quantcast
Channel: BryMayor.com » brynayrb
Viewing all articles
Browse latest Browse all 10

Create Basic Custom Payment Method in Magento

$
0
0

This is the basic payment method tutorial and does not cover if there is a payment integration.

First we need to decide on a unique code for the payment method, in the following example, I used the code new_pay and the name of my module is Brymayor_Payment.

By default in our example, this would create a new configuration under System > Sales > Payment Methods > BryMayor Payment Module.
In your system.xml inside your custom module’s etc folder:

system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
   <sections>
        <payment>
            <groups>
                <new_pay translate="label" module="brymayor_payment">
                    <label>BryMayor Payment Module</label>
                    <sort_order>1000</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</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>0</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>
                        <title translate="label">
                            <label>Payment 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>0</show_in_store>
                        </title>
                    </fields>
                </new_pay>
            </groups>
        </payment>
    </sections>
</config>

We should now see this on the admin:

Create Basic Custom Payment Method in Magento

Now in our module’s config.xml file we need to put in default values for the fields created in system.xml. This is optional since you can set it by yourself:

config.xml

<default>
    <payment>
        <new_pay>
            <active>1</active>
            <model>brymayor_payment/payment</model>
            <order_status>processing</order_status>
            <title>BryMayor Payment Method</title>
        </new_pay>
     </payment>
</default>

Create the model class for our payment method at Brymayor_Pay_Model_Pay, as stated in the config.xml <model> tag.

class Brymayor_Payment_Model_Payment extends Mage_Payment_Model_Method_Abstract
{
    protected $_code = 'new_pay';
}

And also don’t forget to add the model declaration in config.xml (note that the xml below is a fragment):

<?xml version="1.0"?>
<config>
    <global>
        <models>
            <brymayor_payment>
                <class>Brymayor_Payment_Model</class>
            </brymayor_payment>
        </models>
    </global>
</config>

We should now see this new payment method at the frontend:

Create Basic Custom Payment Method in Magento

The post Create Basic Custom Payment Method in Magento appeared first on BryMayor.com.


Viewing all articles
Browse latest Browse all 10

Trending Articles