Then I write the contract, usually separated in phases. Each phase has its own schedule.
For "short" contracts (like one or two months), I send an invoice after the first phase, with about 50% of the value. Then 50% after the work ends.
For longer contracts (6 months+), I divide the total cost between the months. So if a project is 10k for 5 months, I send an 2k invoice each month. Depending on the customer, if they don't pay in at least 5 business days after the invoice is sent, I stop working.
After the contract ends, I usually provide 30 days of email/chat support to answer questions (and not hands-on work).
This is working very fine for me, but sometimes things could go wrong, so having a good lawyer ready is great as others said in this thread.
Good luck!