Magento Forum

   
Payment method - new module tutorial
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

yes thats right, wiki how to is out of date. iam working at my own paymentmodule and will post the results soon. Paymentmethod with own template and paygate.

KR

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

Your update will be most appreciated, thanks.  Hopefully it’ll help me past the adminhtml issues I’m currently experiencing with developing my own module.  Since .8 it seems like this has changed significantly.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

...... sorry, awnsered wrong thread ....

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

hi guys,

i have already developed my first payment model for checkout. this is the special payment model for German market called Lastschrift (debit advice). the buyer must enter the owner of the account, the bank and bank code in the form. the new model is totally integrated in the checkout process (the method of the option of the payment, notification form, validity, notification of the dates in the information sphere, gathering of the dates for the order and expenditure of the dates in Backend). The code is not totally regulated , here i have copied the parts of other models. as soon as it is regulated, i will give the code into ur disposal and post it here.

But there are some open questions:

* i updated version from 0.0.1 to 0.0.2 in config.xml, created a new mysql4-install-0.0.2.php but my changes were not written in the database. i searched the database and found one entry in table “core_resource” which owns the actual version, i had to delete this row and the last datas in “core_config_data”. How could i manage that automaticly, by a mysql4-uninstall-0.0.1.php?

* i added some code to app\code\core\Mage\Sales\Model\Convert\Oder.php and Quote.php, i think thats not the best way, right? Better to overwrite the Model?

public function paymentToQuotePayment(Mage_Sales_Model_Order_Payment $payment$quotePayment=null)
    
{
        
if (!($quotePayment instanceof Mage_Sales_Model_Quote_Payment)) {
            $quotePayment 
Mage::getModel('sales/quote_payment');
        
}
        
        
        
        $quotePayment
->setStoreId($payment->getStoreId())
            ->
setCustomerPaymentId($payment->getCustomerPaymentId())
            ->
setMethod($payment->getMethod())
            ->
setAdditionalData($payment->getAdditionalData())
            ->
setPoNumber($payment->getPoNumber())
            ->
setCcType($payment->getCcType())
            ->
setCcNumberEnc($payment->getCcNumberEnc())
            ->
setCcLast4($payment->getCcLast4())
            ->
setCcOwner($payment->getCcOwner())
            ->
setCcCidEnc($payment->getCcCidEnc())
            ->
setCcExpMonth($payment->getCcExpMonth())
            ->
setCcExpYear($payment->getCcExpYear())
            
            
//My Code
            
->setHpdaAccountOwner($payment->getHpdaAccountOwner())
            ->
setHpdaAccountNumber($payment->getHpdaAccountNumber())
            ->
setHpdaBankCode($payment->getHpdaBankCode())
            ->
setHpdaBank($payment->getHpdaBank());
            
        return 
$quotePayment;
    
}

Also for paymentToOrderPayment in Quote.php.

Cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

@[m]zentrale:  How did you develop then install that module?  I’m working on a custom module myself and don’t know how to get Magento to read mysql-install-0.1.0.php (which is what I have).  How do you get this read?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

here is my config.xml

<config>
  <
modules>
    <!-- declare 
module's version information -->
    <Mage_Heidelpaydebitadvice>
      <!-- this version number will be used for database upgrades -->
      <version>0.0.2</version>
    </Mage_Heidelpaydebitadvice>
  </modules>
  <global>

....................

    <!-- declare resource setup for new module -->
    <resources>
      <!-- resource identifier -->
      <heidelpaydebitadvice_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_Heidelpaydebitadvice</module>
        </setup>
        <!-- specify database connection for this resource -->
        <connection>
          <!-- do not create new connection, use predefined core setup connection -->
          <use>core_setup</use>
        </connection>
      </heidelpaydebitadvice_setup>
    </resources>    
  </global>
  
