<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stephen Gray&#039;s dev blog &#187; payment</title>
	<atom:link href="http://blog.s-gray.com/tag/payment/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.s-gray.com</link>
	<description>e-commerce and integrations</description>
	<lastBuildDate>Sun, 17 Jan 2010 09:32:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Magento create a custom payment method</title>
		<link>http://blog.s-gray.com/2009/11/11/magento-create-a-custom-payment-method/</link>
		<comments>http://blog.s-gray.com/2009/11/11/magento-create-a-custom-payment-method/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 09:42:18 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[gateway]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[payment]]></category>

		<guid isPermaLink="false">http://colourgray.wordpress.com/?p=136</guid>
		<description><![CDATA[I've been doing some work with the Magento e-commerce platform lately and my task was to create a new payment method to use during the standard checkout process.

After much searching online, it seems that any available tutorials for custom payment methods either don't work, are incomplete or worked in previous versions but are now updated. I developed this using version 1.3.2.2 of Magento.

I'm writing this tutorial with the intention of it being the definitive guide to creating a custom payment method.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing some work with the Magento e-commerce platform lately and my task was to create a new payment method to use during the standard checkout process.</p>
<p>I&#8217;ve come to the conclusion that Magento is very annoying to develop for if you know nothing about the platform. Yes the platform is open source but they also have a commercial version, therefore it seems they have tried to make it hard for you to know the complete ins and outs of the system. I.E. if something seems like too much of a task to develop, a company would likely purchase the commercial version and get it developed by the platform developers rather than do it themselves.</p>
<p>You also have to remember that Magento is built on top of the Zend framework, so when you are developing for it documentation does not all reside on the Magento site, you will have to look into how the Zend framework works as well.</p>
<p>Finally, note that by default the Magento checkout process uses AJAX to submit the form, making this a very annoying module to debug. Thankfully Magento makes it easy to log values and throw exceptions which &#8216;pause&#8217; the checkout process.</p>
<p>After much searching online, it seems that any available tutorials for custom payment methods either don&#8217;t work, are incomplete or worked in previous versions but are now updated. I developed this using version 1.3.2.2 of Magento.</p>
<p>I&#8217;m writing this tutorial with the intention of it being the definitive guide to creating a custom payment method.</p>
<p><strong><a href="#0">Prerequisites</a></strong><br />
<strong><a href="#1">1. Creating the module</a></strong><br />
<strong><a href="#2">2. Configuration through the admin</a></strong><br />
<strong><a href="#4">4. Payment adapter model class</a></strong></p>
<h2><a name="0"> Prerequisites</a></h2>
<p>There are a few things you need to note now to avoid confusion later down the line.</p>
<p>For your module, you need the main name and a simpler alias for it. I.E. if your module was called MyPaymentMethod, your alias could be mypayment. Keep the full name and the alias in mind. The full name will be used in class and folder names but the alias will be used when referencing the module anywhere else.</p>
<p>For this tutorial I will be using ModuleName for the full name, modulename for the module alias, and MyModules as the module namespace.</p>
<p>Magento names it&#8217;s classes after their path. I.E. you are going to have a class which handles all of this payment method logic, and it&#8217;s path will be something like app/code/local/MyModules/ModuleName/Model/PaymentLogic.php. It&#8217;s class name will be MyModules_ModuleName_Model_PaymentLogic. Remember this as it helps when trying to figure out where to find a referenced class etc.</p>
<h2><a name="1">Creating the module</a></h2>
<p>OK so first we need to create the initial module and make sure Magento knows that it exists. Lets create the folder structure;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code1'); return false;">View Code</a> TEXT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1361"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p136code1"><pre class="text" style="font-family:monospace;">app/
---- code/
-------- local/
------------ #1 MyModules
---------------- #2 ModuleName
-------------------- #3 Block
-------------------- #4 etc
-------------------- #5 Model</pre></td></tr></table></div>

<p><strong>#1</strong> In Magento terms, MyModules would be the module&#8217;s namespace. I.E. you&#8217;ll likely have one namespace for multiple modules. The namespace can be called anything but should be UpperCamelCase. If you take a look in app/code/core you will see a folder called Mage &#8211; this is the namespace for most of Magento&#8217;s core modules.</p>
<p><strong>#2</strong> This is your actual module name. This should be UpperCamelCase.</p>
<p><strong>#3</strong> This folder is used to contain block classes that are used in your module.</p>
<p><strong>#4</strong> This is where your module configuration will go.</p>
<p><strong>#5</strong> The class that handles all of your payment gateway logic will go here. This is also a good place to put any third party libraries or custom classes you may use.</p>
<p><strong>config.xml</strong></p>
<p>Create the file config.xml in app/code/local/MyModules/ModuleName/config. This file is the main module configuration file. For now, you want it to look like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code2'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1362"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p136code2"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">        register the full module name and it's</span>
<span style="color: #808080; font-style: italic;">        version</span>
<span style="color: #808080; font-style: italic;">    --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">        global module configuration</span>
<span style="color: #808080; font-style: italic;">    --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">            register the module's model group</span>
<span style="color: #808080; font-style: italic;">            note that we use the module's alias</span>
<span style="color: #808080; font-style: italic;">            mentioned in the prerequisites</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MyModules_ModuleName_Model<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">            set which resources the module will</span>
<span style="color: #808080; font-style: italic;">            use when setting up, writing to the db</span>
<span style="color: #808080; font-style: italic;">            and reading from the db. we're going</span>
<span style="color: #808080; font-style: italic;">            to use the core connections.</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>MyModules_ModuleName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_write<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename_write<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_read<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename_read<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Now the module has it&#8217;s basic configuration but Magento doesn&#8217;t care because the module is not yet registered.</p>
<p><strong>MyModules_All.xml</strong></p>
<p>Create the file MyModules_All.xml in app/etc/modules. This is where we register the module. You want this file to look like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code3'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1363"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p136code3"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                for now we're telling the system that</span>
<span style="color: #808080; font-style: italic;">                this module is just local, it's not a core</span>
<span style="color: #808080; font-style: italic;">                or community module and resides in</span>
<span style="color: #808080; font-style: italic;">                app/code/local.</span>
<span style="color: #808080; font-style: italic;">            --&gt;</span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>local<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/MyModules_ModuleName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The module is now registered and Magento knows about it. But what can you do with it? Well, this is a payment method module, so we need to register it as a usable payment method. We also need to be able to set what fields are configured in the administration section that can be used when authenticating with the payment gateway etc.</p>
<h2><a name="2">Configuration through the admin</a></h2>
<p><strong>system.xml</strong></p>
<p>Create the file system.xml in app/code/local/MyModules/ModuleName/etc. Here we will tell Magento to have a new section in the payment methods configuration area for configuring this module. We also set what fields we want there. For every field, we have an element like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code4'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1364"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p136code4"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;field_name</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Field name<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>field type<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>field source model class<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/field_name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>As you will see below. To start with, have the file looking like this;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code5'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1365"><td class="line_numbers"><pre>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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
</pre></td><td class="code" id="p136code5"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sections<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">            here we're telling the system we</span>
<span style="color: #808080; font-style: italic;">            we want to add a new config section</span>
<span style="color: #808080; font-style: italic;">            in the payment method area</span>
<span style="color: #808080; font-style: italic;">        --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groups<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span> <span style="color: #000066;">module</span>=<span style="color: #ff0000;">&quot;paygate&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
                    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                        human readable module name</span>
<span style="color: #808080; font-style: italic;">                        which appears as the name of the</span>
<span style="color: #808080; font-style: italic;">                        payment method in the admin section</span>
<span style="color: #808080; font-style: italic;">                    --&gt;</span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>My Payment Module<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                    <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                        set where this method should appear</span>
<span style="color: #808080; font-style: italic;">                        in comparison to the other methods</span>
<span style="color: #808080; font-style: italic;">                        within the admin</span>
<span style="color: #808080; font-style: italic;">                    --&gt;</span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>670<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            you need this field if you want the user to</span>
<span style="color: #808080; font-style: italic;">                            be able to disable/enable this payment</span>
<span style="color: #808080; font-style: italic;">                            method. leave this out if you don't want</span>
<span style="color: #808080; font-style: italic;">                            this to be optional</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Enabled<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                            <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                                we want to use the standard Magento</span>
<span style="color: #808080; font-style: italic;">                                yes/no select options</span>
<span style="color: #808080; font-style: italic;">                            --&gt;</span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>adminhtml/system_config_source_yesno<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            the below two fields are an example</span>
<span style="color: #808080; font-style: italic;">                            of fields you may need if integrating with</span>
<span style="color: #808080; font-style: italic;">                            a payment gateway's API. you will see how</span>
<span style="color: #808080; font-style: italic;">                            to retrieve these values in your code later</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_key</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>API Key<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_secret</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>API Secret<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_secret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            having this field here allows the user</span>
<span style="color: #808080; font-style: italic;">                            to set whether we want payments to be</span>
<span style="color: #808080; font-style: italic;">                            authorised or authorised AND captured</span>
<span style="color: #808080; font-style: italic;">                            if you don't want the user to choose you</span>
<span style="color: #808080; font-style: italic;">                            can leave this field out</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment_action</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Payment Action<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                            <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                                we're using the source from the paygate</span>
<span style="color: #808080; font-style: italic;">                                module as it has the options we want. this</span>
<span style="color: #808080; font-style: italic;">                                is safe because the paygate module is a core</span>
<span style="color: #808080; font-style: italic;">                                Magento module and therefore will be there</span>
<span style="color: #808080; font-style: italic;">                                with any default install. if it makes you feel</span>
<span style="color: #808080; font-style: italic;">                                safer you can create your own field source model</span>
<span style="color: #808080; font-style: italic;">                                but that isn't covered in this tutorial</span>
<span style="color: #808080; font-style: italic;">                            --&gt;</span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>paygate/authorizenet_source_paymentAction<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/payment_action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            what do you want the status to be of</span>
<span style="color: #808080; font-style: italic;">                            new orders made using this payment</span>
<span style="color: #808080; font-style: italic;">                            method?</span>
<span style="color: #808080; font-style: italic;">                        --&gt;</span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order_status</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>New order status<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>adminhtml/system_config_source_order_status_processing<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>5<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                            this field lets the user choose the</span>
<span style="color: #808080; font-style: italic;">                            name of the payment method as it</span>
<span style="color: #808080; font-style: italic;">                            appears to the normal user on your site</span>
<span style="color: #808080; font-style: italic;">                        -&gt;</span>
<span style="color: #808080; font-style: italic;">                        &lt;title translate=&quot;label&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;label&gt;Title&lt;/label&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;frontend_type&gt;text&lt;/frontend_type&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;sort_order&gt;6&lt;/sort_order&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;show_in_default&gt;1&lt;/show_in_default&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;show_in_website&gt;1&lt;/show_in_website&gt;</span>
<span style="color: #808080; font-style: italic;">                            &lt;show_in_store&gt;0&lt;/show_in_store&gt;</span>
<span style="color: #808080; font-style: italic;">                        &lt;/title&gt;</span>
<span style="color: #808080; font-style: italic;">                    &lt;/fields&gt;</span>
<span style="color: #808080; font-style: italic;">                &lt;/modulename&gt;</span>
<span style="color: #808080; font-style: italic;">            &lt;/groups&gt;</span>
<span style="color: #808080; font-style: italic;">        &lt;/payment&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;/sections&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;/config&gt;</span></pre></td></tr></table></div>

<p><strong>Default configuration values</strong></p>
<p>Before we go and test this, we should set some default values for the configuration fields we just created.</p>
<p>Open app/code/local/MyModules/ModuleName/etc/config.xml and add the following section;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code6'); return false;">View Code</a> XML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1366"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p136code6"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    ...
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    is this payment method enabled?</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this is where we tell the system what</span>
<span style="color: #808080; font-style: italic;">                    class to use to handle all of the payment</span>
<span style="color: #808080; font-style: italic;">                    logic. we call this class the payment</span>
<span style="color: #808080; font-style: italic;">                    adapter model class. you can change the</span>
<span style="color: #808080; font-style: italic;">                    paymentLogic bit to be what you want</span>
<span style="color: #808080; font-style: italic;">                    but it has to be lowerCamelCase and</span>
<span style="color: #808080; font-style: italic;">                    the class name will have to be changed later</span>
<span style="color: #808080; font-style: italic;">                    on as you will see</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modulename/paymentLogic<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;order_status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pending<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/order_status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Credit Card (My Payment Method)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1234<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;api_secret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1234<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/api_secret<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this is the default set of allowed credit</span>
<span style="color: #808080; font-style: italic;">                    card types. leave this as it is for now</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cctypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AE,VI,MC,DI,SS<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cctypes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this should be authorize or authorize_capture</span>
<span style="color: #808080; font-style: italic;">                    you can probably guess that authorize just</span>
<span style="color: #808080; font-style: italic;">                    authorizes the payment but authorize_capture</span>
<span style="color: #808080; font-style: italic;">                    processes it as well</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;payment_action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>authorize_capture<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/payment_action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
                <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">                    this field is used to say whether you only</span>
<span style="color: #808080; font-style: italic;">                    want this method to be used for certain</span>
<span style="color: #808080; font-style: italic;">                    countries but that is not covered by this</span>
<span style="color: #808080; font-style: italic;">                    tutorial</span>
<span style="color: #808080; font-style: italic;">                --&gt;</span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allowspecific<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/allowspecific<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modulename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/payment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Of course, if you have any of the fields in the above file configurable as set in system.xml, the user set value will be used.</p>
<p><strong>Test progress so far</strong></p>
<p>OK so now if you log into the Magento administration and go to System -&gt; Configuration -&gt; Payment methods you should see your new payment method somewhere in that list.</p>
<p>If you enable it it should then also be available if you checkout on your site as normal. Don&#8217;t complete any orders using it yet as there will be problems because we haven&#8217;t finished! We still need to create the most important part, the class which will handle all of the logic.</p>
<p>If you don&#8217;t see your payment method, please make sure you have completed the above steps correctly. Check for any simple mistakes and try clearing the Magento cache as well. The basic rule is; if it doesn&#8217;t appear in the payment method list in the administration section, there&#8217;s a problem with system.xml. If it doesn&#8217;t appear as a usable payment method when checking out, there could be a problem with config.xml.</p>
<h2><a name="4">Payment adapter model class</a></h2>
<p>Create the file PaymentLogic.php in app/code/local/MyModules/ModuleName/Model/. This is where we will put all of our payment gateway logic. First, the contents of the file;</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p136code7'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1367"><td class="line_numbers"><pre>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
83
84
85
86
87
88
89
90
91
92
93
94
</pre></td><td class="code" id="p136code7"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> CompanyName_NewModule_Model_PaymentLogic <span style="color: #000000; font-weight: bold;">extends</span> Mage_Payment_Model_Method_Cc
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * unique internal payment method identifier
     */</span>
    protected <span style="color: #000088;">$_code</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'newmodule'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * this should probably be true if you're using this
     * method to take payments
     */</span>
    protected <span style="color: #000088;">$_isGateway</span>               <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method authorise?
     */</span>
    protected <span style="color: #000088;">$_canAuthorize</span>            <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method capture funds?
     */</span>
    protected <span style="color: #000088;">$_canCapture</span>              <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can we capture only partial amounts?
     */</span>
    protected <span style="color: #000088;">$_canCapturePartial</span>       <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method refund?
     */</span>
    protected <span style="color: #000088;">$_canRefund</span>               <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method void transactions?
     */</span>
    protected <span style="color: #000088;">$_canVoid</span>                 <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can admins use this payment method?
     */</span>
    protected <span style="color: #000088;">$_canUseInternal</span>          <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * show this method on the checkout page
     */</span>
    protected <span style="color: #000088;">$_canUseCheckout</span>          <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * available for multi shipping checkouts?
     */</span>
    protected <span style="color: #000088;">$_canUseForMultishipping</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * can this method save cc info for later use?
     */</span>
    protected <span style="color: #000088;">$_canSaveCc</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * this method is called if we are just authorising
     * a transaction
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> authorize <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * this method is called if we are authorising AND
     * capturing a transaction
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> capture <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * called if refunding
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> refund <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$amount</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * called if voiding a payment
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> void <span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$payment</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>If the payment_action option of &#8216;Authorise&#8217; has been selected, then only the authorize() method will be called and no payment can be taken automatically. If however the payment_action &#8216;Authorise and Capture&#8217; was selected, then only the capture() method will be called and that method should probably authorise the payment before capturing the funds. A bit confusing and not explained anywhere but that&#8217;s how it works!</p>
<p>The Varien_Object $payment object holds all data to do with the transaction and also the order.</p>
<p>So that&#8217;s it! That&#8217;s the method I used to add a custom payment gateway to Magento. Please note: I don&#8217;t work with Magento anymore so if you have a complicated question which requires looking into Magento code, I probably won&#8217;t be able to answer it &#8211; but ask anyway just in case!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.s-gray.com/2009/11/11/magento-create-a-custom-payment-method/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

