by Bhumi // Feb 11,2013 // No comment
This is the next article of magento series and I am going to cover creation of basic custom payment option in admin panel.In Previous article,we have learned Magento Extension Configuration
Before we have defined extension into the community folder the codepool so magento code resides into app/code/community.
So, Let’s dive into the code for creating custom extension of magento for payment gateway
First of all go to PaymentMethod/Module folder and create etc folder and in this folder create config.xml file. Place below code into your config file.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
<?xml version="1.0"?> <config> <modules> <PaymentMethod_PaymentMethod> <version>0.1.2</version> </PaymentMethod_PaymentMethod> </modules> <global> <models> <paymentmethod> <class>PaymentMethod_PaymentMethod_Model</class> </paymentmethod> </models> <helpers> <paymentmethod> <class>PaymentMethod_PaymentMethod_Helper</class> </paymentmethod> </helpers> <resources> <paymentmethod_setup> <setup> <module>PaymentMethod_PaymentMethod</module> </setup> <connection> <use>core_setup</use> </connection> </paymentmethod_setup> <paymentmethod_write> <connection> <use>core_write</use> </connection> </paymentmethod_write> <paymentmethod_read> <connection> <use>core_read</use> </connection> </paymentmethod_read> </resources> <blocks> <paymentmethod> <class>PaymentMethod_PaymentMethod_Block</class> </paymentmethod> </blocks> <rewrite> <paymentmethod_paymentmethod_processing> <from><![CDATA[#^/checkout/onepage#]]></from> <to>/paymentmethod/processing</to> </paymentmethod_paymentmethod_processing> </rewrite> </global> <frontend> <routers> <paymentmethod> <use>standard</use> <args> <module>PaymentMethod_PaymentMethod</module> <frontName>paymentmethod</frontName> </args> </paymentmethod> </routers> <layout> <updates> <paymentmethod> <file>paymentmethod.xml</file> </paymentmethod> </updates> </layout> </frontend> <default> <payment> <paymentmethod> <model>paymentmethod/paymentmethod</model> <title>PaymentMethod</title> <active>0</active> <order_status>processing</order_status> <payment_action>authorize_capture</payment_action> <allowspecific>0</allowspecific> </paymentmethod> </payment> </default> </config> |
Next, is about system configuration so create system.xml and place following code into it.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
<?xml version="1.0" encoding="UTF-8"?> <config> <sections> <!-- payment tab --> <payment> <groups> <paymentmethod translate="label" module="paymentmethod"> <!-- will have title 'New Module' --> <label>PaymentMethod</label> <!-- position between other payment methods --> <sort_order>304</sort_order> <!-- do not show this 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 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> <title translate="label"> <label>Title</label> <comment>This is what the customers will see as the name of the payment option</comment> <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> <api_key translate="label"> <label>API Key</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> </api_key> <paymentmethod_server translate="label"> <label>PaymentMethod Server</label> <frontend_type>select</frontend_type> <source_model>paymentmethod/source_paymentmethodServers</source_model> <sort_order>5</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </paymentmethod_server> <sort_order translate="label"> <label>Sort Order</label> <frontend_type>text</frontend_type> <sort_order>7</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>0</show_in_store> </sort_order> <order_status translate="label"> <label>New order status</label> <frontend_type>select</frontend_type> <source_model>adminhtml/system_config_source_order_status</source_model> <sort_order>8</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> </fields> </paymentmethod> </groups> </payment> </sections> </config> |
Now, create model folder into your community/PaymentMethod/PaymentMethod directory and create file Paymentmethod.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
class PaymentMethod_PaymentMethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract { protected $_code = 'paymentmethod'; protected $_canCapture = true; protected $_canReviewPayment = false; protected $_canAuthorize = true; protected $_formBlockType = 'paymentmethod/form'; protected $_infoBlockType = 'paymentmethod/info'; protected $_paymentMethod = 'paymentmethod'; // Order specific fields protected $_order_status; public function capture(Varien_Object $payment, $amount) { $payment->setStatus(self::STATUS_APPROVED) ->setTransactionId($this->getTransactionId()) ->setIsTransactionClosed(0); return $this; } } |
Here in model folder create one more folder Model/Source and creat file PaymentMethodServers.php
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class PaymentMethod_PaymentMethod_Model_Source_PaymentMethodServers { const SERVER_TEST = 'Test'; const SERVER_LIVE = 'Live'; public function toOptionArray() { return array( array( 'value' => self::SERVER_LIVE, 'label' => Mage::helper('paygate')->__('Live') ), array( 'value' => self::SERVER_TEST, 'label' => Mage::helper('paygate')->__('Test') ), ); } } |
Create helper folder into PaymentMethod/PaymentMethod and in that Data.php file
|
1 2 3 4 5 |
class PaymentMethod_PaymentMethod_Helper_Data extends Mage_Payment_Helper_Data { } |
Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.
Conquer SmartPhone Internet Era with Magento Mobile Themes
On looking at stressed faces of Magento users, it is easy to understand the reason of their stress. The impact of SmartPhone powered virtual era READ MORE
After few days,I am back again with my new quick article release. Today we will continue with Magento article series and i am going to READ MORE
Magento Extension Configuration
Magento is a powerful open source eCommerce solutions.Let’s move to the one step ahead in Magento article series.In this blog post, we will see how READ MORE
Enable system log and errors/warning in magento
Today I am going to start the series of the articles in Magento.No doubt Magento is a best open source e-commerce platform and whenever you READ MORE
Magento is a well known open source ecommerce platform.Recently I have started working on Magento and i want to check the position of blocks in READ MORE
Be a Contributor at CreativeDev.Write an article or tutorial to the community and share some of your knowledge!