Posted by: james | July 22, 2009

Magento Payment Module Integration

To create new payment module in magento first of all understand the folder structure and then go ahead.. here i have created folder structure for my payment module, but not necessary that in every payment module this will be same but in almost it will be same…

first of all go in app/etc/modules/Your_Payment_ModuleName.xml

in that write
<?xml version=”1.0″ encoding=”UTF-8″?>
<config>
<modules>
<your_payment_module_name>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>

// in some module the define module is depending upon some default module so in that case you have to use depends like this…
<depends>
<Mage_Paygate/>
</depends>
</your_payment_module_name>
</modules>
</config>

// that’s it your xml file has been set now go ahead…

now go to app/design/frontend/default/your_theme_name/template/your_payment_module_name/

there create two folder name form and info and in that create .phtml file with same name.so now the structure will look like this,

app/design/frontend/default/your_theme_name/template/your_payment_module_name/form/file_name.phtml
app/design/frontend/default/your_theme_name/template/your_payment_module_name/info/file_name.phtml

// for more info please reffer app/design/frontend/default/default/template/payment/info/cc.phtml
// for more info please reffer app/design/frontend/default/default/template/payment/form/cc.phtml

And now in that do coding as you require for display form or whatever you requrire to display user side do that in this files….

// so your user interface part also complaete and now go to main part our coding…. for that go to ..

app/code/local/your_payment_module_name/ and in that create folder as i mention below….

Block
controllers
etc
Helper
Model

// its not necessary that every payment module has same number of folder but it depends on module….

now go to etc folder and create two xml files
1. config.xml
2. system.xml

now go to config.xml and write in that…..

<?xml version=”1.0″?>
<config>
<modules>
<Your_payment_module_name>
<version>0.1.0</version>
</Your_payment_module_name>
</modules>
<global>
<models>
<your_payment_module_name>
<class>your_payment_module_name_Model</class>
</your_payment_module_name>
</models>
<helpers>
<your_payment_module_name>
<class>your_payment_module_name_Helper</class>
</your_payment_module_name>
</helpers>
<resources>
<your_payment_module_name_setup>
<setup>
<module>your_payment_module_name</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</your_payment_module_name>
<your_payment_module_name_write>
<connection>
<use>core_write</use>
</connection>
</your_payment_module_name_write>
<your_payment_module_name_read>
<connection>
<use>core_read</use>
</connection>
</your_payment_module_name_read>
</resources>
<blocks>
<your_payment_module_name>
<class>your_payment_module_name_Block</class>
</direcpay>
</blocks>

</global>
</config>

//After that go to system.xml and write in that…..

In that write same as system.xml from another default files in paypal or in any other module.. its almost same just change module name with         your new module name..

// now go to helper folder and in that create Data.php so our strucuture will look like this…

app/code/local/your_payment_module_name/Helper/Data.php

In that you have to write extend class defination and not in all payment module this will be true but for almost it will be same as here.

class your_payment_module_name_Helper_Data extends Mage_Core_Helper_Abstract
{
}

// now go to block folder in that you have to create all .php files which are defined in templater folder.. so here we will create filse as mentioned         below..

first of all create folder name Form,Info and in that create Form.php so our strucutre will look like this,

app/code/local/your_payment_module_name/Block/Form/Form.php
app/code/local/your_payment_module_name/Block/Info/Info.php

If you want that user must enter his details here so you have to set template here as Form.phtml and in the Form.phtml create form for entering all         the details and if you want that user has to enter his details at payment site then display appropriate message at there and redirect to that site         after final checkout step.

info.php –> to display layout of Info File
Form.php –> to display layout of form file

And may be there is also another files are.. like Redirect.php, Fail.php

Redirect.php –> in this coding for redirect to payment site
Fail.php –> in this coding for failure, means if any failure occur during transaction then redirect to again shopping site..

// now go to controller Folder Before that please reffer app/code/core/Mage/Paypal/controllers/StandaradController.php/

here create IndexController.php and in that define different action like mentioned below..

public function successAction()
{
}

public function cancelAction()
{
}

public function redirectAction()
{
}

// Now go to Model folder..

Normally in Model there is coming business logic and here also same thing happen… so here you can create one file with different action in same file for different tasks..

for ex.

please read app/code/Mage/Paypal/Model/Standard.php
in this you can see all the normal actions,follow this ans also add your own payment module’s method.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: