Showing posts with label magento. Show all posts
Showing posts with label magento. Show all posts

Monday, September 10, 2012

How to create custom magento payment module - Part 4

app\design\frontend\default\default\etc\mycustom.xml


<?xml version="1.0"?>
<layout version="0.1.0">
    <default>
    </default>
    < mycustom _index_index>
        <reference name="content">
        <block type="mycustom/ mycustom " name=" mycustom " template=" mycustom / mycustom .phtml" />
        </reference>
    </ mycustom _index_index>
</layout>

app\design\frontend\default\default\template\mycustom\form\mycustom.phtml

This is options to add your custom card number and expiry date in the payment methos step while you select your custom payment method.


<?php $_code=$this->getMethodCode() ?>
<ul class="form-list" id="payment_form_<?php echo $_code ?>" style="display:none;">
    <li>
        <label for="<?php echo $_code ?>_check_no" class="required"><em>*</em><?php echo $this->__('Mycustom Card Number:') ?></label>
        <span class="input-box">
            <input type="text" title="<?php echo $this->__('Check No#') ?>" class="input-text required-entry" id="<?php echo $_code ?>_check_no" name="payment[check_no]" value="<?php echo $this->htmlEscape($this->getInfoData('check_no')) ?>" />
        </span>
    </li>
  <li>
        <label for="<?php //echo $_code ?>_check_date" class="required"><em>*</em><?php echo $this->__('Expire At (format 2012-08-01 ):') ?></label>
        <span class="input-box">
            <input type="text" title="<?php echo $this->__('Check Date:') ?>" class="input-text required-entry" id="<?php echo $_code ?>_check_date" name="payment[check_date]" value="<?php echo $this->htmlEscape($this->getInfoData('check_date')) ?>" />
        </span>
    </li>
</ul>
<div>
<?php echo $this->getMethod()->getConfigData('message');?>
</div>

Finally when you select the custom payment in the checkout page and give the custom card number, expire date and click to submit the final step it will redirect your custom payment form.And fill the details and redirect to the site to finsih the payment successfully.

Implement and give your feedback's!!!!cheers!!!

Saturday, September 08, 2012

How to create custom magento payment module - Part 3

app\code\local\Mycustomcard\Mycustom\sql\mycustom_setup\mysql4-install-0.1.0.php


$installer = $this;
/* @var $installer Mage_Customer_Model_Entity_Setup */

