In general, producers are paid an 'advance' against future 'royalties'. These days you rarely ever see the actual royalties becuase the records don't recoup.
As to what kind of advance the producer gets, it depends on the role of the producer. If you just make the beat (ie. "beatmaker") then you are going to get the least amount of money. If you are a full-on producer (ie. beat, vocals, guiding the song, logisitics, etc.) then you are going to get more money.
The biggest factor is your reputation and track record, vs. the quality of the what you contribute to the record, vs. what the client can pay and how much they want you.
Based on these factors you can get anywhere from zero to ridiculous sums. It used to be, when times were good, that the hottest producer in the land could get litterally $100k for one song. Those days are over now. My first release I got $0.00 advance for one song. I've gone as high as $10k.
It is also common at the super low level for beatmakers to give an 'all rights' buyout of a beat for a cash some. In this case, the client (artist, label, whoever) litteraly "buys" the beat and all of the rights associated, including the copyrights, and the beatmaker receives no publishing and (usually) no royalties. This is the worst idea known to mankind. To make things a little complicated, we often use the phrase "sell a beat" to mean both the all rights buyout as well as the traditional placement I first described.
I hope that answers your quesiton.