Magento Customization India – Custom Payment Gateway Module in Magento

Back to Blog
magento ecommerce developers mumbai - ezeelive

Magento Customization India – Custom Payment Gateway Module in Magento

Payment Gateway is the most important section of any eCommerce or Shopping website. Where user can purchase and pay by using Credit Cards online.

Magento base code developed in Zend Framework Module structure. Here developer can developed modules and extensions as per there requirement and use or re-use. A payment gateway system mostly does:

A. valid and accept credit card detail
B. authorize payment detail when submitting order detail
C. Save Transaction ID along with user detail in Order

So let’s create a Custom Payment Gateway Module in Magento in below steps, here our module name is EzeePayment :

1. Create xml file in app/etc/modules/CompanyName_EzeePayment.xml for Module declared:

<config>
<modules>
<CompanyName_EzeePayment>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Payment />
</depends>
</CompanyName_EzeePayment>
</modules>
</config>

2. Create xml file app/code/local/CompanyName/EzeePayment/etc/config.xml for module configuration:

<?xml version="1.0"?>
<config>
<modules>
<CompanyName_EzeePayment>
<version>0.1.0</version>
</CompanyName_EzeePayment>
</modules>
<global>
<blocks>
<ezeepayment>
<class>CompanyName_EzeePayment_Block</class>
</ezeepayment>
</blocks>
<!-- model for ezeepayment module -->
<models>
<ezeepayment>
<class>CompanyName_EzeePayment_Model</class>
</ezeepayment>
</models>
<!-- setup for ezeepayment module -->
<resources>
<!-- identifier -->
<ezeepayment_setup>
<setup>
<module>CompanyName_EzeePayment</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</ezeepayment_setup>
<ezeepayment_write>
<connection>
<use>core_write</use>
</connection>
</ezeepayment_write>
<ezeepayment_read>
<connection>
<use>core_read</use>
</connection>
</ezeepayment_read>
</resources>
</global>
<!-- default configuration values for this module -->
<default>
<!-- 'payment' configuration section -->
<payment>
<!-- 'ezeepayment' configuration group -->
<ezeepayment>
<!-- by default this payment method is inactive -->
<active>0</active>
<!-- model to handle logic for this payment method -->
<model>ezeepayment/paymentMethod</model>
<!-- order status for new orders paid by this payment method -->
<order_status>pending</order_status>
<!-- default title for payment checkout page and order view page -->
<title>Credit Card (Authorize.net)</title>

<cctypes>AE,VI,MC,DI</cctypes>
<payment_action>authorize</payment_action>
<allowspecific>0</allowspecific>
</ezeepayment>
</payment>
</default>
</config>

3. Now create EzeePayment Model PHP file in app/code/local/CompanyName/EzeePayment/Model/PaymentMethod.php :

<?php
class CompanyName_EzeePayment_Model_PaymentMethod extends Mage_Payment_Model_Method_Cc
{
protected $_code = 'ezeepayment';
//payment method (online auth/charge) ?
protected $_isGateway = true;

//authorize online?
protected $_canAuthorize = true;

//capture funds online?
protected $_canCapture = true;

//capture partial amounts online?
protected $_canCapturePartial = false;

//Can refund online?
protected $_canRefund = false;

//Can void transactions online?
protected $_canVoid = true;

//Can use payment method internal in admin panel?
protected $_canUseInternal = true;

//Can show payment method as an option on checkout payment page?
protected $_canUseCheckout = true;

//Is this payment method for multiple shipping checkout?
protected $_canUseForMultishipping = true;

//Save credit card detail for future processing?
protected $_canSaveCc = false;

//Here you will need to code for authorize, capture and void public methods payment gateway
}
?>

In this above class now we have to do actual code for communicating payment gateway. If in admin panel you have selected “Authorize Only”, then authorize method will be called. If you have chosen “Authorize and Capture then only the capture method will be called

4. Now create system xml file app/code/local/CompanyName/EzeePayment/etc/system.xml for Declare configuration options in Magento admin panel :

<?xml version="1.0"?>
<config>
<sections>
<!-- payment tab -->
<payment>
<groups>
<!-- ezeepayment fieldset -->
<ezeepayment translate="label" module="paygate">
<!-- For title 'Ezee Payment' -->
<label>Ezee Payment</label>
<sort_order>670</sort_order>
<!-- not to show configuration options in store scope -->
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<!-- active for website? -->
<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>4</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>2</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>
</ezeepayment>
</groups>
</payment>
</sections>
</config>

5. Create SQL Installer file app/code/local/CompanyName/EzeePayment/sql/ezeepayment_setup/mysql4-install-0.1.0.php:

<?php
$this->startSetup();
$this->run("SQL HERE");
$this->endSetup();

Remember database update change the module version in config.xml file

<modules>
<CompanyName_EzeePayment>
<version>0.2.0</version>
</CompanyName_EzeePaymente>
</modules>

Then create SQL update file app/code/local/CompanyName/EzeePayment/sql/ezeepayment_setup/mysql4-upgrade-0.1.0-0.2.0.php:

<?php
$this->startSetup();
$this->run("UPDATE SQL HERE");
$this->endSetup();

Note :
1. Make sure in your system app/code/local is in include_path.
2. Don’t put your module in Root Mage folder
3. Your module first letter should be capitalized (eg. EzeePayment).
4. If your module is not showing in admin configuration section then check and config.xml file.
5. Clear your system cache.

Hope above example will help you to create the custom module in Magento. If you face any problem with existing code or any Magento related please fill free to contact or comment us. We will feel proud to help you.

In the Last Word :

Ezeelive Technologies (Magento Development Company in India) has the expert team in custom Magento theme design, responsive Magento e-commerce portal development, and Magento customization India. We developed and implement the custom module, extension, and plugin as per project or client requirement.

Share this post

Comment (1)

  • Millar Reply

    Great site you’ve got here.. It’s difficult to find excellent writing like yours nowadays. I truly appreciate people like you! Take care!!

    August 31, 2014 at 12:01 am

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Blog