Guest User

pay.lua

a guest
Dec 10th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.21 KB | None | 0 0
  1. if not fs.exists("/.pay_card") then
  2.     print("Let me guide you through first time setup now...")
  3.     if not fs.exists("/paym.lua") then
  4.         print("Downloading PAYM")
  5.         shell.run("pastebin get JQALyCL6 paym")
  6.         os.loadAPI("paym")
  7.     end
  8.     print("Card number")
  9.     local cardnum = read()
  10.     print("CVV?")
  11.     local cvv = read("*")
  12.     print("PIN?")
  13.     local pin = read("#")
  14.     print("Verifying details...")
  15.     local info = paym.verify(cardnum, cvv, pin)
  16.     for i, v in pairs(info) do
  17.         if v == false then
  18.             error(i .. " invalid.")
  19.         end
  20.     end
  21.     local data = {
  22.         num = cardnum,
  23.         cvv = cvv,
  24.         pin = pin
  25.     }
  26.     local handle = fs.open("/.pay_card","w")
  27.     handle.write(textutils.serialise(data))
  28.     handle.close()
  29. end
  30. local handle = fs.open("/.pay_card","r")
  31. local data = textutils.unserialise(handle.readAll())
  32. handle.close()
  33. function mm()
  34. term.clear()
  35. term.setBackgroundColor(colors.white)
  36. term.clear()
  37. term.setTextColor(colors.blue)
  38. local w,h = term.getSize()
  39. term.setCursorPos((w - 7) / 2,1)
  40. term.write("QuikPay")
  41. term.setCursorPos(1,3)
  42. term.setTextColor(colors.white)
  43. term.setBackgroundColor(colors.green)
  44. term.write(" Get paid ")
  45. term.setCursorPos(1,5)
  46. term.setBackgroundColor(colors.orange)
  47. term.write(" Pay someone ")
  48. term.setCursorPos(1,7)
  49. term.setBackgroundColor(colors.red)
  50. term.write(" Exit ")
  51. while true do
  52. local _, _, _, y = os.pullEvent("mouse_click")
  53. if y == 3 then
  54.     return 0
  55. end
  56. if y == 5 then
  57.     return 1
  58. end
  59. if y == 7 then
  60.     error("Terminated",2)
  61. end
  62. end
  63. end
  64. function dr()
  65.     term.setBackgroundColor(colors.white)
  66.     term.clear()
  67.     term.setCursorPos(1,1)
  68.     term.setTextColor(colors.black)
  69.     print("Amount?")
  70.     local amount = tonumber(read())
  71.     if not amount then
  72.         error("Invalid amount")
  73.     end
  74.     print("Reason?")
  75.     local reason = read()
  76.     local ok, id = paym.initContactless(amount, data.num, reason)
  77.     if ok == false then
  78.         term.setBackgroundColor(colors.black)
  79.         term.setTextColor(colors.white)
  80.         term.setCursorPos(1,1)
  81.         error(id)
  82.     end
  83.     while true do
  84.     print("ID: " .. id)
  85.     print("Press any key to verify")
  86.     os.pullEvent("char")
  87.     local ok, data = paym.checkContactless(id)
  88.     if data.paid == true then
  89.         print("Paid!")
  90.         break
  91.     else
  92.         print("Not yet paid")
  93.     end
  94.     end
  95. end
  96. function pay()
  97.     term.setBackgroundColor(colors.white)
  98.     term.setTextColor(colors.black)
  99.     term.setCursorPos(1,1)
  100.     term.clear()
  101.     print("Payment ID")
  102.     local id = read()
  103.     print("Contacting API")
  104.     local ok, data = paym.checkContactless(id)
  105.     if ok == false then
  106.         error(data)
  107.     end
  108.     for i,v in pairs(data) do
  109.         print(i .. ":" .. v)
  110.     end
  111.     print("To pay, press \"Y\", else press any key")
  112.     local _,c = os.pullEvent("char")
  113.     if c == "y" or c == "Y" then
  114.         print("Paying")
  115.         local ok, data = paym.payContactless(data.num, data.cvv, data.pin, id)
  116.         if ok == false then
  117.             error(data)
  118.         end
  119.         print("Paid")
  120.     end
  121. end
  122. while true do
  123.     x = mm()
  124.     if x == 0 then
  125.         dr()
  126.     else
  127.         pay()
  128.     end
  129. end
Add Comment
Please, Sign In to add comment