how to get payment information on Magento?

76,076

Solution 1

I think it will be

   $payment = $order->getPayment();

It will retrieve the current order payment instance.

Solution 2

//Get Payment
$payment = $order->getPayment()

//Get card type
$payment->getData('cc_type')

//Get Payment Info
$payment->getMethodInstance()->getCode();
$payment->getMethodInstance()->getTitle();

//Get Credit Card info
$payment->getMethodInstance()->getCardsStorage()
$payment->getMethodInstance()->getCardsStorage()->getCards() //array()

Solution 3

To get the method code only it's far safer to use

$order->getPayment()->getMethod();

Skipping instance object which can generate exception if the payment method was uninstalled.

Share:
76,076
Jonathan
Author by

Jonathan

Imagination

Updated on August 13, 2020

Comments

  • Jonathan
    Jonathan almost 4 years

    I have to export the orders to a file, here is my code to go through the orders:

        $orders = Mage::getModel('sales/order')->getCollection()
        ->addAttributeToSelect(array('status', 'ncm'))
        ->addFieldToFilter(
            array(
                array('attribute' => 'status', 'eq' => 'complete')
            )
        );
    
        $order = $orders->getFirstItem();
    
        //print_r($order);
        //exit;
        //foreach($orders as $order){
        $id = $order->getIncrementId();
    
        $payment = $order->getPayment();
        $method = $payment->getMethodInstance();
    
        print_r($payment);
        //}
    

    I need to print some information about the payment like the method, the amount, how many months it was split, if was credit card, i need the reutrning id of the transaction and so the list goes on

    how can I do that?

  • Jonathan
    Jonathan over 13 years
    I am already using that code, but I can't seem on how to retrieve those specific info. Would help me figure it out?
  • Max Pronko
    Max Pronko over 13 years
    Sorry, didn't saw that code. Please, try $order->getPayment()->getAdditionalInformation(); - this is payment + transaction info
  • Max Pronko
    Max Pronko over 13 years
    $order->getPayment()->getMethodInstance()->getPaymentInfo();
  • Stefan Brendle
    Stefan Brendle over 10 years
    For some payment modules $order->getPayment->getMethodInstance()->getData() doesn't work. If you need to know the custom methods, try var_dump(get_class_methods(get_class($order->getPayment()->g‌​etMethodInstance()))‌​) to get a list with all possible methods. In my case they're called getAccountBankname or getAccountBLZ ... it's a bit tricky, but I hope this helps :)
  • user3338098
    user3338098 over 8 years
    $cards = ...->getCards(); $card=$cards['transaction_id']; echo $card->getCcType(); echo $card->getCcLast4();
  • user3338098
    user3338098 over 8 years
    the card information matches the information available in the additional_information column of the sales_flat_order_payment table
  • Harkály Gergő
    Harkály Gergő over 7 years
    Is there a way to get the ID (number) of method too?