I’ve googled a bit and apparently the “surcharges forbidden by contract” have been successfully challenged in courts, at least for some states. But it’s legal to allow discounts for cash.
But I guess that card companies didn’t really care for enforcement at small stores anyway.