Showing posts with label payment. Show all posts
Showing posts with label payment. Show all posts

Wednesday 27 April 2016

How to add form alt message/text on custom payment method like Paypal in magento


When you Create a Custom Payment Method Module in Magento. Add form alt message/text on custom payment method like Paypal(You will be redirected to the PayPal website).

in app/code/local/Companyname/Custompayment/Model/Custompayment.php

class Companyname_Custompayment_Model_Custompayment extends Mage_Payment_Model_Method_Abstract
{
    .
    .
    .
    .
    protected $_formBlockType = 'custompayment/standard_form';
    .
    .
    .
    .
    public function __construct($params = array())
    {
        ............
    }
}

Create new form.php and paste the following contents in that file.
app/code/local/Companyname/Custompayment/Block/Standard/Form.php

class Companyname_Custompayment_Block_Standard_Form extends Mage_Payment_Block_Form
{
    protected function _construct()
    {
        $config = Mage::getModel('custompayment/config');
        $this->setTemplate('custompayment/payment/redirect.phtml')
            ->setRedirectMessage(
                Mage::helper('custompayment')->__('You will be redirected to the Custompayment website when you place an order.')
            )
            ->setMethodTitle('')
            ->setMethodLabelAfterHtml($config->getFieldValue('title'));
        parent::_construct();
    }
}

In this file,  we've set up a template file path which will be used when Magento show our payment method related Message/info. Let's create the related template file.

Create new redirect.phtml in app/design/frontend/base/default/template/custompayment/payment/redirect.phtml

<ul class="form-list" id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
    <li class="form-alt"><?php echo $this->getRedirectMessage() ?></li>
</ul>

Tuesday 26 April 2016

Create dropdown/select box in magento system.xml for payment/shipping configuration

Create drop down in system.xml and show custom values in it, rather than using default magento classes only

Directory : app/code/local/Companyname/Modulename/config/system.xml

In system.xml

<config>
  <sections>
<payment>
  <groups>
<Modulename translate="label" module="Modulename">
<label>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>
<paymentmethod translate="label comment">
   <label>Payment method</label>
   <comment>Omni Payment method.</comment>
   <frontend_type>select</frontend_type>
   <source_model>Modulename/Modelname</source_model>
   <sort_order>30</sort_order>
   <show_in_default>1</show_in_default>
   <show_in_website>0</show_in_website>
   <show_in_store>0</show_in_store>
</paymentmethod>
</fields>
</Modulename>
            </groups>
        </payment>
    </sections>
</config>

If you want to create your custom source_Model, you need to do the following steps: Create a Pmethod.php in app/code/local/Companyname/Modulename/Model/Pmethod.php Companyname_Modulename is our module name. You need to create a function name toOptionArray() as mention below, the value and label can be anything you want to be display in dropdown

In Pmethod.php 

class Companyname_Modulename_Model_Pmethod
{
    public function toOptionArray()
    {
        return array(
            array(
                'value' => 'key1',
                'label' => 'Label 1',
            ),
            array(
                'value' => 'key2',
                'label' => 'label 2',
            )
        );
    }
}