...................
<!-- Database inserts and setting values from tutorial  is done by following code (I hope :-)) -->
<default>
        <payment>       
            <heidelpaydebitadvice>               
                <active>1</active> <!-- mode de paiement enabled ou disabled?-->
                <debug>1</debug>
                <model>heidelpaydebitadvice/heidelpaydebitadvice</model>
                <order_status>1</order_status>
                <!--<payment_action>authorize</payment_action>-->                
                <title>Lastschrifteinzug</title>                
                <allowspecific>0</allowspecific>
            </heidelpaydebitadvice>
        </payment>
    </default>  
</config>

Example for SQL from tutorial is obsolete. These query are now made by config.xml, look for my comments in xml. This part of xml-code replaces the sql querys in howto for new payment module. if you want to make db inserts you can take a look at my following code in file called mysql4-install-0.0.2.php in folder sql/mymodule_setup, in my example its sql/heidelpaydebitadvice_setup. The suffix of filename (0.0.2 in my example) must match with version set in config.xml

<?php
$this
->startSetup()->run("
select 
    @entity_type_id:=entity_type_id from eav_entity_type
where 
    entity_type_code='order_payment';

insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_account_owner', 'hpda_account_owner', 'varchar', 'text', 'Account owner'); 
    
insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_account_number', 'hpda_account_number', 'varchar', 'text', 'Account number'); 

insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_bank_code', 'hpda_bank_code', 'varchar', 'text', 'Bank code'); 

insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_bank', 'hpda_bank', 'varchar', 'text', 'Bank'); 
    
"
)->endSetup(); 

$this->startSetup()->run("
select 
    @entity_type_id:=entity_type_id from eav_entity_type
where 
    entity_type_code='quote_payment';

insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_account_owner', 'hpda_account_owner', 'varchar', 'text', 'Account owner'); 
    
insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_account_number', 'hpda_account_number', 'varchar', 'text', 'Account number'); 

insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_bank_code', 'hpda_bank_code', 'varchar', 'text', 'Bank code'); 

insert into eav_attribute
    (entity_type_id, attribute_name, attribute_code, backend_type, frontend_input, frontend_label)
values 
    (@entity_type_id, 'hpda_bank', 'hpda_bank', 'varchar', 'text', 'Bank'); 
    
"
)->endSetup(); 
?>

I hope my english is “understandable”, its not the best, but i try to improve my written english. And i hope i explained the right thinks....

Cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

oh sorry, i was wrong, the inserts done by the sql in howto of new payment module isnt done by the config.xml, its done by the system.xml also located in etc folder. take a look:

<config>
   <
sections>
        <
payment>
            <
groups>
                <
heidelpaydebitadvice translate="label" module="heidelpaydebitadvice">
                     <
label>Lastschriftverfahren Heidelpay</label>
                    <
frontend_type>text</frontend_type>
                    <
sort_order>0</sort_order>
                    <
show_in_default>1</show_in_default>
                    <
show_in_website>1</show_in_website>
                    <
show_in_store>1</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>
                        <
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>
                        <
sort_order translate="label">                            
                            <
label>Sort order</label>
                            <
frontend_type>text</frontend_type>
                            <
sort_order>100</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>                        
                        <
debug translate="label">
                            <!-- 
debug mode -->
                            <
label>Debug</label>
                            <
frontend_type>select</frontend_type>
                            <
source_model>adminhtml/system_config_source_yesno</source_model>
                            <
sort_order>6</sort_order>
                            <
show_in_default>1</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>0</show_in_store>
                        </
debug>
                        <
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>                      
                        <
allowspecific translate="label">
                            <
label>Payment to applicable countries</label>
                            <
frontend_type>allowspecific</frontend_type>
                            <
sort_order>50</sort_order>
                            <
source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
                            <
show_in_default>1</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>1</show_in_store>
                        </
allowspecific>
                        <
specificcountry translate="label">
                            <
label>Payment to Specific countries</label>
                            <
frontend_type>multiselect</frontend_type>
                            <
sort_order>51</sort_order>
                            <
source_model>adminhtml/system_config_source_country</source_model>
                            <
show_in_default>1</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>1</show_in_store>
                        </
specificcountry>
                        <
model>
                        </
model>
                    </
fields>
                </
heidelpaydebitadvice>                
            </
groups>
        </
payment>
    </
