It depends, you can either be paid in lump sum (with no royalties) or royalties (usually perpetual or a specific lenght of time depending on the contract but lower upfront payment).
Writers who think their piece will become a hit often go for royalties since their income will dramatically expand when the book hits the charts.
New writers who aren't that confident often go for lump sum.