Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Payment method - new module tutorial
 
yshahin
Jr. Member
 
Total Posts:  28
Joined:  2008-05-14
 

Hi, I’m new to magento and i tried this module but it doesn’t work
and the problem is in the system.xml
i was wondering if there is any documentation for that file?
and what is the source_model?

Thanx

 
Magento Community Magento Community
Magento Community
Magento Community
 
Keints
Jr. Member
 
Total Posts:  5
Joined:  2008-05-21
 

Payment module tutorial in wiki has a few bugs in it.

First, in this example module declaration should be in file “app/etc/modules/Mage_Newodule.xml” not “app/etc/modules/NewModule.xml”

Second, directory name for this module should not be in camelCase. It doesn’t work like this.
“app/code/local/Mage/Newmodule/etc/...” instead of “app/code/local/Mage/NewModule/etc/...”

Same changes must be made in XML files also.

It took me quite some time to figure this out.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Juanky
Jr. Member
 
Total Posts:  4
Joined:  2007-11-29
 

@Mark Robinson: I’ve tried your module and I think it works. I’ve only rename /app/etc/modules/BankTransfer.xml to /app/etc/modules/Mage_BankTransfer.xml.

 
Magento Community Magento Community
Magento Community
Magento Community
 
yshahin
Jr. Member
 
Total Posts:  28
Joined:  2008-05-14
 

my problem was in the system.xml
and turns out that because the node source_module looked like this

<source_module>
adminhtml/system_config_source_yesno
</source_module>

the newline character was the problem, i just removed it and it worked
<source_module>adminhtml/system_config_source_yesno</source_module>

and i used the same camel case and the same name for the xml it didn’t make a difference
maybe its a convention more than a requirement smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Princeanil
Jr. Member
 
Total Posts:  28
Joined:  2008-05-06
 

Hi all

I just need a simple duplicate of the Check / Money Order payment method and I want to call it say “Cash Payment”.
Everything else will remain the same.

How can I achieve that ?

The wiki and all the posts written here are too complex.  Can’t i just duplicate a few files that are used for Check / Money Order payment method and rename the method to “Cash Payment” somewhere

Anil

 Signature 

Anil

 
Magento Community Magento Community
Magento Community
Magento Community
 
Alekc
Jr. Member
 
Total Posts:  15
Joined:  2008-05-29
 

Hi, i was reading wiki post about creating a new payment module, and i noticed that it’s kinda broken. Can someone confirm that this revision (http://www.magentocommerce.com/wiki/how-to/create-payment-method-module?rev=1202202677#example_files) which seemes to be the most recent complete one is still valid for the current version of Magento?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
stereotomy
Jr. Member
 
Total Posts:  25
Joined:  2008-02-10
 

i’ve been struggling for 3 days..

does anyone have any idea how the information fields in the phtml file and .php paired?

ie form.phtml and cc.php (in model)

this goes in Model:

public function createFormBlock($name)
{
$block = $this->getLayout()->createBlock(’eway/shared_form’, $name)
->setMethod(’eway_shared’)
->setTemplate(’eway/shared/form.phtml’)
->setPayment($this->getPayment());
return $block;
}

but how exactly this is paired with form.phtml????

this is getting so desperate…

 
Magento Community Magento Community
Magento Community
Magento Community
 
birches
Member
 
Total Posts:  64
Joined:  2008-05-30
 

Hi, I’m no expert on this, but believe this version you quote is wrong.  There is no need to do the sql install part anymore (I saw this on another thread).

I’ve managed to get the payment method showing in admin using the latest wiki tutorial, my only change was to use name app\etc\modules\Mage_NewModule.xml not \app\etc\modules\NewModule.xml (also found on another thread).

Next step - coding the interface....

Alekc - 29 May 2008 10:35 AM

Hi, i was reading wiki post about creating a new payment module, and i noticed that it’s kinda broken. Can someone confirm that this revision (http://www.magentocommerce.com/wiki/how-to/create-payment-method-module?rev=1202202677#example_files) which seemes to be the most recent complete one is still valid for the current version of Magento?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Member
 
Avatar
Total Posts:  73
Joined:  2008-05-28
Brazil
 

Hi,

I’ve followed the article in the wiki to create a custom payment module but i’m not getting it to work. I’ve created it several times and, for some strange reason, I can access the frontend, but the backend gets stuck into some kind of infinite loop, and I’ve no idea why that’s happening.

Here is the code:

app/etc/modules/FirstAttlantic.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <
modules>
        <!-- declare 
Mage_FacPayment module -->
        <
Mage_FirstAttlantic>
            <!-- 
this is an active module -->
            <
active>true</active>
            
            <!-- 
this module will be located in app/code/local code pool -->
            <
codePool>local</codePool>
            
            <!-- 
specify dependencies for correct module loading order -->
            <
depends>
                <
Mage_Payment />
            </
depends>
            
            <!-- declare 
modules version information for database updates -->
            <
version>0.1.0</version>
        </
Mage_FirstAttlantic>
    </
modules>
</
config>

/app/cod/local/Mage/FirstAttlantic/etc/config.xml

<?xml version="1.0"?>
<config>
    <global>
        <!-- declare 
model group for new module -->
        <
models>
            <!-- 
model group alias to be used in Mage::getModel('firstattlantic/...') -->
            <
firstattlantic>
                <!-- 
base class name for the model group -->
                <class>
Mage_FirstAttlantic_Model</class>
            </
firstattlantic>
        </
models>
        <!-- declare 
resource setup for new module -->
        <
resources>
            <!-- 
resource identifier -->
            <
firstattlantic_setup>
                <!-- 
specify that this resource is a setup resource and used for upgrades -->
                <
setup>
                    <!-- 
which module to look for install/upgrade files in -->
                    <
module>Mage_FirstAttlantic</module>
                </
setup>
                <!-- 
specify database connection for this resource -->
                <
connection>
                    <!-- do 
not create new connection, use predefined core setup connection -->
                    <use>
core_setup</use>
                </
connection>
            </
firstattlantic_setup>
            <
firstattlantic_write>
                <use>
core_write</use>
            </
firstattlantic_write>
            <
firstattlantic_read>
                <use>
core_read</use>
            </
firstattlantic_read>
        </
resources>
    </global>
    <!-- declare default 
configuration values for this module -->
    <default>
        <!-- 
'payment' configuration section (tab) -->
        <
payment>
            <!-- 
'firstattlantic' configuration group (fieldset) -->
            <
firstattlantic>
                <!-- 
by default this payment method is inactive -->
                <
active>0</active>
                <!-- 
model to handle logic for this payment method -->
                <
model>firstattlantic/paymentMethod</model>
                <!-- 
order status for new orders paid by this payment method -->
                <
order_status>1</order_status>
                <!-- default 
title for payment checkout page and order view page -->
                <
title>Credit Card Payment</title>
            </
firstattlantic>
        </
payment>
    </default>
</
config>

 Signature 

Gabriel Queiroz Silva

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Member
 
Avatar
Total Posts:  73
Joined:  2008-05-28
Brazil
 

The last two files:

/app/cod/local/Mage/FirstAttlantic/etc/system.xml

<?xml version="1.0"?>
<config>
    <
sections>
        <!-- 
payment tab -->
        <
payment>
            <
groups>
                <!-- 
firstattlantic fieldset -->
                <
firstattlantic translate="label" module="paygate">
                    <!-- 
will have title 'First Attlantic Commerce Credit Card Payment' -->
                    <
label>First Attlantic Commerce Credit Card Payment</label>
                    
                    <!-- 
position between other payment methods -->
                    <
sort_order>670</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>
                        <!-- 
is this payment method active for the website? -->
                        <
active translate="label">
                            <!-- 
label for the field -->
                            <
label>Enabled</label>
                            
                            <!-- 
input type for configuration value -->
                            <
frontend_type>select</frontend_type>
                            
                            <!-- 
model to take the option values from -->
                            <
source_model>adminhtml/system_config_source_yesno</source_model>
                            
                            <!-- 
field position -->
                            <
sort_order>1</sort_order>
                            
                            <!-- do 
not show this field in store scope -->
                            <
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>
                </
firstattlantic>
            </
groups>
        </
payment>
    </
sections>
</
config>

/app/cod/local/Mage/FirstAttlantic/Model/PaymentMethod.php

<?php

    
/**
      * First Attlantic Credit Card Payment
      */
    
class Mage_FirstAttlantic_Model_PaymentMethod extends Mage_Payment_Model_Method_Cc
    {
        
/**
          * unique internal payment method identifier
          *
          * @var string [a-z0-9_]
          */
        
protected $_code 'firstattlantic';
        
        
/**
          * Here are examples of flags that will determine functionality availability
          * of this module to be used by frontend and backend.
          *
          * @see all flags and their defaults in Mage_Payment_Model_Method_Abstract
          *
          * It is possible to have a custom dynamic logic by overloading
          * public function can* for each flag respectively
          */
        
        /**
          * Is this payment method a gateway (online auth/charge) ?
          */
        
protected $_isGateway               true;
        
        
/**
          * Can authorize online?
          */
        
protected $_canAuthorize            true;
        
        
/**
          * Can capture funds online?
          */
        
protected $_canCapture              true;

        
/**
          * Can capture partial amounts online?
          */
        
protected $_canCapturePartial       false;
        
        
/**
          * Can refund online?
          */
        
protected $_canRefund               false;
        
        
/**
          * Can void transactions online?
          */
        
protected $_canVoid                 true;
        
        
/**
          * Can use this payment method in administration panel?
          */
        
protected $_canUseInternal          true;
        
        
/**
          * Can show this payment method as an option on checkout payment page?
          */
        
protected $_canUseCheckout          true;
        
        
/**
          * Is this payment method suitable for multi-shipping checkout?
          */
        
protected $_canUseForMultishipping  true;
        
        
/**
          * Can save credit card information for future processing?
          */
        
protected $_canSaveCc false;
        
        
/**
          * Here you will need to implement authorize, capture and void public methods
          *
          * @see examples of transaction specific public methods such as
          * authorize, capture and void in Mage_Paygate_Model_Authorizenet
          */
    
}

I’m going to start digging into the core classes now, but, in case any of you have had this same problem, please let me know.

Many thanks,

 Signature 

Gabriel Queiroz Silva

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Member
 
Avatar
Total Posts:  73
Joined:  2008-05-28
Brazil
 

Ok, I’ve just got it. I still don’t understand exactly why this happens, but here it goes:

After digging into the code, i’ve noticed that it was getting stuck in the following loop in app/code/core/Mage/Core/Model/Config.php (line 248):

while (!empty($unsortedModules)) {
            
foreach ($unsortedModules as $moduleName=>$module{
                
if (empty($module['parents'])) {
                    $sortedModules[$moduleName] 
$unsortedConfig->getNode('modules/'.$moduleName);
                    unset(
$unsortedModules[$moduleName]);
                    if (!empty(
$module['children'])) {
                        
foreach ($module['children'as $childName=>$dummy{
                            
unset($unsortedModules[$childName]['parents'][$moduleName]);
                        
}
                    }
                    
break;
                
}
            }
        }

This is the code which creates an ordered array with the Modules to be loaded. The module I’ve created depends on the Mage_Payment module, so $module[’parents’] wasn’t empty, so the condition for the first if was never true and the module never get out of $unsortedModules array, so the infinite loop (while (!empty($unsortedModules)) ).

It works now because I’ve noticed that Mage_Payment was listed on Mage_All.xml and it was loaded everytime, so I’ve taken out the dependency from the FirstAttlantic.xml file.

The part I still didn’t get was: Mage_All.xml has modules which have dependencies like my module did. For example:

<Mage_Page>
            <
active>true</active>
            <
codePool>core</codePool>
            <
depends>
                <
Mage_Core />
            </
depends>
        </
Mage_Page>

but this module never got stuck in the loop…

It seems to be a bug for me. Have anyone experienced this as well?

 Signature 

Gabriel Queiroz Silva

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Member
 
Avatar
Total Posts:  73
Joined:  2008-05-28
Brazil
 

Ops! Fourth post in a row! Sorry about that!

But, indeed, it really seems to be a bug. If I change the module definition xml file name from “FirstAttlantic.xml” to “NFirstAttlantic.xml”, then it runs smoothly, even with the dependency.

I was looking through the thread and I’ve noticed that none of the codes have a module which first letter came before “M”.

Moshe and the other guys: Can you pls confirm this?

Magento version here: 1.0.19870
PHP Version 5.2.5
OS: Windows 2003 Server (unfortunatelly)

Maybe on linux the files are being sorted by date added instead of file name.

Best Regards,

 Signature 

Gabriel Queiroz Silva

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gabriel Queiroz
Member
 
Avatar
Total Posts:  73
Joined:  2008-05-28
Brazil
 

Sorry about the infinite posts, but I’ve spent the weekend over this and I think it’s an important info in case you’re not interested on the working-while-your-friends-are-drinking thing. smile

If you’re doing your module based on Authorizenet, as suggested by the wiki, your config.xml need to have all tha data that’s on Autorizenet’s config.xml. So:

<payment>
  <
firstattlanticcc>
    <
active>1</active>
    <
cctypes>AE,VI,MC,DI</cctypes>
    <
cgi_url>https://secure.authorize.net/gateway/transact.dll</cgi_url>
    
<debug>0</debug>
    <
email_customer>0</email_customer>
    <
login backend_model="adminhtml/system_config_backend_encrypted"/>
    <
merchant_email></merchant_email>
    <
model>firstAttlantic/creditCard</model>
    <
order_status>1</order_status>
    <
payment_action>authorize</payment_action>
    <
test>1</test>
    <
title>Credit Card</title>
    <
trans_key backend_model="adminhtml/system_config_backend_encrypted"/>
    <
allowspecific>0