Asking the users to send tokens to your address could be a simple solution. You could also include code in your website to allow them to pay by just clicking a button. In the last case, you can use web3 on your webpage. This is an intro to how to do it:
Check if Web3 has been injected (i.e, metamask):
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}
Then create an instance to your contract:
// instantiate your contract
web3.eth.defaultAccount = web3.eth.accounts[0];
var ABI = [put here your ABI]
var contractInstance = web3.eth.contract(ABI);
var MyContract = contractInstance.at('contractaddress')
Now you can access your contract functions. For instance, you can use transfer function of the ERC20 standard to let people send tokens to the address you decide or directly to your contract (this last option implies that you have a way to transfer from your contract to your personal account).
Assume then that you have a button on the website to execute the payment, then onClick
you can call a function (i.e, payforproducts
) , I will assume for simplicity that you have a variable called amount
that indicate how many tokens the user will pay.
function payforproduct(amount){
MyContract.transfer(web3.eth.accounts[0], 'the contract Address', amount, {from: web3.eth.accounts[0]}, function(err, res){})
}
Here you need to wait for the transaction to be confirmed to be sure that the tokens are submitted to your contract (or any other address you define)
This will show metamask window in the user side asking to approve the transfer of the tokens, they will see the amount and the recipient account, so that they can check that everything is ok, that you are not charging more than expected or that the address is the correct one.
That will be all.
Hope this helps