Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Payment system
- local unicode = require('unicode')
- local event = require("event")
- local component = require('component')
- local serialization = require("serialization")
- local tunnel = require('component').tunnel
- local shell = require('shell')
- local object = require('object')
- local gpu = component.gpu
- local args = shell.parse(...)
- if args[1] ~= 'table' and args[1] == 'string' then
- args = serialization.unserialize(args[1])
- else
- args = args[1]
- end
- local rX,rY = gpu.getResolution()
- local settings = {}
- local w = rX/11*5
- local h = rY/13*9
- object.init()
- local function getEvent(...)
- local args = {...}
- evnt = nil
- if type(args[1]) == 'number' then
- time = args[1]
- end
- evtrue = true
- local function getRawEvent()
- return {event.pull()}
- end
- while evtrue do
- -- s , evnt = pcall(getRawEvent)
- evnt = {event.pull(time)}
- -- if s ~= false then
- for i=1,#args do
- if evnt[1] == args[i] and time == nil then
- evtrue = false
- break
- elseif time ~= nil then
- evtrue = false
- break
- end
- end
- --end
- end
- return evnt
- end
- function payment(arr)
- local request = {
- operation = 'transfer',
- user = arr.buyer,
- key = arr.key,
- target = arr.seller,
- amount = arr.amount,
- description = arr.comment,
- answearKey = arr.answearKey
- }
- tunnel.send(serialization.serialize(request))
- result = {}
- while true do
- local e = {event.pull('modem_message')}
- local answear = serialization.unserialize(e[6])
- if answear.operation == 'transactionResult' and answear.status == true then
- result.status = true
- result.data = answear
- break
- elseif answear.operation == 'transactionResult' and answear.status == false and answear.error == 'timeout' then
- result.status = false
- result.data = answear
- break
- elseif answear.operation == 'transactionResult' and answear.status == false and answear.error == 'deny_command' then
- result.status = false
- result.data = answear
- break
- end
- if answear.operation == 'transfer' and answear.status == true then
- -- print('Payment register!')
- elseif answear.operation == 'transfer' and answear.status == false and answear.status == 'Not enough money' then
- result.status = false
- data = answear
- break
- end
- end
- return result
- end
- function drawLMenu()
- object.square(math.floor((rX-w)/2),math.ceil((rY-h)/2),w,h,' ',0xffffff,0x898989)
- object.frame(math.floor((rX-w)/2)+2,math.ceil((rY-h)/2)+1,w-4,h-5,1)
- end
- function drawMain(arr)
- gpu.setBackground(0x898989)
- drawLMenu()
- object.square(math.floor((rX-w)/2),math.ceil((rY-h)/2),w,h,' ',0xffffff,0x898989)
- object.frame(math.floor((rX-w)/2)+2,math.ceil((rY-h)/2)+1,w-4,h-5,1)
- object.add('button',math.floor((rX-w)/2)+6,math.ceil((rY-h)/2)+h-4,w-12,3,'Оплатить',2,0xffffff,0x009900,'pay')
- -------
- object.text(math.floor((rX-w)/2)+4,math.ceil((rY-h)/2)+2,w-6,1,'Получатель: '..arr.seller,'First','')
- object.text(math.floor((rX-w)/2)+4,math.ceil((rY-h)/2)+4,w-6,1,'Плательщик: '..arr.buyer,'First','')
- object.text(math.floor((rX-w)/2)+4,math.ceil((rY-h)/2)+6,w-6,1,'Сумма оплаты: '..arr.amount,'First','')
- -------
- object.drawAllObject()
- while true do
- e = getEvent('touch')
- if e[1] == 'touch' then
- arr=object.getPressedObject(e[3],e[4])
- if arr ~= false then
- if arr[1] == 'button' then
- if arr[2] == 'pay' then
- local result = payment(args)
- if result.status == true then
- shell.execute(args.trueFile)
- elseif result.status == false and result.data.error == 'timeout' then
- --
- elseif result.status == false and result.data.error == 'Not enough money' then
- --
- end
- end
- end
- end
- end
- end
- end
- args = {
- operation = 'transfer',
- buyer = 'PandaDoddo',
- key = 'shop',
- seller = 'PandaDoddo',
- amount = 100,
- comment = 'test',
- answearKey = 'KEY',
- trueFile = 'yes'
- }
- gpu.setBackground(0x898989)
- drawMain(args)
- shell.execute("z")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement