How SEEDS payments work

Upon clicking Pay with Seeds, a price is quoted in Seeds. We use newdex.io to get the current SEEDS:TLOS rate, and coingecko.com to get the TLOS:USD rate.

agent = Mechanize.new
seeds = JSON.parse(agent.get('https://newdex.io/api/symbol/getSymbolInfo', { symbol: 'token.seeds-seeds-tlos' }).body)
telos = JSON.parse(agent.get('https://api.coingecko.com/api/v3/simple/price?ids=telos&vs_currencies=usd').body)
seeds_usd = seeds['symbolInfo']['askPrice'] * telos['telos']['usd']
seeds_value = (Money.new(value * 100, currency).exchange_to('USD').dollars.to_i / seeds_usd).round

A five-character secret word is generated:

seeds_secret = Array.new(5) { [*'a'..'z', *'0'..'9'].sample }.join

We then periodically poll the caleos.io Telos API to see if a payment has been made with the right memo and amount:

agent = Mechanize.new
j = JSON.parse(agent.get("https://telos.caleos.io/v2/history/get_actions?account=#{seeds_username}").body)
j['actions'].each do |action|
next unless action['act'] && (data = action['act']['data'])
next unless data['to'] == seeds_username && data['symbol'] == 'SEEDS' && data['amount'] && !data['memo'].blank? && (seeds_secret = data['memo'].split('SGP: ').last)
‚Äč
if (@order = Order.find_by(:payment_completed.ne => true, :seeds_secret => seeds_secret, :seeds_value => data['amount']))
@order.set(payment_completed: true)
@order.send_tickets
end
end

That covers the essential steps.