1

I have create a custom payment method extension. It is supposed to ask users to enter bank info. It shows fine on admin page, but doesn't show in frontend. Please tell me what is missing.

Here is config.xml - local/Mine/Payments/etc

  <?xml version="1.0"?>
 <config>
<modules>
  <Mine_Payments>
    <version>1.0.0</version>
  </Mine_Payments>
</modules>

<global>
  <fieldsets>
    <sales_convert_quote_payment>
      <holder_name>
        <to_order_payment>*</to_order_payment>
      </holder_name>
      <bank_name>
        <to_order_payment>*</to_order_payment>
      </bank_name>
      <account_number>
        <to_order_payment>*</to_order_payment>
      </account_number>
      <bank_address1>
        <to_order_payment>*</to_order_payment>
      </bank_address1>
      <swift_code>
        <to_order_payment>*</to_order_payment>
      </swift_code>
      <cvv>
        <to_order_payment>*</to_order_payment>
      </cvv>
      <billing_zip>
        <to_order_payment>*</to_order_payment>
      </billing_zip>
      <aba_routing>
        <to_order_payment>*</to_order_payment>
      </aba_routing>
    </sales_convert_quote_payment>
  </fieldsets>

  <blocks>
    <mine_payments>
      <class>Mine_Payments_Block</class>
    </mine_payments>
  </blocks>

  <models>
    <mine_payments>
      <class>Mine_Payments_Model</class>
    </mine_payments>
  </models>

  <helpers>
    <mine_payments>
      <class>Mine_Payments_Helper</class>
    </mine_payments>
  </helpers>

  <resources>
    <mine_payments_setup>
      <setup>
        <module>Mine_Payments</module>
      </setup>
    </mine_payments_setup>
  </resources>

</global>

<default>
  <payment>
    <mine>
      <active>1</active>
      <model>mine_payments/banktransfer</model>
      <order_status>pending</order_status>
      <title>My Bank Transfer</title>
      <allowspecific>0</allowspecific>
      <payment_action>sale</payment_action>
    </mine>
  </payment>
</default>

<frontend>
  <routers>
    <mine>
      <use>standard</use>
      <args>
        <module>Mine_Payments</module>
        <frontName>mine_payments</frontName>
      </args>
    </mine>
  </routers>
</frontend>

Here is system.xml - local/Mine/Payments/etc

<?xml version="1.0"?>
<config>
 <sections>
      <payment>
          <groups>
              <mine translate="label" module="mine_payments">
                  <label>My Bank Transfer</label>
                  <sort_order>670</sort_order>
                  <show_in_default>1</show_in_default>
                  <show_in_website>1</show_in_website>
                  <show_in_store>0</show_in_store>
                  <fields>
                      <active translate="label">
                          <label>Enabled</label>
                          <frontend_type>select</frontend_type>
                          <source_model>adminhtml/system_config_source_yesno</source_model>
                          <sort_order>1</sort_order>
                          <show_in_default>1</show_in_default>
                          <show_in_website>1</show_in_website>
                          <show_in_store>0</show_in_store>
                      </active>
                      <title translate="label">
                          <label>Title</label>
                          <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>
                      <order_status translate="label">
                          <label>New Order Status</label>
                          <frontend_type>select</frontend_type>
                          <source_model>adminhtml/system_config_source_order_status_new</source_model>
                          <sort_order>3</sort_order>
                          <show_in_default>1</show_in_default>
                          <show_in_website>1</show_in_website>
                          <show_in_store>0</show_in_store>
                      </order_status>
                      <allowspecific translate="label">
                        <label>Payment from Applicable Countries</label>
                        <frontend_type>allowspecific</frontend_type>
                        <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>
                        <sort_order>4</sort_order>
                      </allowspecific>
                      <specificcountry translate="label">
                        <label>Payment from Specific Countries</label>
                        <frontend_type>multiselect</frontend_type>
                        <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>
                        <sort_order>5</sort_order>
                        <can_be_empty>1</can_be_empty>
                      </specificcountry>
                      <sort_order translate="label">
                          <label>Sort Order</label>
                          <frontend_type>text</frontend_type>
                          <sort_order>6</sort_order>
                          <show_in_default>1</show_in_default>
                          <show_in_website>1</show_in_website>
                          <show_in_store>1</show_in_store>
                          <frontend_class>validate-number</frontend_class>
                      </sort_order>
                  </fields>
              </mine>
          </groups>
      </payment>
  </sections>

