In my experience in the US, it is extremely rare to find transit systems (especially buses) that take credit card payments on board. For example, you cannot simply walk onto a bus holding a credit card and pay your fare. Instead (unless you pay with cash), you generally have to load some sort of fare card or app with money, or pay your fare at a ticket machine at a major station. Why do transit vehicles generally not accept credit/debit card payments on board?
Some bus agencies have done as you propose, including, at one point in the past, Valley Metro Three in Phoenix (see page 33-34 for an explanation). Those readers have since been removed. A few points:
First, fare collection equipment is expensive, and money spent outfitting buses with credit card readers is money not spent on transportation services. It's not clear that there's a business case that adding credit card readers to buses increases ridership by enough to pay for the equipment. The lifespan of fare collection systems is measured in decades, with many years required for planning, procurement, and rollout, so even if it makes perfect sense now, it may not have made sense in the 2000s, when many modern fare systems were rolled out.
As you noted, credit card fees add up if you're charging once per ride and would constitute a non-trivial proportion of typical transit fares. This is mitigated if most riders charge a larger amount at once, as with stored value cards and daily/weekly/monthly passes. Modern contactless systems use batched transactions and lower negotiated rates to reduce this expense; this was harder to do in the past. Vending machines are not really a good comparison because snacks and soda are high-margin items, while transit agencies seek to be responsible with public funds.
Until recently, most buses were offline. Smart card-based fare collection systems were designed to mitigate this: funds were loaded onto a (supposedly) secure card so that the actual transaction on the bus could be processed offline. The card readers on buses would wirelessly send/receive batch data when the buses were in the yard. While it's been done, credit card acceptance without online verification involves a high risk of fraud: anyone that can obtain a magnetic stripe that looks plausible (cancelled card, $0 balance prepaid card, fake card, etc...) can travel for free, and it won't be detected until much later, at which point the cheat is long gone. While any system has the potential for fare evasion, I can imagine transit agencies weren't that interested in one so inherently insecure. With the widespread availability of cellular modems, many buses now carry internet connections for tracking and telemetry (though those systems may be incompatible with fare collection), and fast online transactions are possible.
Consider that many taxis did not accept credit cards when many modern transit smartcards were being rolled out, and those that did had quite slow transaction processing times.
Finally, transit agencies have not always been particularly customer-centric organizations. Thinking like "we should make it as easy as possible for people to pay us money so they'll ride more and pay us more" has not always really been how many agencies operated. Many systems are built for regular daily users, especially commuters and transit-dependent riders, and those people will jump through hoops to pay their fares. That's started to change a little, with some transit agencies appointing Chief Customer Offices or similar positions and a growing awareness of the need to prioritize the needs of riders. That's led to initiatives to make transit easier to ride, including easier-to-use fare payment systems, like contactless and fare payment apps.
The modern version of what you propose is contactless payments, which are becoming increasingly common (London, New York, Singapore) along with app-based mobile payments (Berlin, San Francisco, many other cities). This offers much faster speeds than chip readers, works with smart phones and watches, and the equipment is widespread and fairly low cost at this point.
There is demand for the service (obviously).
Merchant fees are actually kind of an issue.
Speed is the big factor.
Having people do it while the bus is enroute is unsafe.
It's about dwell time, mostly
You know that a credit card transaction anywhere else can take a little bit of time. Now try it with cellular data (often flaky), and a line of people waiting to get on the bus. You get 4-5 people at a stop all pulling out credit cards, and that bus is now at the stop 2-3 minutes.
It may be holding up traffic if it doesn't have a special pad to pull over into. But the main issue is that all the passengers are being delayed while you switch cards to one that doesn't say "Declined".
You say "Well, why not do it on the road?" The answer is it's not legal to have passengers queued up in the front of the bus while moving, and the driver can't be distracted by fare-paying complications.
The merchant fees can be prohibitive for small transactions. It's well and good to pay away 3% for overhead, but when it becomes 30-40% of a senior or student fare, that really becomes hard to sell to the board.
It's also about approval time
The other factor is it is very slow to get payment systems approved and installed on buses. The speed at which the payment industry is evolving is putting transit agencies in a difficult position. It may well be that if they were making a cold start today, they could implement all sorts of innovative stuff, but there is a lengthy process to get things designed, approved, FUNDED, and rolled out. And after having done so, they want to sit with that system for awhile and not immediately turn around and do it again because of a bunch of innovations that missed their approval cycle.
The bus systems have rolled out their own electronic pass systems, and they were custom architected to satisfy transit needs, including time of processing, ability to work with no network, and fraud management. Quite often the passes are free (net of purchased value), e.g. pay $10 for the card at a drugstore and it's preloaded with $10. So it is as simple as "if you know you'll be using that system, go get one".