-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
eftpos.dm
220 lines (199 loc) · 8.49 KB
/
eftpos.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#define MAX_EFTPOS_CHARGE 250
/obj/item/eftpos
name = "EFTPOS scanner"
desc = "Swipe your ID card to make purchases electronically."
icon = 'icons/obj/device.dmi'
icon_state = "eftpos"
w_class = WEIGHT_CLASS_SMALL
var/machine_name = ""
var/transaction_locked = 0
var/transaction_paid = 0
var/transaction_amount = 0
var/transaction_purpose = "Default charge"
var/access_code
///linked money account database to this EFTPOS
var/datum/money_account_database/account_database
///Current money account the EFTPOS is depositing to
var/datum/money_account/linked_account
/obj/item/eftpos/Initialize(mapload)
machine_name = "[station_name()] EFTPOS #[rand(101,999)]"
access_code = rand(1000, 9999)
reconnect_database()
print_reference()
//by default, connect to the station vendor account
linked_account = GLOB.station_money_database.vendor_account
return ..()
/obj/item/eftpos/proc/reconnect_database()
account_database = GLOB.station_money_database
/obj/item/eftpos/attack_self(mob/user)
ui_interact(user)
/obj/item/eftpos/attackby(obj/O, mob/user, params)
if(istype(O, /obj/item/card/id))
//attempt to connect to a new db, and if that doesn't work then fail
if(!account_database)
reconnect_database()
if(account_database)
if(linked_account)
scan_card(O, user)
SStgui.update_uis(src)
else
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to linked account.</span>")
else
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to accounts database.</span>")
else
return ..()
/obj/item/eftpos/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, datum/tgui/master_ui = null, datum/ui_state/state = GLOB.inventory_state)
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
if(!ui)
ui = new(user, src, ui_key, "EFTPOS", name, 800, 300, master_ui, state)
ui.open()
/obj/item/eftpos/ui_data(mob/user)
var/list/data = list()
data["machine_name"] = machine_name
data["transaction_locked"] = transaction_locked
data["transaction_paid"] = transaction_paid
data["transaction_purpose"] = transaction_purpose
data["transaction_amount"] = transaction_amount
data["linked_account"] = linked_account ? linked_account.account_name : null
return data
/obj/item/eftpos/ui_act(action, list/params, datum/tgui/ui)
if(..())
return
. = TRUE
var/mob/living/user = ui.user
switch(action)
if("change_code")
var/attempt_code = input("Re-enter the current EFTPOS access code", "Confirm old EFTPOS code") as num
if(attempt_code == access_code)
var/trycode = input("Enter a new access code for this device (4 digits, numbers only)", "Enter new EFTPOS code") as num
if(trycode < 1000 || trycode > 9999)
alert("That is not a valid code!")
return
access_code = trycode
print_reference()
else
to_chat(user, "[bicon(src)]<span class='warning'>Incorrect code entered.</span>")
if("link_account")
if(!account_database)
reconnect_database()
if(account_database)
var/attempt_account_num = input("Enter account number to pay EFTPOS charges into", "New account number") as num
var/attempt_pin = input("Enter pin code", "Account pin") as num
if(!Adjacent(user))
return
var/datum/money_account/target_account = GLOB.station_money_database.find_user_account(attempt_account_num, include_departments = TRUE)
if(!target_account)
for(var/department_key in GLOB.station_money_database.department_accounts)
var/datum/money_account/department_account = GLOB.station_money_database.department_accounts[department_key]
if(department_account.account_number == attempt_account_num)
target_account = department_account
if(target_account && GLOB.station_money_database.try_authenticate_login(target_account, attempt_pin, TRUE, FALSE, FALSE))
linked_account = target_account
else
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to inputed account.</span>")
else
to_chat(user, "[bicon(src)]<span class='warning'>Unable to connect to accounts database.</span>")
if("trans_purpose")
var/purpose = clean_input("Enter reason for EFTPOS transaction", "Transaction purpose", transaction_purpose)
if(!Adjacent(user))
return
if(purpose)
transaction_purpose = purpose
if("trans_value")
var/try_num = input("Enter amount for EFTPOS transaction", "Transaction amount", transaction_amount) as num
if(!Adjacent(user))
return
if(try_num < 0)
alert("That is not a valid amount!")
return
if(try_num > MAX_EFTPOS_CHARGE)
alert("You cannot charge more than [MAX_EFTPOS_CHARGE] per transaction!")
return
transaction_amount = try_num
if("toggle_lock")
if(transaction_locked)
var/attempt_code = input("Enter EFTPOS access code", "Reset Transaction") as num
if(!Adjacent(user))
return
if(attempt_code == access_code)
transaction_locked = FALSE
transaction_paid = FALSE
else if(linked_account)
transaction_locked = TRUE
else
to_chat(user, "[bicon(src)]<span class='warning'>No account connected to send transactions to.</span>")
if("scan_card")
//attempt to connect to a new db, and if that doesn't work then fail
if(!account_database)
reconnect_database()
if(account_database && linked_account)
var/obj/item/I = user.get_active_hand()
if(istype(I, /obj/item/card))
scan_card(I, user)
else
to_chat(user, "[bicon(src)]<span class='warning'>Unable to link accounts.</span>")
if("reset")
//reset the access code - requires HoP/captain access
var/obj/item/I = user.get_active_hand()
if(istype(I, /obj/item/card))
var/obj/item/card/id/C = I
if((ACCESS_CENT_COMMANDER in C.access) || (ACCESS_HOP in C.access) || (ACCESS_CAPTAIN in C.access))
access_code = 0
to_chat(user, "[bicon(src)]<span class='info'>Access code reset to 0.</span>")
else if(istype(I, /obj/item/card/emag))
access_code = 0
to_chat(user, "[bicon(src)]<span class='info'>Access code reset to 0.</span>")
/obj/item/eftpos/proc/scan_card(obj/item/card/id/C, mob/user)
visible_message("<span class='info'>[user] swipes a card through [src].</span>")
if(!transaction_locked || transaction_paid)
return
if(!linked_account)
to_chat(user, "[bicon(src)]<span class='warning'>EFTPOS is not connected to an account.</span>")
return
var/datum/money_account/D = GLOB.station_money_database.find_user_account(C.associated_account_number, include_departments = FALSE)
//if security level high enough, prompt for pin
var/attempt_pin
if(D.security_level != ACCOUNT_SECURITY_ID)
attempt_pin = input("Enter pin code", "EFTPOS transaction") as num
if(!attempt_pin || !Adjacent(user))
return
//given the credentials, can the associated account be accessed right now?
if(!D || !GLOB.station_money_database.try_authenticate_login(D, attempt_pin, restricted_bypass = FALSE))
to_chat(user, "[bicon(src)]<span class='warning'>Unable to access account, insufficient access.</span>")
return
if(alert("Are you sure you want to pay $[transaction_amount] to Account: [linked_account.account_name] ", "Confirm transaction", "Yes", "No") != "Yes")
return
if(!Adjacent(user))
return
//attempt to charge account money
if(!GLOB.station_money_database.charge_account(D, transaction_amount, transaction_purpose, machine_name, FALSE, FALSE))
to_chat(user, "[bicon(src)]<span class='warning'>Insufficient credits in your account!</span>")
return
GLOB.station_money_database.credit_account(linked_account, transaction_amount, transaction_purpose, machine_name, FALSE)
playsound(src, 'sound/machines/chime.ogg', 50, 1)
visible_message("<span class='notice'>[src] chimes!</span>")
transaction_paid = TRUE
///creates and builds paper with info about the EFTPOS
/obj/item/eftpos/proc/print_reference()
playsound(loc, 'sound/goonstation/machines/printer_thermal.ogg', 50, 1)
var/obj/item/paper/R = new(loc)
R.name = "Reference: [machine_name]"
R.info = {"<b>[machine_name] reference</b><br><br>
Access code: [access_code]<br><br>
<b>Do not lose or misplace this code.</b><br>"}
//stamp the paper
var/image/stampoverlay = image('icons/obj/bureaucracy.dmi')
stampoverlay.icon_state = "paper_stamp-cent"
if(!R.stamped)
R.stamped = new
R.stamped += /obj/item/stamp
R.overlays += stampoverlay
R.stamps += "<hr><i>This paper has been stamped by the EFTPOS device.</i>"
var/obj/item/smallDelivery/D = new(get_turf(loc))
if(istype(loc, /mob/living/carbon/human))
var/mob/living/carbon/human/H = loc
if(H.back)
D.forceMove(H.back)
R.forceMove(D)
D.wrapped = R
D.name = "small parcel - 'EFTPOS access code'"