It was VISA et al's way of taxing people purchasing with cash. They had contract terms that wouldn't let you sell at a discount when the customer paid in cash; under Obama the federal government finally banned them, and several states had already done so, but I think usually only for gas purchases.
I think the contracts (or consumer inertia) still make stores advertise at the credit-card price, and the different price for cash has to be advertised as a discount.