sections>
</
config>

The following snippet from config.xml sets the default values:

<default>
        <
payment>
        <!-- 
liste des differentes sous methodes de paiement -->
            <
heidelpaydebitadvice>
                <!-- 
valeurs par defaut des champs dans la partie admin -->
                <
active>1</active> <!-- mode de paiement enabled ou disabled?-->
                <
debug>1</debug>
                <
model>heidelpaydebitadvice/heidelpaydebitadvice</model>
                <
order_status>1</order_status>
                <!--<
payment_action>authorize</payment_action>-->                
                <
title>Lastschrifteinzug</title>                
                <
allowspecific>0</allowspecific>
            </
heidelpaydebitadvice>
        </
payment>
    </default>

cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

@[m]zentrale: OK, maybe I’m being thick here, but:

1) Where in there is the information for the admin interface?
2) How does one get the mysql-setup file to be read?  Is there some installer config you need to do?

Also, I don’t see anywhere how to create a new table, as I need to with my module.

 
Magento Community Magento Community
Magento Community
Magento Community
 
redpen
Sr. Member
 
Total Posts:  254
Joined:  2008-01-23
 

@[m]zentrale - good work here, wish I could understand what you’ve done to create something similiar for ProTX…

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

if paymentmodule is ready developed well post the code here. one question, what is ProTX??

Cheers

Stefan

 
Magento Community Magento Community
Magento Community
Magento Community
 
redpen
Sr. Member
 
Total Posts:  254
Joined:  2008-01-23
 
-

zentrale” date="1204228434"]Hi,

if paymentmodule is ready developed well post the code here. one question, what is ProTX??

Cheers

Stefan

ProTX is a UK payment processor.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi,

if my english would be better i think i could explain my done work better - you see, german grammer in my sentences and too less thesaurus, sorry for that.

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
zburnham
Member
 
Avatar
Total Posts:  69
Joined:  2007-11-07
Westborough, MA
 

Anyone else care to have a stab at explaining [m]zentrale’s code a bit?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 
- 26 February 2008 08:56 AM


But there are some open questions:

* i updated version from 0.0.1 to 0.0.2 in config.xml, created a new mysql4-install-0.0.2.php but my changes were not written in the database. i searched the database and found one entry in table “core_resource” which owns the actual version, i had to delete this row and the last datas in “core_config_data”. How could i manage that automaticly, by a mysql4-uninstall-0.0.1.php?

the upgrade files should be named mysql4-upgrade-0.0.1-0.0.2.php

- 26 February 2008 08:56 AM

* i added some code to app\code\core\Mage\Sales\Model\Convert\Oder.php and Quote.php, i think thats not the best way, right? Better to overwrite the Model?

Yes, you should overload the original class with your model by extending it:

class MZentrale_Module_Model_Convert_Order extends Mage_Sales_Model_Convert_Order
{
    
public function paymentToQuotePayment(Mage_Sales_Model_Order_Payment $payment$quotePayment=null)
    
{
        $quotePayment 
parent::paymentToQuotePayment($payment$quotePayment);

        
//My Code
        
$quotePayment
            
->setHpdaAccountOwner($payment->getHpdaAccountOwner())
            ->
setHpdaAccountNumber($payment->getHpdaAccountNumber())
            ->
setHpdaBankCode($payment->getHpdaBankCode())
            ->
setHpdaBank($payment->getHpdaBank());
            
        return 
$quotePayment;
    
}

To override the model put this in your module/etc/config.xml:

<config>
...
   <global>
...
      <
models>
         <
sales>
            <
rewrite>
               <
convert_order>MZentrale_Module_Model_Convert_Order</convert_order>
            </
rewrite>
         </
sales>
      </
models>
   </global>
</
config>

 
Magento Community Magento Community
Magento Community
Magento Community
 
mzentrale1
Guru
 
Total Posts:  731
Joined:  2007-12-06
Stuttgart, Germany
 

Hi Moshe,

thank you, ill update my module and reporting about success! Thanks.

I tried to upload some pics of my modul but it didnt work, after long loading time i got error?

Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top