The Gemara in Masechet Berachot cites the verse in Tehillim (17:15), "Va’ani Be’sedek Ehezeh Panecha" ("I shall behold Your countenance with righteousness"), and explains it to mean that when we come before G-d in prayer, we must first give charity. The Arizal (Rav Yishak Luria of Safed, 1534-1572) taught (in Sha’ar Ha’kavanot) that during the Shaharit service, as one recites the words, "Ve’ata Moshel Ba’kol" in the section of "Va’yebarech David," he should give three coins to charity. One should first place two coins in the charity box, and then a third coin. This practice is rooted in Kabbalistic teachings.
Rav Haim Vital (1543-1620), the Arizal’s primary disciple, testified that the Arizal would give three coins to charity in this fashion also before Minha. Before Arbit, however, this practice should not be followed. Since Arbit marks a period of "Dinim" ("judgments"), it is not a time for charity. It goes without saying that if a person is approached by a collector, he should generously donate, at any time of day or night. However, the practice to specifically donate coins to charity before prayer applies before Shaharit and before Minha, but not before Arbit.
It sometimes happens in some communities that several, or even numerous, collectors come to the synagogue and approach congregants while they pray, which can be very disruptive and undermine one’s concentration. The question arises as to whether one must nevertheless give to the collectors, despite the disruption they cause, in light of the ruling of the Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204) that one who is approached by a needy individual and refuses to give violates the Torah prohibition of "Lo Tikpotz Et Yadecha" ("Do not shut your hand closed" – Devarim 15:7). Seemingly, one would be required to give to everyone who approaches him, even during the Tefila. In truth, however, this is not the case. The Halachic authorities clarified that this prohibition is violated only if a pauper approaches with an immediate need – such as if he is hungry and has no food, and he approaches a person to ask for food or for money with which to purchase food. If one refuses this desperate plea, he transgresses the Torah prohibition of "Lo Tikpotz." However, the collectors who approach congregants in the synagogue nowadays are collecting for long-term needs, and, as such, the prohibition of "Lo Tikpotz" does not apply. Of course, in general, one should generously assist those in need to the best of his ability. But if collectors are disrupting his prayer, he is not required to give them money while he prays. This is the ruling of Rav Rahamim Shayo (contemporary), in his work Mehkereh Aretz.
It should be mentioned that when reciting the Shema, and of course while reciting the Amida, it is strictly forbidden to give charity. Halacha forbids even signaling or motioning to somebody during these sections of the prayer service, and so one certainly should not give charity while reciting Shema or the Amida.
The concept underlying the connection between charity and prayer, as the Arizal explained, is that the Shechina (divine presence) is with us even in our state of exile, but it is "weak" because of the absence of the Bet Ha’mikdash. By giving charity to strengthen a poor, downtrodden pauper, we also "strengthen" the Shechina.
Summary: It is a proper custom to give three coins to charity while reciting the words "Ve’ata Moshel Ba’kol" in "Va’yebarech David" during Shaharit, and also before Minha. If one is approached by collectors during the prayer service, and thus disrupts his Kavana (concentration), he is not required to give them money, and while reciting Shema or the Amida, it is forbidden to interrupt to give charity. Needless to say, at all other times one should donate generously to those in need of financial assistance, to the best of his ability.