Home » Php » php – Credit card detail in Magento

php – Credit card detail in Magento

Posted by: admin July 12, 2020 Leave a comment


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.


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

Exp Info:


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

$lastOrderId = Mage::getSingleton('checkout/session')

foreach($payarry as $key => $cardinfo)
    echo $key;
    echo $cardinfo;                     



        $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…



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

            foreach($payarry as $key => $cardinfo)
                 echo"<pre>"; print_r($payarry);

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