How to display the last 4 digits of the credit card used for a Craft Commerce purchase I'd like to display the last 4 digits of the credit card used for a purchase in a front-end template. It appears the data is in the db in the craft_commerce_transactions table reference column in JSON format.

{
    "approvalCode":"PNRABL",
    "transId":"60007205645",
    "card": {
        "number":"1234",
        "expiry":"112318"
    }
}


Is there a method supported by Craft Commerce to display this data in a users account area?
I'm not sure whether you're referring to displaying this in the Control Panel somewhere or on the front-end of a site in a user account area.

Assuming it's on the front-end of a site and you've already got a reference to the order, it'd be something like:

{# Grab an order #}
{% set order = craft.commerce.orders.id(15).first() %}

{% if order %}
    {% Grab all of it's transactions %}
    {% set transactions = order.getTransactions() %}

    {# Loop through all of them looking for the one(s) you're interested in on this order.  Here, we just grab the first. #}
    {% set transaction = transactions[0] %}

    {# Output the reference #}
    {{ transaction.reference }}
{% endif %}


Keep in mind that the reference value is a response that comes back directly from the particular payment gateway, so it may or may not even be JSON, much less include the last 4 digits of a credit card number.  If it is JSON, XML, etc. then you'll need to parse that value looking for where they save the last 4 digits.