It varies from situation to situation, and there are, unfortunately, no clear 'rules'.
In the situation of your friend's buying a scarf, I (a speaker of BrE) would think of the buying as a past action, and say, "Where did you buy it?". 'Where', implying a shop, locates the action in the shop, and therefore at a past time.
On the other hand, I might say instead, "Oh, you've bought a new scarf," being more interested in the fact that she now has a new scarf (as a result of a past purchse).
Had there been a previous discussion about her intention to buy a new scarf, I then might say, on seeing her next time, either "Oh, you bought a new scarf then", or "Oh, you've bought a new scarf". In the first of these I am thinking of the past action of going out and buying that we had discussed previously; in the second I am more interested in the fact that she now has the new scarf.
The bad news is that the usage will probably never become totally clear to you. Even if you do feel confident in the usage in one of the two main dialects, AmE and BrE, you'll find that speakers of the other dialect do things slightly differently. The good news is that it does not matter a great deal. In borderline cases such as the one I noted above, either tense is perfectly acceptable.
I should add that native speakers do not think consciously about which tense they will choose. The explanations you read in grammar and course books are attempts by grammarians to explain what they hear and see; they are not absolute rules for speaking the language perfectly - though they do, of course, aserve as useful guidelines for learners.