The rule in Germany used to be that you could buy tickets on the train, without paying a surcharge, if your departure station was unmanned. I remember travelling on some rural lines where paying on board was the norm.
These days most stations have ticket machines so I don't know if that rule still exists.