Hi there! I'm working on Magento CE 1.9.3.2, and I'm trying to set up a custom payment method. The module is enabled in the admin panel, and the payment method is enabled in the settings. The back-end works well, but it doesn't show up in the front-end. I literally copied the files from this guide (changing all the names, obviously):
But, even then, it doesn't work. Where's the error? I've tried like three different times but I don't know where I'm making mistakes.
Here are the files:
DNAFactory - Custompaymentmethod --Block ---Form ----Custompaymentmethod.php ---Info ----Custompaymentmethod.php --Helper ---Data.php --Model ---Paymentmethod.php --etc ---config.xml ---system.xml --sql ---custompaymentmethod_setup ----install-1.0.0.0.php
config.xml:
<?xml version="1.0"?>
<config>
<modules>
<DNAFactory_Custompaymentmethod>
<version>1.0.0.0</version>
</DNAFactory_Custompaymentmethod>
</modules>
<global>
<fieldsets>
<sales_convert_quote_payment>
<custom_field_one>
<to_order_payment>*</to_order_payment>
</custom_field_one>
<custom_field_two>
<to_order_payment>*</to_order_payment>
</custom_field_two>
</sales_convert_quote_payment>
</fieldsets>
<helpers>
<custompaymentmethod>
<class>DNAFactory_Custompaymentmethod_Helper</class>
</custompaymentmethod>
</helpers>
<blocks>
<custompaymentmethod>
<class>DNAFactory_Custompaymentmethod_Block</class>
</custompaymentmethod>
</blocks>
<models>
<custompaymentmethod>
<class>DNAFactory_Custompaymentmethod_Model</class>
</custompaymentmethod>
</models>
<resources>
<custompaymentmethod_setup>
<setup>
<module>DNAFactory_Custompaymentmethod</module>
</setup>
</custompaymentmethod_setup>
</resources>
</global>
<default>
<payment>
<custompaymentmethod>
<active>1</active>
<model>custompaymentmethod/paymentmethod</model>
<order_status>pending</order_status>
<title>CustomPaymentMethod</title>
<allowspecific>0</allowspecific>
<payment_action>sale</payment_action>
</custompaymentmethod>
</payment>
</default>
<frontend>
<routers>
<custompaymentmethod>
<use>standard</use>
<args>
<module>DNAFactory_Custompaymentmethod</module>
<frontName>custompaymentmethod</frontName>
</args>
</custompaymentmethod>
</routers>
</frontend>
</config>system.xml:
<?xml version="1.0"?>
<config>
<sections>
<payment>
<groups>
<custompaymentmethod translate="label" module="custompaymentmethod">
<label>CustomPaymentMethod Module</label>
<sort_order>1000</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<title translate="label">
<label>Title</label>
<frontend_type>text</frontend_type>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<sort_order>1</sort_order>
</title>
<active translate="label">
<label>Enabled</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<sort_order>2</sort_order>
</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>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<sort_order>3</sort_order>
</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>
</specificcountry>
</fields>
</custompaymentmethod>
</groups>
</payment>
</sections>
</config>install-1.0.0.0.php:
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
ALTER TABLE `{$installer->getTable('sales/quote_payment')}`
ADD `custom_field_one` VARCHAR( 255 ) NOT NULL,
ADD `custom_field_two` VARCHAR( 255 ) NOT NULL;
ALTER TABLE `{$installer->getTable('sales/order_payment')}`
ADD `custom_field_one` VARCHAR( 255 ) NOT NULL,
ADD `custom_field_two` VARCHAR( 255 ) NOT NULL;
");
$installer->endSetup();Model/Paymentmethod.php:
<?php
/**
* Created by PhpStorm.
* User: miche
* Date: 20/02/2017
* Time: 13:34
*/
class Envato_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract {
protected $_code = 'custompaymentmethod';
protected $_formBlockType = 'custompaymentmethod/form_custompaymentmethod';
protected $_infoBlockType = 'custompaymentmethod/info_custompaymentmethod';
public function assignData($data)
{
$info = $this->getInfoInstance();
if ($data->getCustomFieldOne())
{
$info->setCustomFieldOne($data->getCustomFieldOne());
}
if ($data->getCustomFieldTwo())
{
$info->setCustomFieldTwo($data->getCustomFieldTwo());
}
return $this;
}
public function validate()
{
parent::validate();
$info = $this->getInfoInstance();
if (!$info->getCustomFieldOne())
{
$errorCode = 'invalid_data';
$errorMsg = $this->_getHelper()->__("CustomFieldOne is a required field.\n");
}
if (!$info->getCustomFieldTwo())
{
$errorCode = 'invalid_data';
$errorMsg .= $this->_getHelper()->__('CustomFieldTwo is a required field.');
}
if ($errorMsg)
{
Mage::throwException($errorMsg);
}
return $this;
}
public function getOrderPlaceRedirectUrl()
{
return Mage::getUrl('custompaymentmethod/payment/redirect', array('_secure' => false));
}
}Block/Form/Custompaymentmethod.php:
<?php
class DNAFactory_Custompaymentmethod_Block_Form_Custompaymentmethod extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('custompaymentmethod/form/custompaymentmethod.phtml');
}
}Block/Info/Custompaymentmethod.php:
<?php
class DNAFactory_Custompaymentmethod_Block_Info_Custompaymentmethod extends Mage_Payment_Block_Info
{
protected function _prepareSpecificInformation($transport = null)
{
if (null !== $this->_paymentSpecificInformation)
{
return $this->_paymentSpecificInformation;
}
$data = array();
if ($this->getInfo()->getCustomFieldOne())
{
$data[Mage::helper('payment')->__('Custom Field One')] = $this->getInfo()->getCustomFieldOne();
}
if ($this->getInfo()->getCustomFieldTwo())
{
$data[Mage::helper('payment')->__('Custom Field Two')] = $this->getInfo()->getCustomFieldTwo();
}
$transport = parent::_prepareSpecificInformation($transport);
return $transport->setData(array_merge($data, $transport->getData()));
}
}
Helper/Data.php:
<?php
class DNAFactory_Custompaymentmethod_Helper_Data extends Mage_Core_Helper_Abstract
{
}design/frontend/base/default/template/custompaymentmethod/form/custompaymentmethod.phtml:
<div class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
<div>
<label><?php echo $this->__('Custom Field One') ?>*</label>
<span>
<input type="text" title="<?php echo $this->__('Custom Field One') ?>" name="payment[custom_field_one]" value="<?php echo $this->htmlEscape($this->getInfoData('custom_field_one')) ?>" />
</span>
</div>
<div>
<label><?php echo $this->__('Custom Field Two') ?>*</label>
<span>
<input type="text" title="<?php echo $this->__('Custom Field Two') ?>" name="payment[custom_field_two]" value="<?php echo $this->htmlEscape($this->getInfoData('custom_field_two')) ?>" />
</span>
</div>
</div>
<div>
<?php echo $this->getMethod()->getConfigData('message');?>
</div>etc/modules/DNAFactory_Custompaymentmethod.xml:
<?xml version="1.0"?>
<config>
<modules>
<DNAFactory_Custompaymentmethod>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Payment />
</depends>
</DNAFactory_Custompaymentmethod>
</modules>
</config>
Thank you in advice for your precious help! ![]()
Solved! Go to Solution.
I just found the error, a stupid one if you ask me!
I just put:
class Envato_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
Instead of:
class DNAFactory_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
For the model. Now it works!
I just found the error, a stupid one if you ask me!
I just put:
class Envato_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
Instead of:
class DNAFactory_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract
For the model. Now it works!