I don't quite understand the concept of payable in a function in the smart contract and the difference between payable ,view and pure.
Payable function means that you will send some ETH with the function. If you don't send any ETH with it,
transaction will fail.
View is used to return data from function. Such function will read contract
Pure is the same as
View, except you can't read
state/storage in it, but only do calculations with passed
parameters or variables created inside function.
Pure are gas free when called from outside the contract or from other
View/Pure function. If you call such function from inside normal function (which changes contract state), you will be charged however.
Payable means that the function can receive Ether via that function call. Comments in this contract explain this modifier.
View means that the function only reads from member variables contained within the contract. Explained here.
Pure states that no member variables within the contract are read from — all required data is in scope within the function itself. Explained here.