$installer->startSetup();
$installer->run("

ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `check_no` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `{$installer->getTable('sales/quote_payment')}` ADD `check_date` VARCHAR( 255 ) NOT NULL ;

ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `check_no` VARCHAR( 255 ) NOT NULL ;
ALTER TABLE `{$installer->getTable('sales/order_payment')}` ADD `check_date` VARCHAR( 255 ) NOT NULL ;

");
$installer->endSetup();


\app\code\core\Mage\Checkout\controllers\OnepageController.php

search this content in the file


   $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();


and replace this  code

if($_POST['payment']['method']=='mycustom')
{
$totalamount=Mage::getSingleton('checkout/cart')->getQuote()->collectTotals()->getGrandTotal();  
$round_amount=ceil($totalamount);
$cardnum=$_POST['payment']['check_no'];
$expat =$_POST['payment']['check_date'];

Mage::getSingleton('core/session')->setcardnum($cardnum);
Mage::getSingleton('core/session')->setexpdate($expat);
Mage::getSingleton('core/session')->settotamount($round_amount);

$redirectUrl = 'http://localhost.com/magento151/index.php/mycustom/index/redirect/';
}else
{
             $redirectUrl = $this->getOnepage()->getCheckout()->getRedirectUrl();
}

continues of part 4 to check the code to finish....




How to create custom magento payment module - Part 2

app\code\local\Mycustomcard\Mycustom\etc\config.xml


<?xml version="1.0"?>
<config>
    <modules>
        <Mycustomcard_Mycustom>
            <version>0.1.0</version>
        </Mycustomcard_Mycustom>
    </modules>
    <frontend>
        <routers>
            <mycustom>
                <use>standard</use>
                <args>
                    <module>Mycustomcard_Mycustom</module>
                    <frontName>mycustom</frontName>
                </args>
            </mycustom>
        </routers>
        <layout>
            <updates>
                <mycustom>
                    <file>mycustom.xml</file>
                </mycustom>
            </updates>
        </layout>
    </frontend>
    <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>
        <models>
            <mycustom>
                <class>Mycustomcard_Mycustom_Model</class>
                <resourceModel>mycustom_mysql4</resourceModel>
            </mycustom>
            <mycustom_mysql4>
                <class>Mycustomcard_Mycustom_Model_Mysql4</class>
                <entities>
                    <mycustom>
                        <table>mycustom</table>
                    </mycustom>
                </entities>
            </mycustom_mysql4>
        </models>
        <resources>
            <mycustom_setup>
                <setup>
                    <module>Mycustomcard_Mycustom</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </mycustom_setup>
            <mycustom_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </mycustom_write>
            <mycustom_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </mycustom_read>
        </resources>
        <blocks>
            <mycustom>
                <class>Mycustomcard_Mycustom_Block</class>
            </mycustom>
        </blocks>
        <helpers>
            <mycustom>
                <class>Mycustomcard_Mycustom_Helper</class>
            </mycustom>
        </helpers>
    </global>
    <default>
        <payment>
            <mycustom>
                <active>1</active>
                <model>mycustom/mycustom</model>
                <order_status>processing</order_status>
                <title>Mycustom Payment Method</title>
                <message>Please draw check in favour of Test Corporation: #XXXX-XXXX</message>
            </mycustom>
         </payment>
    </default>
</config>

app\code\local\Mycustomcard\Mycustom\etc\system.xml


<?xml version="1.0"?>
<config>
   <sections>
<!-- payment tab -->
        <payment>
            <groups>
<!-- mycustom fieldset -->
                <mycustom translate="label" module="paygate">
<!-- will have title 'New Module' -->
                    <label>Mycustom  payment</label>
<!-- position between other payment methods -->
                    <sort_order>670</sort_order>
<!-- do not show this configuration options in store scope -->
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</show_in_store>
                    <fields>
<!-- is this payment method active for the website? -->
                        <active translate="label">
<!-- label for the field -->
                            <label>Enabled</label>
<!-- input type for configuration value -->
                            <frontend_type>select</frontend_type>
<!-- model to take the option values from -->
                            <source_model>adminhtml/system_config_source_yesno</source_model>
<!-- field position -->
                            <sort_order>1</sort_order>
<!-- do not show this field in store scope -->
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </active>
                        <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>
<currency translate="label">
<label>Currency</label>
<frontend_type>text</frontend_type>
  <sort_order>4</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
</currency>

<partner_code translate="label">
                            <label>Partner Code</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>5</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </partner_code>

<partner_key translate="label">
                            <label>Partner Key</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>6</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
</partner_key>
                   
 <payee translate="label">
                            <label>Payee</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>7</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
</payee>

                    </fields>
                </mycustom>
            </groups>
        </payment>
    </sections>
</config>

app\code\local\Mycustomcard\Mycustom\Helper\Data.php


class Mycustomcard_
Mycustom
_Helper_Data extends Mage_Core_Helper_Abstract
{

}

app\code\local\Mycustomcard\Mycustom\Model\Mycustom.php


class Mycustomcard_Mycustom_Model_Mycustom extends Mage_Payment_Model_Method_Abstract
{
protected $_code = 'mycustom';
protected $_formBlockType = ' mycustom/form_ mycustom';
protected $_infoBlockType = ' mycustom/info_ mycustom  ';


//public function getOrderPlaceRedirectUrl()
// {

//when you click on place order you will be redirected on this url, if you don't want this action remove this method
// return Mage::getUrl('customcard/standard/redirect', array('_secure' => true));
// }

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)){
$errorCode = 'invalid_data';
$errorMsg = $this->_getHelper()->__('Check No and Date are required fields');
}

if($errorMsg){
Mage::throwException($errorMsg);
}


return $this;
}
}

To check part 3 code continues....



How to create custom magento payment module - Part 1

Magento custom payment is  very simple.If you have knowledge in magento its very simple to implement.
See the following steps to implement custom payment in magento.

Step 1:
Folder structure like this
app->etc->modules->Mycustomcard_Mycustom.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycustomcard_Mycustom>
            <active>true</active>
            <codePool>local</codePool>
        </Mycustomcard_Mycustom>
    </modules>
</config>





Check this path in the back end.

System->configuration->Advanced->Disable Modules Output

In this page the "Mycustomcard_Mycustom" is make as enabled.



Step 2:
Then create folders like this.


app\code\local\Mycustomcard\Mycustom
app\code\local\Mycustomcard\Mycustom\Block\Form\Mycustom.php

class Mycustomcard_Mycustom_Block_Form_Mycustom extends Mage_Payment_Block_Form
{
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('mycustom/form/mycustom.phtml');
    }
}

