0

I have to implement an easy payment scheme for my site. In the checkout frontend i need to display 3 payment options such as 6 months , 12 months and 24 months. Also in the payment gateway you can set only one redirect url for all 3. So without creating 3 separate payment modules i was thinking of handling it using one module as only one parameter differs (installment) from the rest of the code. Is it possible in magento? And if possible how can i achieve it?

4
  • Yes, it is possible. It can be handled in same way, as card related modules handle different cards. You can take a look at default CC payment method implementation for details of this.
    – Prateek
    Commented Jun 30, 2016 at 13:14
  • Thanks for the answer. I'll go through the CC payment method and check. Commented Jul 2, 2016 at 2:48
  • Don't forget to come back to the question if you get stuck or find the solution.
    – Prateek
    Commented Jul 6, 2016 at 8:16
  • I would always come back when i find the answer. Anyway thanks for the reminder. Commented Jul 10, 2016 at 8:17

1 Answer 1

1

Custom/Pay/Model/Custom_pay_Model_Paymodel.php

<?php
class Custom_Pay_Model_paymodel extends Mage_Payment_Model_Method_Abstract {
    protected $_code = 'pay';

    protected $_isInitializeNeeded      = true;
    protected $_canUseInternal          = true;
    protected $_canUseForMultishipping  = false;

    // define variable to add a custom form for payment method in checkout
    protected $_formBlockType = 'pay/form_pay';

    //this is the function to get the data in the custom form
    public function assignData($data)
    {
        Mage::log($data->getPayInstallment());
    }
    public function getOrderPlaceRedirectUrl() {
        return Mage::getUrl('pay/payment/redirect', array('_secure' => true));
    }       
}

Custom/pay/Block/Form/Pay.php

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

design/frontend/base/template/pay/form/pay.phtml

<ul class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
<li>
    &nbsp
</li>    
<li>     
    <input type="radio" style="margin-left: 20px;" id="paysix" name="payment[pay_installment]" value="6" checked>
    <label for="paysix" style="float:left">6 Months</label>    

    <input type="radio" style="margin-left: 10px;" id="paytwelve" name="payment[pay_installment]" value="12">
    <label for="paytwelve">12 Months</label>    
</li>
</ul>

Using the above code i showed a custom form for the payment method with 2 radio buttons. Then in the assign data function i added it to the Mage::Registry and took it from the block which i created the request form and created the form according to the selected values.

1
  • So actually you'd have to use $data->getData("pay_installment") to access the correct information. Commented Apr 23, 2019 at 15:23

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.