You are correct, in that the stores pay a fee to the card companies. I think it’s around 3%, which is why the card companies can compete with each other with cash back offers.
Usually, that processing fee is invisible. But, sometimes the cash and credit prices are different, especially in low margin businesses like gas stations.
I once negotiated a good cash price on a car, and pulled out my credit card. No go... They wanted a check that would clear before pickup to avoid the Visa or MC processing fee. I couldn’t blame them, but thought it would be fun to see what they’d do when I offered to pay that way.
A bought a new car back in the early eighties, and didn’t have enough local credit so I had to put it on a credit card. The interest rate was 18%. Heh. So I opened up an account at a credit union and paid off the card immediately. Strange days.