1

My Custom Payment Module is appearing on front end but its multiselect field is not loading.

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Magik_Paymentpro>
            <version>0.1.0</version>
        </Magik_Paymentpro>
    </modules> 
   <global>
      <models>
         <paymentpro>
            <class>Magik_Paymentpro_Model</class>
         </paymentpro>
      </models>
   </global>
   <default>
      <payment>
         <paymentpro>
            <active>1</active>
            <model>paymentpro/paymentmethod</model>
            <order_status>processing</order_status>
            <title>TCS Cash Payment Methods</title>
         </paymentpro>
      </payment>
   </default>
</config>  

system.xml

<?xml version="1.0"?>
<config>
<sections>
<!-- payment tab -->
<payment>
<groups>
<!-- paymentpro fieldset -->
<paymentpro translate="label" module="paygate">
<!-- will have title 'Cash On Delivery' -->
<label>TCS Cash Payment Methods</label>
<!-- position between other payment methods -->
<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>
<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</source_model>
<!--<source_model>adminhtml/system_config_source_order_status_new</source_model>-->
<!--<source_model>adminhtml/system_config_source_order_status_processing</source_model>-->
<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>
</order_status>
<title translate="label">
    <label>TCS Cash Payment Methods</label>
    <frontend_type>text</frontend_type>
    <sort_order>3</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</title>                       
<allowspecific translate="label">
<label>Payment from applicable countries</label>
<frontend_type>allowspecific</frontend_type>
<sort_order>4</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 from Specific countries</label>
<frontend_type>multiselect</frontend_type>
<sort_order>5</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>
<cashmethod translate="label">
<label>Cash Method</label>
<frontend_type>multiselect</frontend_type>
<sort_order>6</sort_order>
<source_model>paymentpro/paymentmethod</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</cashmethod>
</fields>
</paymentpro>
</groups>
</payment>
</sections>
</config>

Magik/Paymentpro/Model/Paymentmethod.php

<?php
class Magik_Paymentpro_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
{
    protected $_code  = 'paymentpro';
    protected $_isGateway = true;
    protected $_canAuthorize = true;
    protected $_canCapture = true;
    protected $_canCapturePartial = false;
    protected $_canRefund = true;
    protected $_canVoid = true;
    protected $_canUseInternal = true;
    protected $_canUseCheckout = true;
    protected $_canUseForMultishipping = true;
    protected $_canSaveCc = false;
    //protected $_formBlockType = 'payment/form_checkmo';
    //protected $_infoBlockType = 'payment/info_cod';

    /**
    * Assign data to info model instance
    *
    * @param   mixed $data
    * @return  Mage_Payment_Model_Method_Checkmo
    */

  public function toOptionArray()
  {
    return array(
      array('value' => 0, 'label' => 'Cash On Delivery'),
      array('value' => 1, 'label' => 'Cash At Doorstep')   );
  }
    public function authorize(Varien_Object $payment, $amount){
        $data = $payment->getData();
        /*
        $data = array(
        store_id,
        customer_payment_id,
        method,
        additional_data,
        po_number,
        cc_type,
        cc_number_enc,
        cc_last4,
        cc_owner,
        cc_exp_month,
        cc_exp_year,
        cc_number,
        cc_cid,
        cc_ss_issue,
        cc_ss_start_month,
        cc_ss_start_year,
        parent_id,
        amount_ordered,
        base_amount_ordered,
        shipping_amount,
        base_shipping_amount,
        method_instance)
        */
    }
    public function capture(Varien_Object $payment, $amount){
        // Grab stored payment data array for processing
        $paymentData = unserialize($payment->getAdditionalData());
    }
    public function void(Varien_Object $payment){
        // actions when order is voided occur here
    }
    public function refund(Varien_Object $payment, $amount){
        // actions when order is refunded occur here
    }   
    public function assignData($data){
        $details = array();
        if ($this->getPayableTo()) {
        $details['payable_to'] = $this->getPayableTo();
        }
        if ($this->getMailingAddress()) {
        $details['mailing_address'] = $this->getMailingAddress();
        }
        if (!empty($details)) {
        $this->getInfoInstance()->setAdditionalData(serialize($details));
        }
        return $this;
    }

    public function getPayableTo(){
        return $this->getConfigData('payable_to');
    }

    public function getMailingAddress(){
        return $this->getConfigData('mailing_address');
    }
}

