In Ethereum, payments are normal functions with value attached. That means anything you can pass to a function you can include in a payment. It's fairly common to have some data about what was bought together with the funds to pay for it.
Simple example:
function checkOut(bytes32 itemId, uint qty) payable returns(bool success) {
// do stuff like check the math
if(items[itemId].price * qty != msg.value) throw;
// track inventory, status, etc.
return true;
}
Example assumes a struct full of item information and checks the price * qty matches the ETH sent with the transaction (msg.value
). Throw
reverts state changes and gives the money back in case that check failed (error or mischief on the front-end).
This example has a payable
function: http://solidity.readthedocs.io/en/develop/solidity-by-example.html#safe-remote-purchase
payable
is used to explicitly declare that receiving ETH is allowed, otherwise they autotmatically reject unexpected funds for security reasons. It's a relatively new feature for non-payable functions to throw
when they receive funds.
Hope it helps.