The other question is that at that time I did not know that kaffara is not required so I ate (I though my fasting is invalid so I ate). does this will make me do the kaffara or not. JazakaAllah for the response.
Praise be to Allaah.
No doubt masturbation is haraam according to most of the scholars, as Shaykh al-Islam Ibn Taymiyah (may Allaah have mercy on him) said. If this happened in Ramadaan, this is worse, and if there was ejaculation of sperm because of the masturbation, the violation of the sanctity of the fast is even more severe in sin. From the time the maniy (semen) is ejaculated, the fast is broken, but the person should still fast for the rest of that day. It is not permissible for him to stop fasting, because of the sanctity of the month. You have to repent for breaking your fast by deliberately ejaculating, and you also have to repent for not keeping the fast for the rest of the day and for violating the sanctity of the fast by doing something else that broke the fast, namely eating food. You also have to fast one day to make up for breaking your fast. Increase the number of good deeds (hasanaat) you do and observe naafil (supererogatory) fasts, for good deeds (hasanaat) cancel out bad deeds (sayi’aat). And Allaah is Forgiving and Merciful.