Merchants absolutely can pass on the fees or give "discounts" for cash, at least in the USA. Gas stations are one of the major businesses that practice this.
Anecdotally, I worked at a company store years ago where we would charge customers paying with cards a 2.75% fee, which is what we were paying. And that store was operated by a Fortune 500 company.
Also, virtually every small private business I go to in Los Angeles charges some fee, or has stipulations, for credit card transactions.
This wasn't originally the case. Passing on the fee was for a long time against most merchant agreements. Which makes sense from the credit card company's point of view: they don't want shoppers to have any reason not to whip out the card.
Maybe I should've mentioned "Los Angeles" higher in my comment, but looking at the sibling comment to yours, apparently there are plenty other states where it is legal to pass on the fees as a surcharge as well. Obviously your situation may vary.
Anecdotally, I worked at a company store years ago where we would charge customers paying with cards a 2.75% fee, which is what we were paying. And that store was operated by a Fortune 500 company.
Also, virtually every small private business I go to in Los Angeles charges some fee, or has stipulations, for credit card transactions.