1

I am making a custom payment gateway and I have it in the capture payment in Magento when a payment has been through:

$payment->setTransactionAdditionalInfo                     
           (Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,array
('TransactionGUId'=>$result['transaction_guid'], 'TransactionId'=>$result
['transaction_id'],'Messages'=>$result['messages'])); 

Which writes the payment transaction additional information. I need to get in the refund these additional informations to send them to the payment Gateway. I tried:

 $collection = Mage::getModel('sales/order_payment_transaction')->getCollection()
 ->addAttributeToFilter('order_id', array('eq' => $payment->getOrder()->getEntityId()))
 ->addAttributeToFilter('txn_type', array('eq' => 'capture'))
        ->addPaymentIdFilter($payment->getId());


       $transaction = $collection->getAdditionalInformation('transactionId');
        $transactionGUId = $collection->getAdditionalInformation('transactionGUId');

but it returns an error.

1

You need to get the individual object from the collection

Try

 $collection = Mage::getModel('sales/order_payment_transaction')
                  ->getCollection()
                  ->addAttributeToFilter('order_id',  
                      array('eq' => $payment->getOrder()->getEntityId()))
                  ->addAttributeToFilter('txn_type', array('eq' => 'capture'))
                  ->addPaymentIdFilter($payment->getId());


 foreach($collection as $transaction){
       print_r($transaction->getAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS));
 }

Update - your key is Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS

In order to get the individual value try

$rawValue = $transaction->getAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAIL)
if(is_array($rawValue) && array_key_exist(...)){
    $transactionGUId = $rawValue['TransactionGUId']; 
    ...
}

Take a look at /app/code/core/Mage/Sales/Model/Order/Payment/Transaction.php,

 /**
 * Additional information setter
 * Updates data inside the 'additional_information' array
 * Doesn't allow to set arrays
 *
 * @param string $key
 * @param mixed $value
 * @return Mage_Sales_Model_Order_Payment_Transaction
 * @throws Mage_Core_Exception
 */
public function setAdditionalInformation($key, $value)
{
    if (is_object($value)) {
        Mage::throwException(Mage::helper('sales')->__('Payment transactions disallow storing objects.'));
    }
    $info = $this->_getData('additional_information');
    if (!$info) {
        $info = array();
    }
    $info[$key] = $value;
    return $this->setData('additional_information', $info);
}

/**
 * Getter for entire additional_information value or one of its element by key
 * @param string $key
 * @return array|null|mixed
 */
public function getAdditionalInformation($key = null)
{
    $info = $this->_getData('additional_information');
    if (!$info) {
        $info = array();
    }
    if ($key) {
        return (isset($info[$key]) ? $info[$key] : null);
    }
    return $info;
}
  • but i need to get separately two data when i write foreach i don't get them separately how can i get $transactionID = ...and $transactionGUID =... these are two keys with values in the transaction additional information i need to get these two values to send them in a xml file – user1619177 Aug 20 '15 at 18:11
  • What is the output of print_r($transaction->getAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS); – Renon Stewart Aug 20 '15 at 19:34
  • I don't know how can i find out i have a problem i only see the answer of the request i can't see the request itself my code is as follows: – user1619177 Aug 20 '15 at 19:46
  • Take a look at my update... try Mage::log($transaction->getAdditionalInformation(Mage_Sales_Model_Order_Payment_T‌​ransaction::RAW_DETAILS)) – Renon Stewart Aug 20 '15 at 19:49
  • great thank you! the following worked foreach($collection as $transaction){ $rawValue = $transaction->getAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS); if(is_array($rawValue)){ $transactionGuid = $rawValue['TransactionGUId']; } } – user1619177 Aug 20 '15 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.