You have more purchase options than ever these days. The usual channels are station ticket machines, staffed ticket counters, the operator's official mobile app, convenience stores in much of Asia, and licensed kiosks or tobacco shops in parts of Europe. Hotels sometimes sell tourist passes at the front desk, but they occasionally add a markup, so treat that as a convenience option.
Payment is rarely a problem in developed systems, since machines take international cards and many networks now let you tap a contactless Visa or Mastercard directly as your ticket, no pass needed. That said, some countries still have machines that prefer local cards, exact cash, or chip-and-PIN, and a few apps require a local phone number or app store region to register. That is when the staffed counter or a convenience store becomes your friend.
My general routine in a new city: try the official app first while still at the airport on wifi, and if it fights you, buy a physical card at the station machine with a credit card. Keep a little local cash as backup for older machines.