It's legal but I believe it requires collecting payment upfront to make enforcement practical. The bus company example is pretty good - you get on the bus and pay how they prefer or you don't ride.
If you ate at a restaurant which had a 'no cash' policy, I'm not sure how you would resolve a situation with a client who was willing to pay in cash only. Would the restaurant be able to refuse your cash and say you ate without paying?