Also, this is at least also mentioned in the Hinterlands rulebook (both 1st and 2nd ed.).
From 2nd ed. Hinterlands rulebook:
Many cards in Hinterlands do something "when you gain" or "when you buy" that card or another card.
• When you buy a card, you first buy it, then gain it. So, for example, if you have Haggler in play and buy Embassy, you first resolve Haggler's "when you buy" ability, then gain Embassy, then resolve Embassy's "when you gain" ability.
• When you gain a card without buying it, "when you gain" abilities will still happen, but "when you buy" abilities will not.
• "When you gain this" happens directly after you gain the card; the card will be in your discard pile already (or wherever else it was put) when you resolve that ability.
• When playing a card, its "when you gain/buy" abilities no longer do anything.
• You can sometimes buy a card without gaining it, such as by using Trader to gain Silver instead. You can also sometimes gain cards when it is not your turn.
• The player that "when you buy" things happen for is the player who paid for the card, and the player that "when you gain" things happen for is the player who actually gained the card. Those are normally the same person, but can be different, for example due to the Dominion: Alchemy card Possession.