Create a Custom Payment Method Module in Magento



Step 1: app\etc\modules\Excellence_Pay.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Excellence_Pay>
            <active>true</active>
            <codePool>local</codePool>
        </Excellence_Pay>
    </modules>
</config>

Step 2:     app\design\frontend\base\default\layout\pay.xml
<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
    </default>
    <pay_index_index>
        <reference name="content">
            <block type="pay/pay" name="pay" template="pay/pay.phtml" />
        </reference>
    </pay_index_index>
</layout>
Step 3:     app\design\frontend\base\default\template\pay\form\pay.phtml
<?php $_code=$this->getMethodCode() ?>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
    <li>
        <label for="<?php echo $_code ?>_check_no" class="required"><em>*</em><?php echo $this->__('MTCN No#') ?></label>
        <span class="input-box">
            <input type="text" title="<?php echo $this->__('MTCN No#') ?>" class="input-text required-entry" id="<?php echo $_code ?>_check_no" name="payment[check_no]" value="<?php echo $this->htmlEscape($this->getInfoData('check_no')) ?>" />
        </span>
    </li>
    <li>
        <label for="<?php echo $_code ?>_check_date" class="required"><em>*</em><?php echo $this->__('First Name:') ?></label>
        <span class="input-box">
            <input type="text" title="<?php echo $this->__('First Name:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_check_date" name="payment[check_date]" value="<?php echo $this->htmlEscape($this->getInfoData('check_date')) ?>" />
        </span>
    </li>
                <li>
        <label for="<?php echo $_code ?>_last_name" class="required"><em>*</em><?php echo $this->__('Last Name:') ?></label>
        <span class="input-box">
            <input type="text" title="<?php echo $this->__('Last Name:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_last_name" name="payment[last_name]" value="<?php echo $this->htmlEscape($this->getInfoData('last_name')) ?>" />
        </span>
    </li>
                <li>
        <label for="<?php echo $_code ?>_check_address" class="required"><em>*</em><?php echo $this->__('Address:') ?></label>
        <span class="input-box">
               
            <input type="text" title="<?php echo $this->__('Address:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_check_address" name="payment[check_address]" value="<?php echo $this->htmlEscape($this->getInfoData('check_address')) ?>" />
        </span>
    </li>
</ul>
<div>
                <?php echo $this->getMethod()->getConfigData('message');?>
</div>
Step 4:     app\code\local\Excellence\Pay\Block\Form\pay.php
<?php
class Excellence_Pay_Block_Form_Pay extends Mage_Payment_Block_Form
{
                protected function _construct()
                {
                                parent::_construct();
                                $this->setTemplate('pay/form/pay.phtml');
                }
}
Step 5:     app\code\local\Excellence\Pay\Block\Info\pay.php
<?php
class Excellence_Pay_Block_Info_Pay extends Mage_Payment_Block_Info
{
                protected function _prepareSpecificInformation($transport = null)
                {
                                if (null !== $this->_paymentSpecificInformation) {
                                                return $this->_paymentSpecificInformation;
                                }
                                $info = $this->getInfo();
                                $transport = new Varien_Object();
                                $transport = parent::_prepareSpecificInformation($transport);
                                $transport->addData(array(
                                                Mage::helper('payment')->__('MTCN No#') => $info->getCheckNo(),
                                                Mage::helper('payment')->__('First Name') => $info->getCheckDate(),
                                                Mage::helper('payment')->__('Last Name') => $info->getLastName(),
                                                Mage::helper('payment')->__('Address') => $info->getCheckAddress()
                                ));
                                return $transport;
                }
}
Step 6:     app\code\local\Excellence\Pay\etc\config.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Excellence_Pay>
            <version>0.1.0</version>
        </Excellence_Pay>
    </modules>
    <frontend>
        <routers>
            <pay>
                <use>standard</use>
                <args>
                    <module>Excellence_Pay</module>
                    <frontName>pay</frontName>
                </args>
            </pay>
        </routers>
        <layout>
            <updates>
                <pay>
                    <file>pay.xml</file>
                </pay>
            </updates>
        </layout>
    </frontend>
    <global>
                <fieldsets>
                                 <sales_convert_quote_payment>
                                                <check_no>
                                                                <to_order_payment>*</to_order_payment>
                                                </check_no>
                                                <check_date>
                                                                <to_order_payment>*</to_order_payment>
                                                </check_date>
                                                                <last_name>
                                                                <to_order_payment>*</to_order_payment>
                                                </last_name>
                                                                <check_address>
                                                                <to_order_payment>*</to_order_payment>
                                                </check_address>
                                 </sales_convert_quote_payment>
                </fieldsets>
        <models>
            <pay>
                <class>Excellence_Pay_Model</class>
                <resourceModel>pay_mysql4</resourceModel>
            </pay>
            <pay_mysql4>
                <class>Excellence_Pay_Model_Mysql4</class>
                <entities>
                    <pay>
                        <table>pay</table>
                    </pay>
                </entities>
            </pay_mysql4>
        </models>
        <resources>
            <pay_setup>
                <setup>
                    <module>Excellence_Pay</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </pay_setup>
            <pay_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </pay_write>
            <pay_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </pay_read>
        </resources>
        <blocks>
            <pay>
                <class>Excellence_Pay_Block</class>
            </pay>
        </blocks>
        <helpers>
            <pay>
                <class>Excellence_Pay_Helper</class>
            </pay>
        </helpers>
    </global>
    <default>
        <payment>
            <pay>
                <active>1</active>
                <model>pay/pay</model>
                <order_status>processing</order_status>
                <title>Excellence Payment Method</title>
                <message>Please draw check in favour of Test Corporation: #XXXX-XXXX</message>
            </pay>
         </payment>
    </default>
