Your rights:
Regardless of your nationality and regardless of your place of residence, you should be able to buy tickets at the same price as the railway companies usually charge customers coming from their own country. (Social tariffs are excluded.)
Our advice:
Compare prices on different websites. Especially, if you want to travel abroad. If you book at an intermediary (e. g. booking portals), they may charge service fees for their activity.