Here is a Model - local/Mine/Payments/Model/Banktransfer.php

<?php
class Mine_Payments_Model_Banktransfer extends  Mage_Payment_Model_Method_Abstract
{
  protected $_code = 'mine_banktransfer';
  protected $_formBlockType = 'mine_payments/form_banktransfer';
  protected $_infoBlockType = 'mine_payments/info_banktransfer';

  public function assignData($data)
  {
      if (!($data instanceof Varien_Object)) {
          $data = new Varien_Object($data);
      }
      $info = $this->getInfoInstance();

      if ($data->getHolderName()){
          $info->setHolderName($data->getHolderName());
      }

      if ($data->getBankName()){
          $info->setBankName($data->getBankName());
      }

      if ($data->getAccountNumber()){
        $info->setAccountNumber($data->getAccountNumber());
      }

      if ($data->getBankAddress1()){
          $info->setBankAddress1($data->getBankAddress1());
      }

      if ($data->getSwiftCode()){
          $info->setSwiftCode($data->getSwiftCode());
      }

      if ($data->getBillingZip()){
          $info->setBillingZip($data->getBillingZip());
      }

      if ($data->getCvv()){
          $info->setCvv($data->getCvv());
      }

      if ($data->getAbaRouting()){
          $info->setAbaRouting($data->getAbaRouting());
      }

      return $this;
  }

  public function validate()
  {
      parent::validate();

      $info = $this->getInfoInstance();

      if(empty($info->getHolderName())){
          $errorCode = 'invalid_data';
          $errorMsg = $this->_getHelper()->__('Holder Name is a required field.');
      }

      if(empty($info->getBankName())){
          $errorCode = 'invalid_data';
          $errorMsg = $this->_getHelper()->__('Bank Name is a required field.');
      }

      if(empty($info->getAccountNumber())){
          $errorCode = 'invalid_data';
          $errorMsg = $this->_getHelper()->__('Account Number is a required field.');
      }

      if(empty($info->getBankAddress1())){
          $errorCode = 'invalid_data';
          $errorMsg = $this->_getHelper()->__('Bank Address is a required field.');
      }

      if(empty($info->getSwiftCode())){
          $errorCode = 'invalid_data';
          $errorMsg = $this->_getHelper()->__('SWIFT Code is a required field.');
      }

      if(empty($info->getBillingZip())){
          $errorCode = 'invalid_data';
          $errorMsg = $this->_getHelper()->__('Billing Zip is a required field.');
      }

      if(empty($info->getCvv())){
          $errorCode = 'invalid_data';
          $errorMsg = $this->_getHelper()->__('CVV is a required field.');
      }

      if($errorMsg){
          Mage::throwException($errorMsg);
      }
      return $this;
  }

 }

Here is Helper. - local/Mine/Payments/Helper/Data.php

<?php

 class Mine_Payments_Helper_Data extends Mage_Core_Helper_Abstract
 {
 }

Here is Form - local/Mine/Payments/Block/Form/Banktransfer.php

<?php
class Mine_Payments_Block_Form_Banktransfer extends Mage_Payment_Block_Form
{
protected function _construct()
{
    parent::_construct();
    $this->setTemplate('mine/form/banktransfer.phtml');
}
}

Here is Info - local/Mine/Payments/Block/Info/Banktransfer.php

