SHOW:
|
|
- or go back to the newest paste.
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 | os.loadAPI("paym") | |
31 | - | local data = textutils.unserialise(handle.readAll()) |
31 | + | |
32 | local pdata = textutils.unserialise(handle.readAll()) | |
33 | handle.close() | |
34 | function mm() | |
35 | term.clear() | |
36 | term.setBackgroundColor(colors.white) | |
37 | term.clear() | |
38 | term.setTextColor(colors.blue) | |
39 | local w,h = term.getSize() | |
40 | term.setCursorPos((w - 7) / 2,1) | |
41 | term.write("QuikPay") | |
42 | term.setCursorPos(1,3) | |
43 | term.setTextColor(colors.white) | |
44 | term.setBackgroundColor(colors.green) | |
45 | term.write(" Get paid ") | |
46 | term.setCursorPos(1,5) | |
47 | term.setBackgroundColor(colors.orange) | |
48 | term.write(" Pay someone ") | |
49 | term.setCursorPos(1,7) | |
50 | term.setBackgroundColor(colors.red) | |
51 | term.write(" Exit ") | |
52 | while true do | |
53 | local _, _, _, y = os.pullEvent("mouse_click") | |
54 | if y == 3 then | |
55 | return 0 | |
56 | end | |
57 | if y == 5 then | |
58 | return 1 | |
59 | end | |
60 | if y == 7 then | |
61 | error("Terminated",2) | |
62 | end | |
63 | end | |
64 | end | |
65 | function dr() | |
66 | term.setBackgroundColor(colors.white) | |
67 | term.clear() | |
68 | term.setCursorPos(1,1) | |
69 | term.setTextColor(colors.black) | |
70 | print("Amount?") | |
71 | local amount = tonumber(read()) | |
72 | if not amount then | |
73 | error("Invalid amount") | |
74 | end | |
75 | print("Reason?") | |
76 | - | local ok, id = paym.initContactless(amount, data.num, reason) |
76 | + | |
77 | local ok, id = paym.initContactless(amount, pdata.num, reason) | |
78 | if ok == false then | |
79 | term.setBackgroundColor(colors.black) | |
80 | term.setTextColor(colors.white) | |
81 | term.setCursorPos(1,1) | |
82 | error(id) | |
83 | end | |
84 | while true do | |
85 | print("ID: " .. id) | |
86 | print("Press any key to verify") | |
87 | os.pullEvent("char") | |
88 | local ok, data = paym.checkContactless(id) | |
89 | if data.paid == true then | |
90 | print("Paid!") | |
91 | break | |
92 | else | |
93 | print("Not yet paid") | |
94 | end | |
95 | end | |
96 | end | |
97 | function pay() | |
98 | term.setBackgroundColor(colors.white) | |
99 | term.setTextColor(colors.black) | |
100 | term.setCursorPos(1,1) | |
101 | term.clear() | |
102 | print("Payment ID") | |
103 | local id = read() | |
104 | print("Contacting API") | |
105 | local ok, data = paym.checkContactless(id) | |
106 | if ok == false then | |
107 | error(data) | |
108 | end | |
109 | - | print(i .. ":" .. v) |
109 | + | |
110 | print(i .. ":" .. tostring(v)) | |
111 | end | |
112 | print("To pay, press \"Y\", else press any key") | |
113 | local _,c = os.pullEvent("char") | |
114 | if c == "y" or c == "Y" then | |
115 | - | local ok, data = paym.payContactless(data.num, data.cvv, data.pin, id) |
115 | + | |
116 | local ok, data = paym.payContactless(pdata.num, pdata.cvv, pdata.pin, id) | |
117 | if ok == false then | |
118 | error(data) | |
119 | end | |
120 | print("Paid") | |
121 | end | |
122 | end | |
123 | while true do | |
124 | x = mm() | |
125 | if x == 0 then | |
126 | dr() | |
127 | else | |
128 | pay() | |
129 | end | |
130 | end |