Payment before delivery works. Either bill hourly and stop working if they stop paying... or bill by the project with 50% down, 50% at delivery. Or whatever percentages you negotiate.
But handing over a working repo with instructions is actually a decent way to go once you are paid. Otherwise you are on the hook for actually running the thing, too, which is a completely different ballgame.