</config>
Step 7:     app\code\local\Excellence\Pay\etc\system.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
   <sections>
        <payment>
            <groups>
                <pay translate="label" module="pay">
                    <label>Excellence Payment Module</label>
                    <sort_order>670</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>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>
                        <message translate="label">
                                                                                                                <label>Displayed Message</label>
                                                                                                                <frontend_type>textarea</frontend_type>
                                                                                                                <sort_order>4</sort_order>
                                                                                                                <show_in_default>1</show_in_default>
                                                                                                                <show_in_website>1</show_in_website>
                                                                                                                <show_in_store>1</show_in_store>
                                                                                                </message>
                    </fields>
                </pay>
            </groups>
        </payment>
    </sections>
</config>
Step 8:     app\code\local\Excellence\Pay\Helper\Data.php
<?php

class Excellence_Pay_Helper_Data extends Mage_Core_Helper_Abstract
{

}
Step 9:     app\code\local\Excellence\Pay\Model\pay.php
<?php
class Excellence_Pay_Model_Pay extends Mage_Payment_Model_Method_Abstract
{
                protected $_code = 'pay';
                protected $_formBlockType = 'pay/form_pay';
                protected $_infoBlockType = 'pay/info_pay';

                public function assignData($data)
                {
                                if (!($data instanceof Varien_Object)) {
                                                $data = new Varien_Object($data);
                                }
                                $info = $this->getInfoInstance();
                                $info->setCheckNo($data->getCheckNo())
                                ->setLastName($data->getLastName())
                                ->setCheckAddress($data->getCheckAddress())
                                ->setCheckDate($data->getCheckDate());
                               
                                return $this;
                }


                public function validate()
                {
                                parent::validate();

                                $info = $this->getInfoInstance();

                                $no = $info->getCheckNo();
                                $date = $info->getCheckDate();
                                if(empty($no) || empty($date)){
                                                $errorCode = 'invalid_data';
                                                $errorMsg = $this->_getHelper()->__('Check No and Date are required fields');
                                }

                                if($errorMsg){
                                                Mage::throwException($errorMsg);
                                }


                                return $this;
                }
}
?>
Step  10:     app\code\local\Excellence\Pay\sql\pay_setup\mysql4-install-0.1.0.php
<?php
$installer = $this;
/* @var $installer Mage_Customer_Model_Entity_Setup */

$installer->startSetup();
$installer->run("

ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `check_no` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `check_date` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `last_name` VARCHAR( 255 ) NOT NULL ;

ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `check_no` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `check_date` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `last_name` VARCHAR( 255 ) NOT NULL ;

");
$installer->endSetup();
 

Custm_payment_method
Add caption


Custm_payment_method 


Custm_payment_method
Share on Google Plus

About quora Questions & Answers A-Z

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment