Depends on the jurisdiction I guess ? I just checked, and around here cash is the only type of payment that cannot be refused, and if they get caught trying they would be fined 150€.
A debt must be incurred for them to refuse it. If one walks up to a counter to pay for something, there is no debt and a business can refuse to take the cash.