<?php
class Mine_Payments_Block_Info_Banktransfer extends Mage_Payment_Block_Info
{
protected function _prepareSpecificInformation($transport = null)
{
    if (null !== $this->_paymentSpecificInformation) {
        return $this->_paymentSpecificInformation;
    }
    $info = $this->getInfo();
    $transport = new Varien_Object();
    $transport = parent::_prepareSpecificInformation($transport);
    $transport->addData(array(
        Mage::helper('payment')->__('Holder Name') => $info->getHolderName(),
        Mage::helper('payment')->__('Bank Name') => $info->getBankName(),
        Mage::helper('payment')->__('Account Number') => $info->getAccountNumber(),
        Mage::helper('payment')->__('SWIFT Code') => $info->getSwiftCode(),
        Mage::helper('payment')->__('Billing Zip') => $info->getBillingZip(),
        Mage::helper('payment')->__('CVV') => $info->getCvv(),
        Mage::helper('payment')->__('ABA routing') => $info->getAbaRouting(),
        Mage::helper('payment')->__('Bank Address') => $info->getBankAddress1()
    ));
    return $transport;
}
}

Here is form phtml. - base/default/template/mine/from/banktransfer.pthml

<?php $_code=$this->getMethodCode() ?>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
<li>
    <label for="<?php echo $_code ?>_holder_name" class="required"><em>*</em><?php echo $this->__('Holder Name') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('Holder Name') ?>" class="input-text required-entry" id="<?php echo $_code ?>_holder_name" name="payment[holder_name]" value="<?php echo $this->htmlEscape($this->getInfoData('holder_name')) ?>" />
    </span>
</li>
<li>
    <label for="<?php echo $_code ?>_bank_name" class="required"><em>*</em><?php echo $this->__('Bank Name') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('Bank Name') ?>" class="input-text required-entry" id="<?php echo $_code ?>_bank_name" name="payment[bank_name]" value="<?php echo $this->htmlEscape($this->getInfoData('bank_name')) ?>" />
    </span>
</li>
<li>
    <label for="<?php echo $_code ?>_account_number" class="required"><em>*</em><?php echo $this->__('Account Number:') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('Account Number:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_account_number" name="payment[account_number]" value="<?php echo $this->htmlEscape($this->getInfoData('account_number')) ?>" />
    </span>
</li>
<li>
    <label for="<?php echo $_code ?>_aba_routing"><?php echo $this->__('ABA routing:') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('ABA routing:') ?>" class="input-text" id="<?php echo $_code ?>_aba_routing" name="payment[aba_routing]" value="<?php echo $this->htmlEscape($this->getInfoData('aba_routing')) ?>" />
    </span>
</li>
<li>
    <label for="<?php echo $_code ?>_swift_code" class="required"><em>*</em><?php echo $this->__('SWIFT Code:') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('SWIFT Code:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_swift_code" name="payment[swift_code]" value="<?php echo $this->htmlEscape($this->getInfoData('swift_code')) ?>" />
    </span>
</li>
<li>
    <label for="<?php echo $_code ?>_bank_address1" class="required"><em>*</em><?php echo $this->__('Bank Address:') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('Bank Address:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_bank_address1" name="payment[bank_address1]" value="<?php echo $this->htmlEscape($this->getInfoData('bank_address1')) ?>" />
    </span>
</li>
<li>
    <label for="<?php echo $_code ?>_billing_zip" class="required"><em>*</em><?php echo $this->__('Billing Zip:') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('Billing Zip:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_billing_zip" name="payment[billing_zip]" value="<?php echo $this->htmlEscape($this->getInfoData('billing_zip')) ?>" />
    </span>
</li>
<li>
    <label for="<?php echo $_code ?>_cvv" class="required"><em>*</em><?php echo $this->__('CVV:') ?></label>
    <span class="input-box">
        <input type="text" title="<?php echo $this->__('CVV:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_cvv" name="payment[cvv]" value="<?php echo $this->htmlEscape($this->getInfoData('cvv')) ?>" />
    </span>
</li>
</ul>
<div>
<?php echo $this->getMethod()->getConfigData('message');?>
</div>
  • I researched many posts in Internet. Finally, made it work. In config.xml, <mine> (in default/payment and frontend/routers tags)should've been <mine_banktransfer> I am not sure why it has to be. But just wondering if it has to be the same with the model's (Mine_Payments_Model_Banktransfer) $_code. – softalent Dec 10 '16 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.