Another programmer wants to subcontract me to write, test, and document code. If anyone has nuggets of wisdom they could share regarding the business arrangement, I sure would appreciate the advice. My present plan is to go through specification and break it down into fixed-price deliverables, with the definition of "done" being passing the pre-specified test.
In all important ways, a client is a client is a client:
Treat the other programmer like your customer representative. They must be available to answer questions you have about requirements and etc. You might want to make this responsibility clear in the contract.
Do not use fixed bid. Fixed bid is a terrible plan, whether contracting or subcontracting. Walking on water and designing to spec are easy when both are frozen.
Have a lawyer help you write up a contract that specifies hourly rate, payment terms (half up front, net 15 or due on receipt, etc), scope, intellectual property ownership, and all the other important stuff, just as you would for a regular client.
Make sure their contract actually allows subcontracting. You wouldn't want to be left in the lurch because your client's client fails to pay for breach of contract.
Do not use fixed bid.
Beware of the payment terms. You may not get paid until the main contractor gets paid. If you're going to ask to be paid first, you may have to settle for less. Different places and industries vary in their practices and legal requirements. Follow @Ramhound 's advice.
What you need in cases like this is a good contract. It should specify deliverables and when you get paid, and what happens when you don't get paid. It turns out that software people in general aren't all that good at writing contracts, so make sure you have a lawyer help you. It will cost perhaps a few hundred dollars, but that's chicken feed when you risk being stiffed for thousands. (Don't forget to list it as a business expense on your taxes.)
The idea behind a contract isn't to win in court, because you never want to have to win in court. The idea is to make it clear what is to be done, so there aren't major arguments over who promised what and so that any court case will be predetermined (in which case the party that would lose will normally offer a settlement).
If you want to go fixed bid, make sure the requirements and acceptance criteria are nailed down in advance. You will get change requests, so you will need a way to deal with that. Changing things under the originally negotiated price is normally not a good way (although you can allow small changes for the sake of good will). Set the price higher than you think is warranted by the work. You're assuming the risk, after all, and you deserve to be paid for it. (If you're using fixed bid, the contract is more important, as it has to make sure you won't wind up in a position of having to do indefinite amounts of work to collect a definite amount of money.)
So, find a lawyer. Talk to the lawyer about what you want to do and how to write the contract. Let the lawyer know what you're planning to do, as a fixed-price contract will be somewhat different from an hourly rate.