Subrogation takes place by operation of law alone in favour of the person who, having a legitimate interest therein, pays whenever his payment discharges from liability to the creditor the person on whom the final burden of all or part of the debt is to fall.