Just to clarify: Buying is a subset of gaining. That is, buying is one way to gain a card. There are others.
Actually buying is not a subset of gaining. Buying triggers a gain, but it is not itself a gain.
You Buy a card by paying for it. As a consequence of Buying the card, you Gain it. The two things happen in order: Buy, then Gain.
For example, if you Buy a Mint with Royal Seal in play, the following happens:
Buy Mint by paying for it.
-> When you buy Mint, trash all Treasure in play (including Royal Seal)
Gain Mint as a consequence of Buying it
-> Royal Seal can't put Mint on top of your deck, because it is not in play.