Reputation: 777
I am trying to get authorize.net transaction id on magento's success page. Here's the code I am using:
$orders = Mage::getModel('sales/order')->getCollection();
$order = $orders->getLastItem();
$transactionId = $order->getPayment()->getTransactionId();
As a result, $transactionId is an empty string.
Thank you
Upvotes: 0
Views: 6184
Reputation: 116
First, I wanted to say that the method you use to get a reference to the last order is not the most efficient or accurate method. It would be better to do this:
$order = Mage::getModel('sales/order')
->load(Mage::getSingleton('checkout/session')->getLastOrderId());
As of the current Magento versions (Enterprise Edition 1.13 and Community 1.8), the best way to get the transaction id (and other fields from the payment transaction and card) is from the 'authorize_cards' field stored inside the 'additional_information' field on the payment object (Mage_Sales_Model_Order_Payment or sales_flat_order_payment table).
The whole thing would look something like this (you can add this code to 'app/design/frontend/base/default/template/checkout/success.phtml'):
<?php
$order = Mage::getModel('sales/order')
->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$cardsStorage = Mage::getModel('paygate/authorizenet_cards')
->setPayment($order->getPayment());
foreach ($cardsStorage->getCards() as $card) {
$lastTransId = $card->getLastTransId();
echo '<p>' . $lastTransId . '</p>';
}
?>
Upvotes: 1