In any action brought for the recovery of the purchase money against any person holding a contract for the purchase of lands, the party bound to perform the contract, if not the plaintiff, may be made a party, and the court in a final judgment may order the interest of purchaser to be sold or transferred to the plaintiff upon such terms as may be just, and may also order a specific performance of the contract in favor of the complainant, or the purchaser, in case a sale be ordered.