Sometimes 4F is returned with an empty value. How do I provide the AID on the receipt if 4F is not provided or is empty?

Answer:

The Application Identifier (ADF Name) tag 4F comes from the card.  The terminal (card reader)  will only pass this TLV from the card. It will never create it or change it. If the card doesn't have a value for this tag, the reader will just output an empty TLV (4F00).

When the reader reads the record of the Payment System Directory from the card, if the value of the 4F tag is returned by the card,  the reader will save it to the 4F and 84 tags (so the values of 4F and 84 are the same) and then copy the value to the 9F06 tag.

If the Payment System Directory is not supported by the card, then the AID will be returned in Dedicated File (DF) Name tag 84 and the value will also be copied to the 9F06 tag. So if the returned value of the 4F tag is empty, you can use the value in the 84 or the 9F06 tag.

Because of this, the best practice is to use tag 84 or 9F06 for printing the AID on the receipt, not the 4F tag