From the words of our Sages it is clear that it is permitted to say, “This coin is for tzedakah so that my son will live,” or “so that I will have a portion in the World to Come,” and the person is considered a completely righteous individual as a result. The same applies to all similar situations when a person has in mind to receive some benefit from doing a mitzvah, and there is no blemish in doing so. This is because main thing is that he fuflilled the commandment of Hashem. And even though he had in mind that he will gain from it in some way, he does not lose his reward from the mitzvah. The same applies to doing a chessed-kindness with his fellow or lends him money, while having in mind that he will gain for himself as well, such as that in its merit his wealth will increase or that his children will be successful etc. — it is a complete mitzvah.
Nevertheless, it is better if he has in mind to do it purely for the sake of Heaven; that is, that he wishes to do the mitzvah because that is what Hashem commanded him in the Torah. In this manner, the holiness of the mitzvah is greater, for it is done in its most exalted manner and it greatly arouses the Attribute of Chessed up Above, which then extends to all of Creation.