Can the telecommunications company stipulate in its contract that there will be a financial penalty for cancelling the contract?
Question

I work for a mobile company. Part of my work is to draw up new plans to be offered in the market. What is the ruling on the following situations?
1. The company sells a mobile line for a monthly fee; the customer pays the invoice at the end of every month for a fixed monthly fee, plus the cost of calls made by the customer. Sometimes the company stipulates in the contract that the minimum length of this contract is for one year, for example, and if the customer cancels the contract before that, the company has the right to demand payment of the penalty that is mentioned in the contract. Is this kind of penalty permissible, on the grounds that the company incurs some loss if the customer cancels the contract before one year.
2. The second situation is similar to the first, but in this case in addition to the line, the company sells a mobile phone to be paid for in installments over the year, interest-free. In this case, if the customer cancels the contract before one year, then he has to pay the penalty for cancelling the line, and also what remains of the installments for the price of the phone, without any additional amount. Is the penalty permissible in this case too?
Praise be to Allah.Firstly: 
The real nature of the annual contract that is drawn up between the customer and the telecommunications company is a rental of use contract, in which the company offers the customer the use of communication, according to the pricing of minutes that is agreed upon. In return, the customer pays the fixed fee and the costs that may change according to his use of the service. 
This is a permissible kind of contract and there is nothing wrong with it, as it fulfills the essential parts and conditions of a contract, and there is nothing ambiguous about it. 
It says in al-Ma‘aayeer ash-Shar‘iyyah: It is permissible for rental to be for a fixed or changeable sum, according to the way agreed upon by both parties."(Al-Ma‘aayeer ash-Shar‘iyyah, p. 115  no. 9, 5/2/1. 
Secondly: 
If agreement has been reached with the telecommunications company on a year-long contract, this is a binding contract and it is not permissible for either of the two parties to cancel it except with the agreement of the other party. Ibn Qudaamah (may Allah have mercy on him) said: Rental is a binding contract on both parties, and neither of them has the right to cancel it. This is the view of Maalik, ash-Shaafa‘i, and ashaab ar-ra’y. That is because it is a contract in which a benefit or service is offered in return for compensation; hence it is binding, like a sale contract, whether the individual has an excuse or not."(Al-Mughni, 5/332) 
If the contract includes a penalty in the event of cancellation, then this is a binding and valid condition. We have explained previously that such conditions are islamically acceptable, in the answers to questions no. 112090 . 
It says in  a statement issued by the Islamic Fiqh Council:
It is permissible to stipulate a penalty in all financial contracts, apart from contracts in which the basic commitment is a debt, because that is obviously riba. 
And they said: The harm for which it is permissible to receive compensation is actual financial harm and actual losses that result from cancellation, and what one misses out on of certain earnings. It does not include intangible harm such hurt feelings and damage to reputation. End quote. 
If the other party agrees to let off the party that wants to cancel the contract, that is better and is preferable, because the Prophet (blessings and peace of Allah be upon him) said: “Whoever lets a Muslim off a transaction, Allah will let him off his sins on the Day of Resurrection.” Narrated by Abu Dawood. 
However it is a good idea for the company to make allowances emergencies and unforeseen circumstances which may force customers to cancel their contracts, and not to treat those who have legitimate excuses like those who cancel for no good reason. 
Thirdly: 
There is nothing wrong with the second type of contract mentioned in the question. Compelling the customer to pay the remaining installments on the mobile phone when cancelling the contract is acceptable so long as he is not required to pay anything more than the price of the phone that was agreed upon. 
And Allah knows best.