If someone gives alms (Donation/charity) in form of anything. If his intention is to get merit. Then will he actually get merit out of that karma?
Yes, if your intention is getting merit then you will get it.
Manu Smriti 4.234. For whatever purpose (a man) bestows any gift, for that same purpose he receives (in his next birth) with due honour its (reward).
But you should make sure that the recipient is worthy of receiving gifts. Also, one should never boast of the act after donating something.
Manu Smriti 4.237. By falsehood a sacrifice becomes vain, by self-complacency (the reward for) austerities is lost, longevity by speaking evil of Brahmanas, and (the reward of) a gift by boasting.
Whatever one desires, is bound to be achieved at some point of time. Giving charity / alms and desiring returns for the same is one aspect of it. For any action, there is always a specific deity (good or bad). Whenever one does that fruitful action, that's considered equivalent to worshipping that deity. For example,
- Plowing the farm is equivalent to worshipping the deity of earth (Dharati)
- Planting the trees is equivalent to worshipping the deity of rains (Varuna)
- Earning the money is equivalent to worshipping the deity of money (Kubera)
- Making homa-havana for various purposes is equivalent to worshipping the deity of fire (agni)
From above limited examples, we should understand that the deities etc. are not physical beings like humans. They are merely the consciousness associated with certain aspect of nature. Because they are named as such, we often think them to be human like statures.
Now you may look at below verse from Gita. It suggests that, whichever deity you worship OR whichever action you perform with the success in mind -- is bound to succeed. The time taken depends on various aspects like perseverance, amount of desires, previous results etc.
BG 4.12 - Acting with desirous of success, those who worship the deities here in this human world, the success happens quickly from those actions.
However, these actions are termed as RAjasika and they ultimately result in sins and hence dukha (sorrow). Refer this:
What is the definition of sin according to Hinduism?
The charity done with fruitful results in mind is said to be RAjasika charity.
BG 17.21 - But the charity which is given expecting returns, or again with a desire for its results, and which is given grudgingly,- that is considered to be born of Rajas.
If someone donates with intention of getting merits (punya fal), only then he will get merits. If someone donates with no intention of getting merits then he will get no merits at all said by Lord krishna in Bhagwat Geeta.
Anyone donates to get punya fal then he will get punya fal. To get those punya fal he has to go to heaven. Entry in heaven is not free. One has to pay to get entry in heaven. But problem is, our currency don't work in heaven. In heaven only divine currency (punya fal) works. And we can earn this divine currency only when we are alive. And we can only earn if we want to earn. If we don't want to earn divine currency then we won't get any. Means getting divine currency or not, it's totally in our hand. If we want it then we will get it by doing punya karma. And if we don't want then we won't get it on our punya karma as simple as that.
Here question arises, if we don't get divine income on our punya karma then what we will get? And one word answer is.... Moksha (Libration). here is how...
If we have divine income then we will have to go for heaven And if we have sin income then we have to go for hell. But in case if we don't have neither divine income nor sin income, then where will we go? We can enter in heaven only if we have divine income, and same as hell.
So if we hasn't earn any divine income or sin income in our life time then we can't enter in heaven/hell. Forget about heaven or hell, but you can't even enter in bhooloka or mrityu loka again. yes, loka where we dies, even in that loka we can't return without any income. Because this mrityu loka is knows as karma loka. Here people can only born if they have any income to spend here. If in previous birth, you have died empty handed (without divine or sin income) then we can't even take another birth also. SO like this, your entry is forbidden in Heaven, Hell and bhooloka.
You have only one place left to go now, And that place is Vakuntha dham which is the final goal of human life. Reaching on Vakuntha dham is called moksha. If one can reach to the Sheer Sagar then he don't need to go to anywhere else. He/She stays with Narayana once at for all. He get freedom from life and birth cycle. He never gets birth again. This freedom is known as moksha.
Note: My answer is based on teachings of Bhagwat Geeta.
Some of the information contained in this post requires additional references. Please edit to add citations to reliable sources that support the assertions made here. Unsourced material may be disputed or deleted.