First off the contract needs to be explicit as to exactly the work you are doing and how you are going to be paid.
Second, you have two options with regards to payment: fixed price or hourly. Personally I find fixed price to be easier on everyone; however, if you are unsure as to how long something is really going to take or it has a lot of unknowns then hourly is a better way to go.
For fixed price I ask for between 25% and 50% up front. It depends on the size of the contract (smaller deals = more upfront), amount of my own money I'll have to expend (servers, tools such as compilers, etc) and the amount of risk I think there is for non-payment.
If it's a small project then it is balance billed at the end along with customer acceptance. Once paid I deliver the source NOT before then. If it's a larger project then there are deliverables along the way in which they release a certain percentage of the funds with the balance done at the end.
For hourly, I'm usually on site. This may not be an option for you. However, be prepared that they may argue the actual number of hours you worked off site when you bill them. Regardless, you need to have established, in the contract, how often you bill and how often you get paid. Some companies like NET 30.. meaning you send a bill and they pay you 30 days later. This may or may not be acceptable and is certainly negotiable.
Each task should have a time estimate involved. If for some reason you believe the task will take longer, discuss it with them immediately. Preferably BEFORE you get to the point of spending 8 hours on a 1 hour item. The key here is that you do not want to surprise them. Each task should have time for coding, testing, discussing and deploying that piece of code. Sometimes this means a 30 minute thing will have 4 hours assigned to it. In the event you are able to complete the task in less time allowed be sure they know of it and bill for the smaller time.
Now, onto the work you want to do versus that you don't. This needs to be clear. From a fixed price perspective the contract must clearly define the exact scope of project. Any deviation should be handled through change requests along with the cost of the change, again requiring management signature.
With hourly, you can be a little more vague but be prepared to be asked to do things outside of scope. Bearing in mind that if you decline to do the additional work they may decline to continuing using your services.
With expected payments there should be a bit about what happens if they are late paying you. You need to think about this situation. Is work going to come to a complete stop? How does it escalate? Are late fees attached after a certain time period? Do you offer a discount if paid earlier or on time? As a contractor, this is a tough situation however it is a little easier if it is thought through and spelled out before hand.
There are very few situations in a fixed price bid that I would consider deploying code without payment. I've had even long term customers screw me over by renegotiating after the fact. Regardless, you should NEVER consider putting time bombs or engaging in any practice that might disrupt their business in the event of non-payment. That could land you in a world of legal hurt. There are legal means of getting the customer to pay you and those are the only ones to consider.
Finally, communication is an absolute must. Build this time into any proposal you have. Don't go a week without talking to them. People want to know what's going on, even if it's just an email or phone call saying X, Y and Z tasks complete, working on A and B now.