Magento – Getting payment info on help

magento-1.7

Here us the whole thing that i am not able to solve it. i am trying to pass all order info, customer info and payment info through an event oberver and inserting to another db. Right now everything is working fine and i successfully insert order info,customer info. What i can not get is the payment info such as credit card info, authorization code info.

Here is my code:

On the config.xml file i have this event observer:

<sales_order_place_after>
            <observers>
                <insertorder_orderexport>
                    <class>insertorder_orderexport/observer</class>
                    <method>exportOrder</method>
                </insertorder_orderexport>
            </observers>
</sales_order_place_after>

On my function i have this observer.php i have this code:

class InsertOrder_OrderExport_Model_Observer {


public function exportOrder(Varien_Event_Observer $observer) {

    $order = $observer->getEvent()->getOrder();

    Mage::getModel('insertorder_orderexport/export')->exportOrder($order);

return true;

}

}

on my export.php i have this code:

class InsertOrder_OrderExport_Model_Export
{

public function exportOrder($order)
{

    include('classes.php');

 $getCcInfo = Mage::getModel('sales/order')->getCollection()->setPageSize(1)->setOrder('created_at')->getFirstItem();
    $order_data = $getCcInfo->getPayment()->getData('additional_information');

    if(!empty($order_data)){

    foreach($order_data as $value){

        $aPayment = new OrderPayment;
        $aPayment->CreditCardNumber    = $value['cc_last4'];
        $aPayment->AuthorisationNumber = $value['approval_code'];
    }

    }

The code continue with other classes and insertions like order and customer info but eveything is tested and works fine beside this block of code which ends up empty.

The strange thing is that when i test this code on magento root folder i get the results i want lets say when i print_r($order_data); i get this result:

Array
(

[1dccc017a3fa2a84bad51ece5cbffd20] => Array
    (
        [id] => 1dccc017a3fa2a84bad51ece5cbffd20
        [requested_amount] => 
        [balance_on_card] => 
        [last_trans_id] => 2201005063
        [processed_amount] => 6.94
        [cc_type] => VI
        [cc_owner] => 
        [cc_last4] => 1111
        [cc_exp_month] => 4
        [cc_exp_year] => 2018
        [cc_ss_issue] => 
        [cc_ss_start_month] => 
        [cc_ss_start_year] => 
        [approval_code] => 8Z0LNX
    )
)

So it means that $order_data is full with values but i don't understand why it ends up empty after.

Also i have tried other events like:

checkout_onepage_controller_success_action

checkout_submit_all_after

Still no results. And i don't have any error in my log file.

Please professional users help me, Thank you

Best Answer

I think you simply need to remove the foreach loop.

foreach($order_data as $value){
    // $value is now $order_data['id'] or some such
    // and when you call $value['cc_last4']
    // you're mistakenly looking in $order_data['id']['cc_last4']
}

Just use this instead:

if(!empty($order_data)){
    $aPayment = new OrderPayment;
    $aPayment->CreditCardNumber    = $value['cc_last4'];
    $aPayment->AuthorisationNumber = $value['approval_code'];
}
Related Topic