Magento – Save Credit Card Number for Authorize NET

It’s been a while now since I wrote my first blog,   during the time I have been working on some cool magento projects. One of my clients asked me to have the credit card number saved for all orders placed using Authorize NET, by default magento saves the credit card number only for Saved CC payment method.

Magento uses it’s built in encryption algorithm based on mcrypt php extension to save the credit card number, in order to enable saving credit card numbers we need to override a default Authorize NET Paygate model Mage_Paygate_Authorizenet.

If you are using Magento 1.4.x then setting $_canSave=true will be enough to have magento start saving credit card numbers, but in Magento 1.5.x things has changed a bit, you would also need to override _registerCard method to force and save the credit card number below is the sample code.

<config>
 
<global>
 
   <models>
 
     <mymodule>
 
        <class>Displaze_MyModule_Model</class>
 
     </mymodule>
 
     <paygate>
 
        <rewrite>
 
           <authorizenet>Displaze_MyModule_Model_Authorizenet</authorizenet>
 
        </rewrite>
 
     </paygate>
 
   </models>
 
 
</global>
 
</config>
<!--?php
/*
 * Make Authorizenet to save credit card number
 *
 */
 
class Displaze_MyModule_Model_Authorizenet extends Mage_Paygate_Model_Authorizenet
{
    /**
     * @todo uncomment the following if you want to refund the payment, or make a patial payment
     */
    //protected $_canCapturePartial       = false;
    //protected $_canRefund               = false;
    protected $_canSaveCc = true;
    protected $_canUseInternal          = true;
 
    /**
     * It sets card`s data into additional information of payment model
     * AuthorizeNet has added additional_information field in sale_flat_order_payment table
     * where they savve credit card info, and disallow to save the card in other fields,
     * This method is temprory and we need to fetch the card info from additional_information
     * field.
     * @param Mage_Paygate_Model_Authorizenet_Result $response
     * @param Mage_Sales_Model_Order_Payment $payment
     * @return Varien_Object
     */
    protected function _registerCard(Varien_Object $response, Mage_Sales_Model_Order_Payment $payment)
    {
        $cardsStorage = $this--->getCardsStorage($payment);
        $card = $cardsStorage-&gt;registerCard();
        $card
            ->setRequestedAmount($response-&gt;getRequestedAmount())
            ->setBalanceOnCard($response-&gt;getBalanceOnCard())
            ->setLastTransId($response-&gt;getTransactionId())
            ->setProcessedAmount($response-&gt;getAmount())
            ->setCcType($payment-&gt;getCcType())
            ->setCcOwner($payment-&gt;getCcOwner())
            ->setCcLast4($payment-&gt;getCcLast4())
            ->setCcExpMonth($payment-&gt;getCcExpMonth())
            ->setCcExpYear($payment-&gt;getCcExpYear())
            ->setCcSsIssue($payment-&gt;getCcSsIssue())
            ->setCcSsStartMonth($payment-&gt;getCcSsStartMonth())
            ->setCcSsStartYear($payment-&gt;getCcSsStartYear());
 
        $cardsStorage-&gt;updateCard($card);
        //below is the only reason to override this method,
        //$this-&gt;_clearAssignedData($payment);
        return $card;
    }
}
Posted in Magento | Leave a comment

How to install Redmine on Hostgator Server ?

I have been using hostgator since 2007 and found one of the leading hosting provider. When Hostgator announced to support Ruby on Rails applications, my first impression was to install Redmine, a great project management tool based on Ruby on Rails.

To configure you need 3 main gems to be installed.

  1. gem install rails -v=2.3.5 (takes quite a while!)
  2. gem install rake -v=0.8.3
  3. gem install hoe -v=1.3.0

Get the latest copy of redmine from RubyForge ,  you need to login to your ssh account in order to install Redmine, if you don’t have access just call or have a live chat with them they will enable it for you in matter of minutes.

I downloaded the latest copy from here http://rubyforge.org/frs/download.php/72201/redmine-1.0.1.tar.gz unzip the folder some where in your /home/username/redmine

Now goto your web root directory which is /home/username/public_html and create a symlink redmine to the original installation folder (/home/username/redmine/public)

We are now actually a few steps away from the completion of installation, goto

cd ~/redmine

rename dispatch.fcgi.example to dispatch.fcgi

execute this command to set the installation mode to production,

rake db:migrate RAILS_ENV="production"
It's time to configure the database goto /home/username/redmine/config and open database.yml file enter the newly created database info there .

Now login to your cpanel and create a subdomain redmine.domain.com and it shall point to your symlink /home/username/public_html/redmine

Posted in Ruby On Rails | 2 Comments

Archives

Meta