Home » Php » php – Credit card detail in Magento

php – Credit card detail in Magento

Posted by: admin July 12, 2020 Leave a comment

Questions:

How can I get the credit card detail in Magento from OnepageController.php?
I have retrieved all the other information like billing information, shipping information and user details. I am using the following to get the card detail but it returns blank:

$lastQuoteId = $session->getLastQuoteId();
$lastOrderId = $session->getLastOrderId();
$order  = Mage::getModel('sales/order')->load($lastOrderId);
$card_exp_month     = $order->getCcExpMonth($lastOrderId);///(Nahi AAya)
$card_exp_year      = $order->getCcExpYear($lastOrderId);///(Nahi AAya)

When I print $card_exp_month and $card_exp_year, both are blank. Is there another way by which I can determine the credit card detail? I’m looking for CC number, expiry year and expiry month.

How to&Answers:

Instead of $order->getCcExpMonth($lastOrderId) try $order->getPayment()->getCcExpMonth($lastOrderId).

Use print_r($order->getPayment()->debug()) to see what other values are available, or view the sales_flat_order_payment table to see some more examples.

Answer:

CC Last 4: $order->getPayment()->getCcLast4()

Exp Info:
$order->getPayment()->getCcExpMonth()
$order->getPayment()->getCcExpYear()

Answer:

I got the card details in phtml file like following way.

$lastOrderId = Mage::getSingleton('checkout/session')
                                        ->getLastRealOrderId();

$order=Mage::getModel('sales/order')->loadByIncrementID($lastOrderId);
$payarry=$order->getPayment()->debug();
foreach($payarry as $key => $cardinfo)
{                   
    echo $key;
    echo $cardinfo;                     
}

Answer:

Also

        $quote = Mage::getSingleton('checkout/session')->getQuote();  // or load by id
        $order = $quote->getOrder();
        $payment = $quote->getPayment();
        $instance = $payment->getMethodInstance();

        $ccNumber = $instance->getInfoInstance()->getCcNumber();
        $ccExpMonth = $instance->getInfoInstance()->getCcExpMonth();

and so on for CcCid, CcOwner, etc…

Answer:

            <?php

            require_once("app/Mage.php");
            $app = Mage::app('');
            $salesModel=Mage::getModel("sales/order");
            $salesCollection = $salesModel->getCollection();
            foreach($salesCollection as $order)
            {
                $orderId= $order->getIncrementId(); echo "<br/>";
                echo $orderId;

            $payarry=$order->getPayment()->debug();
            foreach($payarry as $key => $cardinfo)
            {     
                 echo"<pre>"; print_r($payarry);

                //echo $key; echo "<br/>";
                //echo $cardinfo;       echo "<br/>";               
            }

            }


            ?>