There is no money in the Federation itself. Places like DS9 however are not part of the Federation. It is easy to forget that because the Federation is in charge of daily operations of the station, but it is a Bajoran station, and they do have ultimate control.
Whenever we see monetary exchanges, it is with non-Federation species. Quark is Ferengi, and is operating a business on a Bajoran station. The Barzans were not Federation members at the time of the Barzans Wormhole episode.
While money isn't needed in daily life inside the Federation, when interacting with other species there needs to be some form of payment available to exchange for those goods and services. Starfleet clearly has some system for officers to use to pay for that stuff when operating out of places like DS9 or when vessels interact with species outside the Federation.
I think I remember an episode of Voyager where they are on a planet and "charging" purchases at a market to the ship. I'd assume those charges are totaled up and Voyager as a whole comes to some sort of trade arrangement to pay for it all instead of trying to figure it all out individually when it's not a situation where Starfleet is interacting with the species on a constant basis to have something like set exchange rates.