layout/paymentpro.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <catalog_product_view>
        <reference name="product.info">
            <block type="paymentpro/catalog_product_view_profile" name="product.info.additional.recurring.schedule" as="recurring_info" template="paymentpro/catalog/product/view/profile/schedule.phtml">
                <action method="addToParentGroup"><group>detailed_info</group></action>
                <action method="setTitle" translate="value"><value>Recurring Profile</value></action>
            </block>
        </reference>
        <reference name="product.info.options.wrapper">
            <block type="paymentpro/catalog_product_view_profile" name="product.info.options.recurring" as="recurring_options" template="paymentpro/catalog/product/view/profile/options.phtml"/>
        </reference>
    </catalog_product_view>
</layout>

paymentpro/paymentpro.phtml

<?php
// Retrieve order
$_order = new Mage_Sales_Model_Order();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$_order->loadByIncrementId($orderId);
?>
<form name="paymentproform" method="post" action="http://www.gateway.com/the_url_they_gave_me">
    <input type="hidden" name="orderid" value="<?php echo $orderId; ?>">
    <input type="hidden" name="grandtotal" value="<?php echo $_order->getBaseGrandTotal(); ?>">
</form>
<script type="text/javascript">
document.paymentproform.submit();
</script>

etc/modules/Magik_Paymentpro.xml

<?xml version="1.0"?>
<config>
<modules>
<!-- declare Magik_Paymentpro module -->
<Magik_Paymentpro>
<!-- 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 module's version information for database updates -->
<version>0.1.0</version>
</Magik_Paymentpro>
</modules>
</config>

1 Answer 1

1

One of your problems is in Magik/Paymentpro/Model/Paymentmethod.php. You don't have your block type defined.

You need this to tell Magento where to find your payment block:

protected $_formBlockType = 'paymentpro/form_paymentpro';

Next, you don't have a block defined for your extension. In config.xml you need the following in your global section:

<blocks>
    <paymentpro>
        <class>Magik_Paymentpro_Block</class>
    </paymentpro>
</blocks>

You'll need to add the Block in your extension file structure.

Add the following folders and file:

app/code/local/Magik/Paymentpro/Block/Form/Paymentpro.php

Inside Paymentpro.php:

class Magik_Paymentpro_Block_Form_Paymentpro extends Mage_Payment_Block_Form
{
    protected function _construct()
    {
        parent::_construct();

        // This is the template for paymentpro/form/paymentpro.phtml
        // You have this in paymentpro/paymentpro.phtml in your code
        // above and that's ok, but to keep thing consistent you
        // should do it like this.

        $this->setTemplate('paymentpro/form/paymentpro.phtml');
    }
}

Move paymentpro/paymentpro.phtml to paymentpro/form/paymentpro.phtml. You can put the code for your multiselect in there.

The code you have in layout/paymentpro.xml is for recurring profiles. You don't have this set up correctly. You can remove it.

5
  • thanks for your help and effort. still i have a problem in code. i removed the action value from phtml file and there is nothing inside action i.e. action="" now the one page checkout keeps on running and preloader not stopping. what to do.? Please HELP. ITS URRGENTTT !!!! Commented Jan 25, 2015 at 21:42
  • I actually made it work on my local dev environment. Are you trying to submit a form to somewhere else in that phtml? Commented Jan 25, 2015 at 23:44
  • i just want to load multiselect drop down to appear on click. or appear by default. I don't know how to achieve it. Commented Jan 26, 2015 at 6:07
  • If you add my corrections then your payment module will work. You'll need to replace everything you did in your phtml file with new code to create your multiselects. Refer to how Ccsave.php creates this form. You can also use Ccsave as a reference to see how to handle saving that data. In Magik/Paymentpro/Model/Paymentmethod.php add your code for processing the payment in the authorize() and capture() functions. hth Commented Jan 26, 2015 at 19:29
  • I have saved a copy of C:\wamp\www\magento1\app\code\core\Mage\Payment\Block\Form.php to C:\Users\aa\Desktop\Magik\Paymentpro\Block <pre>class Magik_Paymentpro_Block_Form extends Mage_Core_Block_Template</pre> one good thing is that continuous loading is now stopped. but still multiselect is not appearing. and i don't understand what code to add in authorize() and capture(). Please Guide me. m new bee in magento Commented Jan 27, 2015 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.