First make sure you are working for a reputable contractor
second do quality work
third do all the required paper work to get paid
forth talk to the contractor if there is a problem
If that fails then the most common methods of recovery are; file a lien, file in small claims court, or hire an attorney if we are talking a significant amount.