When a Contract Is Done, the Legal Definition
A contract is discharged when the parties in the contract all live up to it. When the contractor has finished work and the customer has paid the contractor, the contract has been discharged. When someone pays for a product and the product is delivered, the contract has been discharged.
Completion of the contract is called discharge by performance, when all parties have completed their respective duties as outlined by the contract.
The degree of performance may be complete, substantial or so inferior it is a breach of contract. Complete performance discharges it in all cases. Substantial completion may discharge the contract, especially when one side finished the work but the other side isn't happy with sound performance. Inferior performance according to the contract is a breach of contract.
Failure via Condition
Contracts can be conditional and rely on that condition to go forward, such as when purchase of a house is conditional on approval of financing by the buyer. Financial contracts may say that the security will be sold when the price reaches a certain point, and if that price point isn't reached within a set time period, the contract is terminated.
Conditions can be conditions precedent, conditions concurrent and precedents subsequent.
Conditions precedent are those conditions that must be met before the promise in the contract becomes binding. If the buyer doesn't get a mortgage first, they cannot enter the contract to buy the house. Conditions subsequent terminate the promise to perform outlined in the contract. Someone who enters a contract to do something and then becomes injured and unable to do so has a subsequent condition. Concurrent conditions are those that are concurrent on other things happening; these conditions can be implied or explicit. A seller who promises to sell something after delivery of it to them cannot deliver it until they have it. A contract that states "I will pay you if" is clearly conditions subsequent. Concurrent conditions also include contracts that state delivery will only be made upon payment.
The contract can be discharged by the agreement of the parties. They can discharge it by mutual agreement in writing, or they may form a new contract and discharge the old one. It is safest to end a contract by agreement in writing to avoid a he said / she said argument on the terms of its discharge later.
Agreement can take the form of novation, where a new party substitutes for one of the existing parties. Someone assuming a mortgage so the current home occupant can move out is one case, while a builder referring a new contractor to take on a job they can't complete is another. Novation requires a previously valid obligation, agreement of the old and new party to the new contract, a legally valid new contract and discharge for the prior party.
Breach of Contract
When someone doesn't deliver on time, delivers a flawed product, delivers the wrong product or fails to meet the main requirements of performance, they are in breach of contract. Minor breaches may allow someone to suspend their obligations until the breach is remedied, but major breaches often lead to lawsuits or termination of the contract.
If you pay someone to fix your appliance and they visit once to diagnose the issue and don't come back for two months, you can say they are in breach of the contract where you pay them to repair the appliance and don't have to pay for their further services. A contract where someone agrees to sell an item by a specific date is in breach of contract if the item hasn't sold by X date; while it is unlikely this leads to a lawsuit, the other party in the contract is then free to find another agent to help sell the item.
Impossibility of Performance
Impossibility of performance ends a contract when it cannot be completed. When someone dies before finishing a book, it is impossible for them to live up to the book contract calling for that title and one more in the series. Someone who promises to sell an item can't deliver it if it is destroyed in a fire. You cannot be required to deliver services or goods per a contract if interim changes in the law make it illegal. Zoning changes that make building a building per contract illegal can terminate the contract, though grandfathered properties may not be affected.
One common form of this is the line in many contracts that say they are not responsible for acts of God. You can't deliver a crop if it is destroyed by a hail storm or wildfire. Nor is this failure something the farmer could have stopped or prevented. Leases are terminated if the building is destroyed by a natural disaster.
Commercial impracticality is a legal concept where someone cannot deliver per contract because it isn't economically feasible. This doesn't refer to someone hiring another to build a product in violation of the laws of physics. It refers to someone hired to build a building for X dollars, and after all the plans are completed, it costs 2X to build. The construction contractor may say this is impossible, let me out of the contract if you don't refine the plan to something I can deliver.
A contract that says deliver this item at a certain price but prices skyrocket such that the company loses too much money on the deal is another form of impossibility of performance, though these cases often end up in court.