Search This Blog

Wednesday 25 July 2012

Get Payflow Edition payment response details:

Extend the Payflowpro.php model app\code\local\Mage\Paypal\Model\Payflowpro.php

Add following line of code next to $this->_debug($debugData); in protected function _postRequest(Varien_Object $request) method Approx line number : 382
    Mage::getSingleton('customer/session')->setPaymentResponseInfo($debugData); // Storing the results in a temporary session

Add the following code in Order success method in OnepageController.php

    $order = Mage::getModel('sales/order')->load($lastOrderId);
    $debugData = Mage::getSingleton('customer/session')->getPaymentResponseInfo();
    if(is_array($debugData) and count($debugData) > 0)
    {
        $write = Mage::getSingleton('core/resource')->getConnection('core_write');
        $queryString = "CREATE TABLE IF NOT EXISTS `payment_response` (`id` int(11) NOT NULL auto_increment, `order_id` varchar(50) NOT NULL, `avsaddr` varchar(50) NOT NULL, `avszip` varchar(50) NOT NULL, `cvv2match` varchar(50) NOT NULL, `response` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
        $write->query($queryString);
      
        $order = Mage::getModel('sales/order')->load($lastOrderId);
        $query = "INSERT INTO `payment_response` (`order_id`, `avsaddr`, `avszip`, `cvv2match`, `response`) VALUES ('".$lastOrderId."', '".$debugData['avsaddr']."', '".$debugData['avszip']."', '".$debugData['cvv2match']."', '".json_encode($debugData)."')";
        $write->query($query);
      
        Mage::getSingleton('customer/session')->setPaymentResponseInfo('');//Unset the session information
    }

Do point 4 by extending OnepageController.php or Create an observer for order success and store the details into table

Add the following  code to display payment response in app\design\adminhtml\default\default\template\sales\order\view\tab\info.phtml

        if($_order->getEntityId())
        {
            $write = Mage::getSingleton('core/resource')->getConnection('core_write');
            $queryString = "CREATE TABLE IF NOT EXISTS `payment_response` (`id` int(11) NOT NULL auto_increment, `order_id` varchar(50) NOT NULL, `avsaddr` varchar(50) NOT NULL, `avszip` varchar(50) NOT NULL, `cvv2match` varchar(50) NOT NULL, `response` text NOT NULL, PRIMARY KEY  (`id`)) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
            $write->query($queryString);
          
          
            $write = Mage::getSingleton('core/resource')->getConnection('core_write');
            $query = "SELECT * FROM `payment_response` WHERE `order_id`=".$_order->getEntityId();
            $value = $write->query($query);
            $results = $value->fetchAll();
            $payResponse = json_decode($results[0]['response']);
        }
     if(count($results) > 0):
        <div><strong>Payment Response Information:</strong> </div>
        <div>
            CSC Match: echo $results[0]['cvv2match']; <br/>
            AVS Zip Match: echo $results[0]['avszip']; <br/>
            AVS Street Match: echo $results[0]['avsaddr'];<br/>
        </div>
    endif;

No comments:

Post a Comment