If a deposit has been paid, it is seen as a proof of the performance of the contract. If the sale is concluded, this down-payment is considered as a part-payment of the price.
In the event of non-performance, the contract stipulates the procedure to be followed with regard to deposits. Under the Spanish Civil Code, in the absence of any provision in the contract relating to deposits, in case of non-performance of the contract by the buyer, the seller can keep the deposit, and in case of non-performance by the seller, the latter has to repay an amount equivalent to the double of the deposit.
It is very unusual for deposits to be paid before a notary. It is more usual for them to be paid before a real estate agent when such an agent is involved in the sale.
Are there any consumer protection measures (cooling-off period, right of withdrawal)?
There are no specific consumer protection measures relating to immovable property. However, there are measures to protect off-plan buyers who give down-payments and measures to make it mandatory to subscribe to liability insurance for construction defects.