This was outlawed here in Australia a few years ago, so merchants are now free to charge a fee for credit card purchases (which some would call offering a discount for cash).
The main reason for doing this was to make the costs of buying by credit card transparent. Under the old system, credit card providers charged a fee to the merchant, but the fee was hidden from the consumer. The merchants had to absorb this cost by raising prices slightly across the board. That meant that the banks were effectively applying a small sales tax to nearly all retail sales. Estimates varied, but it was generally thought to be around 1% to 2%. It doesn't sound like much, but across every sale in the country, it's a huge amount.
Most big retailers continue to do this, but smaller retailers either have a mimimum amount for credit card purchases, or tack on a fee of around 3%.