How to make payable function to receive tokens and not ether?
payable modifier allows a function of a contract to receive ether.
Tokens work entirely differently to ether as they are just numbers registered against addresses in a token contract. They never leave the token contract and any transfers are entirely contained in the contract
Another contract that seeks to have payments made to it in tokens, must be aware of the token contract itself in order to interact with it. Even then a token payment to that contract is made by normal token transfer:
It's then up to the other contract to somehow be aware of that transaction. Such a contract may be written to rely on the
transferFrom() function in which the token hold calls
approve() on the token to give the contract permission to move tokens. The user then might be able to interact with that contract's token payment functions for whatever and however they've been written.
There is no way that payable function receives ethereum tokens. Ethere's fuel is ether, not token, so what you do to change status would coast ether. This article shows the difference between ether and token.
Hope it helps~