Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:2:271

If you disclose your charitable expenditures, they are good; but if you conceal them and give them to the poor, it is better for you, and He will remove from you some of your misdeeds ˹thereby˺. And Allah, with what you do, is ˹fully˺ Acquainted.  

If you proclaim, make manifest, your voluntary almsgivings, that is, your supererogatory deeds, it is a fine thing, to show them; but if you conceal them, and give them to the poor, that is even better for you, than making them manifest or giving it to the rich. As regards the obligatory almsgiving, it is better to make it manifest, so that it serves as an example and so that one is not accused ˹falsely of not giving˺; as regards giving it to the poor, this is obligatory; and it will absolve you of, some of, your evil deeds (read yukaffir, ‘it will absolve’, or nukaffir, ‘We will absolve’, either in apocopated form ˹with no final vowel, yukaffir, nukaffir˺, being a supplement to the locus of fa-huwa, ‘that is’, or with nominative inflection ˹yukaffiru, nukaffiru˺, indicating the beginning of a new sentence). God is aware of what you do, knowing its inner and outer aspects, nothing of it being hidden from Him.
القرآن:٢:٢٧١

إِنْ تُبْدُوا الصَّدَقَاتِ فَنِعِمَّا هِيَ ۖ وَإِنْ تُخْفُوهَا وَتُؤْتُوهَا الْفُقَرَاءَ فَهُوَ خَيْرٌ لَكُمْ ۚ وَيُكَفِّرُ عَنْكُمْ مِنْ سَيِّئَاتِكُمْ ۗ وَاللَّهُ بِمَا تَعْمَلُونَ خَبِيرٌ  

{إن تبدوا} تظهروا {الصدقات} أي النوافل {فَنعمَّا هي} أي نعم شيئاً إبداؤها {وإن تخفوها} تسروها {وتؤتوها الفقراء فهو خير لكم} من إبدائها وإيتائها الأغنياء أما صدقة الفرض فالأفضل إظهارها ليقتدي به ولئلا يتهم، وإيتاؤها الفقراء متعين {ويكَفِّر} بالياء والنون مجزوما بالعطف على محل فهو ومرفوعا على الاستئناف {عنكم من} بعض {سيئاتكم والله بما تعملون خبير} عالم بباطنه كظاهره لا يخفى عليه شيء منه.