Show only the last 4 digits on the Magento 1 backend when editing a customer


The Subscribe Pro extension's integration with Spreedly for credit card storage is PCI level 1-compliant and secure. By default, Subscribe Pro itself only stores the first 5 and last 4 digits of customers' credit card information, as is permitted by PCI regulations. In many cases we only show the last 4 digits, but in some cases we show a more full number, with the missing digits obfuscated. For example, our default credit cards tab in the Magento backend on the customer edit screen would show "41111XXXXXXX1111" for a credit card number "4111111111111111".

However, some of our customers wish to limit the data that is displayed in this case, so that only the last four digits are shown. Below is a code example that does just that, changing the output from "41111XXXXXXX1111" to "1111". This code sample will modify and add to the Subscribe Pro SFC_Autoship extension code. For best practices, we recommend extracting these changes into a separate module so that future updates to our extension do not wipe out the change.

First, in app/code/local/SFC/Autoship/Block/Adminhtml/Customer/Paymentprofiles/Paymentprofile.php around lines 144-148 replace the block starting with $this->addColumn('creditcard_number'... with this:

$this->addColumn('creditcard_number', array(
    'header' => Mage::helper('autoship')->__('Card Number (Last 4 Digits)'),
    'index' => 'creditcard_number',
    'type' => 'text',
    'renderer' => 'autoship/adminhtml_customer_grid_renderer_creditcard_number',
));

Next, you will need to create a file called: app/code/local/SFC/Autoship/Block/Adminhtml/Customer/Grid/Renderer/Creditcard/Number.php

That file should contain the following code:

<?php
class SFC_Autoship_Block_Adminhtml_Customer_Grid_Renderer_Creditcard_Number extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        return substr($row->getData('creditcard_number'), -4);
    }
}

You can modify the output of that credit card number by changing the 'return' portion above. The filename, path and class name may vary if you are moving it into another module, but should ultimately line up with the value for 'renderer' in the first code block.

Magento 1 show only last 4 digits