Where the contract stipulates that the party who fails to perform it shall pay a certain sum by way of damages, no greater or lesser sum may be awarded to the other party.
However, the judge may, even of his own motion, moderate or increase the penalty so agreed if it is manifestly excessive or derisory.
Where the undertaking has been performed in part, the agreed penalty may be reduced by the judge, even of his own motion, in proportion to the interest which the partial performance has procured for the creditor, without prejudice to the application of the preceding paragraph.
Any stipulation contrary to the preceding two paragraphs is deemed unwritten.
Unless there is definitive non-performance, the penalty is incurred only when the debtor is put on notice.