To have a pure heart, one must believe in God and refrain from sins. Truthfulness, prayer, and performing good deeds also contribute to the heart's purity.
And thus do We explain the verses for a people who are certain.
O you who have believed, fear Allah and speak words of appropriate justice.
Our Lord, indeed we have believed, so forgive us and have mercy upon us, and You are the best of the merciful.
Righteousness is not that you turn your faces toward the east or the west, but [true] righteousness is in one who believes in Allah, the Last Day, the Angels, the Scripture, and the Prophets, and gives his wealth, in spite of his love for it, to relatives, orphans, the needy, the traveler, those who ask [for help], and for freeing slaves.
Once upon a time, there was a man named Hassan who sought to find the light of his heart. He lived in a community where people showed kindness to one another. Hassan decided to be compassionate and do good deeds. Every day, he would share part of his earnings with the needy and play with children. Soon, Hassan's heart became bright and joyful, leading him to realize that it is through love and service to others that one can achieve a pure heart.