You can't (always) buy friendship
The hostility of creatures is dealt with mainly on page 185 of the Player's Handbook, under "Social Interaction".
In general terms, an NPC’s attitude toward you is described as friendly, indifferent, or hostile. Friendly NPCs are predisposed to help you, and hostile ones are inclined to get in your way. It’s easier to get what you want from a friendly NPC, of course.
There are certainly times when creatures are required by the rules to act or think in a certain way (such as when they are Charmed, or under the effect of other spells). But these conditions are usually temporary (and often cause a creature to become hostile once they fade). In general, although there are many rules for defeating an enemy, there are very few on recruiting them.
There are a lot of dangerous and powerful creatures in Dungeons and Dragons. If there were rules for exactly what investment of gold or time or Ability checks would make a creature friendly to you, it could seriously imbalance the game (as suddenly, every villain could become a member of your party).
There are no rules given (in the DMG, XGtE, or PHB) on money or time requirements which will infallibly make a hostile creature friendly to you. Certainly social skills (Persuasion, Performance, Insight) could be helpful for intelligent creatures, and Animal Handling could be useful for beasts. But exactly what is required for successfully gaining a friendly attitude is up to the DM.
The closest the game comes is in doing what you're describing is in Xanathar's Guide to Everything (XGtE) on page 126 - 127 under "Carousing".
A character can carouse with the lower class for 10 gp to cover expenses, or 50 gp for the middle class. Carousing with the upper class requires 250 gp for the workweek and access to the local nobility.
...
After a workweek of carousing the character stands to make contacts
within the selected social class. The character makes a Charisma (Persuasion)
check using the Carousing table.
- 1—5 Character has made a hostile contact.
- 6—10 Character has made no new contacts.
- 11—15 Character has made an allied contact.
- 16—20 Character has made two allied contacts.
- 21+ Character has made three allied contacts.
These rules aren't intended to target particular NPCs, however. They rather give rules for making contacts of the DM's choosing. You could adapt these rules if you prefer, but keep in mind the dangers of such a system.
Dangers of Rules for Friendship
As an example, if there was a rule for exactly what resources (Ability checks, time, money, etc.) it took to make someone like you, then that rule could be applied to the player characters. The villain could keep trying to buy them dinner every night for six years, and at the end of it (if the villain rolled high enough on Persuasion) they would have to like him and agree to work together.
Creatures are not bound by rules when it comes to how they feel or who they like. If they were, every creature in your game could be forced to be a player resource, and PC decisions could be enforced by the same system.
Essentially, the DM would no longer control NPCs, and players would no longer control PCs.