1

Today I am trying to create a custom payment method. Which requires user to fill in 2 fields and they all shows in the One-page Checkout Process. However, when I finished them and continue to the next step. The Info Block on the right side showed only the method title.

Please help.. Thank you a lot!

Below are my files:

Model:

<?php 
class Tai_Smartpay_Model_Smartpay extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'tai_smartpay';
protected $_formBlockType = 'tai_smartpay/form_smartpay';
protected $_infoBlockType = 'tai_smartpay/info_smartpay';

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 getOrderPlaceRedirectUrl()
{
    return Mage::getUrl('tai_smartpay/payment/redirect', array('_secure' => false));
}

Block Form:

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

Info Block:

?php
class Tai_Smartpay_Block_Info_Smartpay 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);

    Zend_Debug::dump($this->getInfo()->getCustomFieldOne());

    return $transport->setData(array_merge($data, $transport->getData()));
}
}

and Template:

<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>
0

I've found it, the code is correct. It's because of my cache. When I restart my computer. It works. However, I still don't know what kind of cache caused this problem, because I have disabled all the cache inside the Admin Config :/

Your Answer

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

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