The laptop battery for my Compaq Presario CQ40 seems to be broken because it does not charge any more when connected to the mains.
Can this be repaired or I should call it end of life and replace it?
Well I think the charging IC might have burnt out Compaq uses TPS 51125 by Texas Instruments for that I think. Also trouble shoot if your charger is ok. When the battery starts getting dead. What actually happens is the voltage decreases than the rated one and there is a surge if current than the rated value. Have you checked that out. A faulty battery usually gets charged except in some cases, however the charging discharging time is less.
So after going through all the issues, still if doesnot work you need to replace the battery. Do get it checked, I saw one or two odd cases when an IC on battery was faulty and was able to be repaired.
Laptop battery packs are made up from a number of smaller, individual cells and although it is possible to replace them, mixing old and new ones can lead to nasty charge/discharge imbalances (so it's really change all or nothing) and some of the cells are tricky to solder/desolder, plus you will have to crack open the plastic case AND disassemble the unit - and some of them are 'potted' to seal the whole assembly.
I looked into rebuilding a Lithium-Ion battery pack a year or so ago and concluded it was not worth the time, hassle and cost when reputable suppliers benefit from economies of scale.