It is legal, just no one wants to make the first move, which may lead to lost business.
These days, once places are adding inflation surcharges, adding a cc surcharge won't faze anyone.
I think it is illegal in New York
SECTION 518
Credit card surcharge prohibited
General Business (GBS) CHAPTER 20, ARTICLE 29-A
§ 518.
Credit card surcharge prohibited. No seller in any sales
transaction may impose a surcharge on a holder who elects to use a
credit card in lieu of payment by cash, check, or similar means.
Any seller who violates the provisions of this section shall be guilty
of a misdemeanor punishable by a fine not to exceed five hundred dollars
or a term of imprisonment up to one year, or both.