Usually the contract itself specifies how that should work. You often see a schedule of payments, and how dealing with early cancelation should work.