I learn the Magento 7 days ago, and I try to create a custom model for payment method. I have a problem and I working 3 days, but I cant resolve.
If I change in config.xml
:
<models>
<internship_payment>
<class>Internship_Payment_Model</class>
</internship_payment>
</models>
<internship_payment>
in <payment>
admin/system/confuguration/payment methods
show me this error:
Call to a member function setAllowedTypes() on boolean in C:\xampp\htdocs\intership\magento\app\code\core\Mage\Paypal\Model\Config.php on line 1092
If I keep the internship_payment
, admin work, but i get this error on frontend:
Call to a member function setMethod() on boolean in C:\xampp\htdocs\intership\magento\app\code\core\Mage\Payment\Helper\Data.php on line 106
I follow this tutorial.
- Namespace: Internship
- Module: Payment
config.xml (app/Code/Local/Internship/Payment/etc/config.xml
)
<config>
<modules>
<Internship_Payment>
<version>0.0.1</version>
</Internship_Payment>
</modules>
<default>
<payment>
<payment>
<active>1</active>
<model>payment/pay</model>
<order_status>processing</order_status>
<title>Excellence Payment Method2</title>
</payment>
</payment>
</default>
<global>
<fieldsets>
<sales_convert_quote_payment>
<check_no>
<to_order_payment>*</to_order_payment>
</check_no>
<check_date>
<to_order_payment>*</to_order_payment>
</check_date>
</sales_convert_quote_payment>
</fieldsets>
<blocks>
<payment>
<class>Internship_Payment_Block</class>
</payment>
</blocks>
<models>
<internship_payment>
<class>Internship_Payment_Model</class>
</internship_payment>
</models>
<resources>
<payment_custom_setup>
<setup>
<module>Internship_Payment</module>
</setup>
</payment_custom_setup>
</resources>
</global>
<frontend>
<routers>
<payment>
<use>standard</use>
<args>
<module>Internship_Payment</module>
<frontName>payment</frontName>
</args>
</payment>
</routers>
</frontend>
</config>
system.xml (app/Code/Local/Internship/Payment/etc/config.xml
)
<?xml version="1.0" encoding="UTF-8"?>
<config>
<sections>
<payment>
<groups>
<payment translate="label" module="payment">
<label>My Payment Module</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>
<order_status translate="label">
<label>New order status</label>
<frontend_type>select</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>
</order_status>
<title translate="label">
<label>Title</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>0</show_in_store>
</title>
</fields>
</payment>
</groups>
</payment>
</sections>
</config>
Pay.php (Model
)
class Internship_Payment_Model_Pay extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'payment';
protected $_formBlockType = 'payment/form_pay';
protected $_infoBlockType = 'payment/info_pay';
public function assignData($data)
{
if (!($data instanceof Varien_Object)) {
$data = new Varien_Object($data);
}
$info = $this->getInfoInstance();
$info->setCheckNo($data->getCheckNo())
->setCheckDate($data->getCheckDate());
return $this;
}
public function validate()
{
parent::validate();
$info = $this->getInfoInstance();
$no = $info->getCheckNo();
$date = $info->getCheckDate();
if (empty($no) || empty($date)) {
$errorCode = 'invalid_data';
$errorMsg = $this->_getHelper()->__('Check No and Date are required fields');
}
if ($errorMsg) {
Mage::throwException($errorMsg);
}
return $this;
}
}
Pay.php (Block/Form
)
class Internship_Payment_Block_Form_Pay extends Mage_Payment_Block_Form
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('payment/form/pay.phtml');
}
}
Pay.php (Block/Info
)
class Internship_Payment_Block_Info_Pay 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')->__('Check No#') => $info->getCheckNo(),
Mage::helper('payment')->__('Check Date') => $info->getCheckDate()
));
return $transport;
}
}