That used to be typical in the US as well. I think that when pay-at-the-pump became the norm (using a card), prepayment became expected even when paying with cash inside, at around the same time. I expect there are some gas stations here and there in the US that still operate the way you describe though.
An increasing number of gas stations are completely unattended though — the attached store might close overnight but the pumps are still usable.