app\code\local\Mycustomcard\Mycustom\Block\Index\Redirect.php

class Mycustomcard_Mycustom_Block_Index_Redirect extends Mage_Core_Block_Abstract
{
    protected function _toHtml()
    {
            $session_LastRealOrderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();   
             $totalamount=Mage::getSingleton('core/session')->gettotamount();
            $cardnum = Mage::getSingleton('core/session')->getcardnum();       
             $expdate = "2100-12-31 23:59";

  $html = '<form action="http://customshop.com/index.php/mycustom/index/postvalues" id="requestpayment" name="requestpayment" method="post">
<div>
                                <input id="Code" name="Code" type="hidden" value="'.time().'" />
                            <input id="Payee" name="Payee" type="hidden" value="'.$payee.'" />
                            <input id="Description" name="Description" type="hidden" value="Pembayaran kredit rumah ke 1397" />
                            <input id="Currency" name="Currency" value="'.$currency.'" type="hidden">
                            <input id="Amount" name="Amount" type="hidden" value="'.$totalamount.'" />
                            <input id="ExpireAt" name="ExpireAt" type="hidden" value="'.$expdate.'" />
                            <input id="SendResultTo" name="SendResultTo" type="hidden" value="http://customshop.com/index.php/mycustom/index/store" />
                            <input id="RedirectTo" name="RedirectTo" type="hidden" value="http://customshop.com/index.php/mycustom/index/success" />
                            <input id="CustomCard" name="CustomCard" type="hidden" value="'.$cardnum.'" />
                            <input id="PartnerCode" name="PartnerCode" type="hidden" value="'.$partner_code.'" />
                            <input id="session_LastRealOrderId" name="session_LastRealOrderId" type="hidden" value="'.$session_LastRealOrderId.'" />   
                            <input id="signature" name="signature" type="hidden" value="" />
                            </form>';
        $html.= $this->__('You will be redirected to the custompayment website in a few seconds.');
        $html.= '<script type="text/javascript">
        document.getElementById("requestpayment").submit();</script>';
      

        return $html;
 
    }
}

app\code\local\Mycustomcard\Mycustom\Block\Info\Mycustom.php

If you select the Custom card in the checkout page "Payment informations" section.
The Card Number and Expire at values as you fill and the infos display in the right side..

class Mycustomcard_Mycustom_Block_Info_Mycustom 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')->__('Card Number') => $info->getCheckNo()
            Mage::helper('payment')->__('Expire At') => $info->getCheckDate()
        ));
        return $transport;
    }
}


\app\code\local\Mycustomcard\Mycustom\controllers\IndexController.php

class Mycustomcard_Mycustom_IndexController extends Mage_Core_Controller_Front_Action
{
  protected $_order;
   
     public function  postvaluesAction()
    {
               // code here
    }

  public function storeAction()
    {
         // code here
    }

public function cancelAction($error_mess)
        {
               if (Mage::getSingleton('checkout/session')->getLastRealOrderId())
                 {
            $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
            if($order->getId())
                        {
                                    // Flag the order as 'cancelled' and save it
                                $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, $error_mess)->save();
                        }
                 }

        }

public function redirectAction()
    {   
        $session = Mage::getSingleton('checkout/session');
        $session->setPaypalStandardQuoteId($session->getQuoteId());          $this->getResponse()->setBody($this->getLayout()->createBlock('mycustom/index_redirect')->toHtml());
        $session->unsQuoteId();
        $session->unsRedirectUrl();
      
    }
       
         public function  successAction()
    {
        $session = Mage::getSingleton('checkout/session');
        $session->setQuoteId($session->getPaypalStandardQuoteId(true));
        Mage::getSingleton('checkout/session')->getQuote()->setIsActive(false)->save();
        $this->_redirect('checkout/onepage/success', array('_secure'=>true));
    }
}

Go to part 2 for the continues....

Saturday, August 11, 2012

Module create easy in magento | custom module

Custom module is created easily in magento.
  • if we download the ModuleCreator folder and it will paste in the htdocs folder.
  • And type in the addressbar localhost/moduleCreator
Use this following links to download module creator

URLS:

http://blog.theunical.com/ecommerce/shopping-carts/magento-cart/magento-how-to-create-a-custom-plugin-module-example-tutorial/


http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table 


Magento Module Creator:

 window was opened.And you give just the values to give  the input in text box.

namespace    : Companyname
module          :  productname
rootdirectory : D:\xampp\htdocs\magento\
design           : default
design           : default

then click Create button.

Automatically custom module created in a fractional of a second.