0

I am using the Authorize Direct Post Payment Method with EE 1.13. I need to export credit card payment details including cc_type and cc_last4. In sales_flat_order_payment cc_type is null and cc_last4 appears to be encrypted.

A few orders include cc_type and the unencrypted cc_last4 in the additional_information field which looks like this:

a:1:{s:15:"authorize_cards";a:1:{s:32:"61cb8d50438f041ab581a381cd81f8e8";a:13:{s:2:"id";s:32:"61cb8d50438f041ab581a381cd81f8e8";s:16:"requested_amount";s:0:"";s:15:"balance_on_card";s:0:"";s:13:"last_trans_id";s:10:"2195591072";s:16:"processed_amount";s:5:"18.95";s:7:"cc_type";s:2:"VI";s:8:"cc_owner";N;s:8:"cc_last4";s:4:"1111";s:12:"cc_exp_month";s:1:"1";s:11:"cc_exp_year";s:4:"2015";s:11:"cc_ss_issue";N;s:17:"cc_ss_start_month";N;s:16:"cc_ss_start_year";N;}}}

But most payments additional_information field just looks like

a:1:{s:12:"payment_type";s:9:"authorize";}

Why do some payments include cc_type and cc_last4 in additional_information and some do not?

How do I reliably capture cc_type and cc_last4 prior to payment capture with auth.net Direct Post?

2 Answers 2

3

The field is serialized within additional_data with an md5(microtime(1)) as the key.

The short answer here is going to be loading the model, unserializing, and exporting to CSV:

$order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);
$payment = $order->getPayment();

Once you have the payment object you can coax the cc_last4 and the cc_type out of it (it's an array):

$addlinfo = $payment->getAdditionalInformation();
$addlinfo = array_shift($addlinfo['authorize_cards'])); // get only the relevant values from the array
$filepath = Mage::getBaseDir('var') . DS . 'export' . DS . 'cclast4export.csv';

$csvWriter = new Varien_File_Csv();
$csvWriter->saveData($filepath,$addlinfo);

In my tests you shouldn't have to decrypt. However, if you do, just use $payment->decrypt($field) where $field contains the encrypted information.

The above sample code will write a CSV in var/export/cclast4export.csv with ALL of the options. I'll leave it to you (as homework) to pare this down to just the two fields you're requesting.

Hope that helps!

8
  • cc_type is null for all payments and most payments do not have authrorize_cards in additional_information, so I don't think this solution is going to work. The issue here is making sure that this data is stored.
    – Howie Ross
    Commented Aug 22, 2013 at 17:06
  • So part of me hopes I'm wrong, but this line github.com/LokeyCoding/magento-mirror/blob/magento-1.7/app/code/… makes me think that you've only authorized those orders and have not captured. In that case you would want to capture the payment...
    – philwinkle
    Commented Aug 22, 2013 at 17:12
  • That is correct, that I have only authed these payments. I will be capturing them once I receive notification that they have shipped.
    – Howie Ross
    Commented Aug 22, 2013 at 20:08
  • Check back at that time. Authed payments won't have any additional information in the payments table until the funds have been captured.
    – philwinkle
    Commented Aug 22, 2013 at 20:16
  • Thanks for the info, but I need to export cc_type before the capture has occurred.
    – Howie Ross
    Commented Aug 23, 2013 at 13:13
0

Add to Mage_Authorizenet_Model_Directpost _fillPaymentByResponse()

->setCcType($response->getXCardType());

so that

$payment->setCcAvsStatus($response->getXAvsCode()) ->setCcLast4($payment->encrypt(substr($response->getXAccountNumber(), -4)));

becomes

$payment->setCcAvsStatus($response->getXAvsCode()) ->setCcLast4($payment->encrypt(substr($response->getXAccountNumber(), -4))) ->setCcType($response->getXCardType());

You'll want to do this in a copy of DirectPost.php in app/code/local/Mage/Authorizenet/Model/Directpost.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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