mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-26 22:42:26 +01:00
Adds a helper proc for money transfers (#5876)
Adds a helper proc for money transfers between two accounts. Cleans up the EFTPOS and cargo delivery code to use said helper proc. Changes SSEconomy to use indexed lists for accounts and look up the accounts by accessing it via the index.
This commit is contained in:
@@ -95,13 +95,12 @@
|
||||
data["transactions"] = trx
|
||||
|
||||
var/list/accounts[0]
|
||||
for(var/i=1, i<=SSeconomy.all_money_accounts.len, i++)
|
||||
var/datum/money_account/D = SSeconomy.all_money_accounts[i]
|
||||
for(var/M in SSeconomy.all_money_accounts)
|
||||
var/datum/money_account/D = SSeconomy.get_account(M)
|
||||
accounts.Add(list(list(\
|
||||
"account_number"=D.account_number,\
|
||||
"owner_name"=D.owner_name,\
|
||||
"suspended"=D.suspended ? "SUSPENDED" : "",\
|
||||
"account_index"=i)))
|
||||
"suspended"=D.suspended ? "SUSPENDED" : "")))
|
||||
|
||||
if (accounts.len > 0)
|
||||
data["accounts"] = accounts
|
||||
@@ -174,9 +173,7 @@
|
||||
held_card = C
|
||||
|
||||
if("view_account_detail")
|
||||
var/index = text2num(href_list["account_index"])
|
||||
if(index && index <= SSeconomy.all_money_accounts.len)
|
||||
detailed_account_view = SSeconomy.all_money_accounts[index]
|
||||
detailed_account_view = SSeconomy.get_account(href_list["account_number"])
|
||||
|
||||
if("view_accounts_list")
|
||||
detailed_account_view = null
|
||||
@@ -254,8 +251,8 @@
|
||||
<tbody>
|
||||
"}
|
||||
|
||||
for(var/i=1, i<=SSeconomy.all_money_accounts.len, i++)
|
||||
var/datum/money_account/D = SSeconomy.all_money_accounts[i]
|
||||
for(var/M in SSeconomy.all_money_accounts)
|
||||
var/datum/money_account/D = SSeconomy.get_account(M)
|
||||
text += {"
|
||||
<tr>
|
||||
<td>#[D.account_number]</td>
|
||||
|
||||
+59
-100
@@ -11,56 +11,52 @@
|
||||
var/transaction_purpose = "Default charge"
|
||||
var/access_code = 0
|
||||
var/datum/money_account/linked_account
|
||||
var/prelocked_account = null
|
||||
|
||||
/obj/item/device/eftpos/New()
|
||||
/obj/item/device/eftpos/Initialize()
|
||||
..()
|
||||
machine_id = "[station_name()] EFTPOS #[SSeconomy.num_financial_terminals++]"
|
||||
access_code = rand(1111,111111)
|
||||
spawn(0)
|
||||
print_reference()
|
||||
|
||||
//create a short manual as well
|
||||
var/obj/item/weapon/paper/R = new(src.loc)
|
||||
R.name = "Steps to success: Correct EFTPOS Usage"
|
||||
/*
|
||||
R.info += "<b>When first setting up your EFTPOS device:</b>"
|
||||
R.info += "1. Memorise your EFTPOS command code (provided with all EFTPOS devices).<br>"
|
||||
R.info += "2. Confirm that your EFTPOS device is connected to your local accounts database. For additional assistance with this step, contact NanoTrasen IT Support<br>"
|
||||
R.info += "3. Confirm that your EFTPOS device has been linked to the account that you wish to receive funds for all transactions processed on this device.<br>"
|
||||
R.info += "<b>When starting a new transaction with your EFTPOS device:</b>"
|
||||
R.info += "1. Ensure the device is UNLOCKED so that new data may be entered.<br>"
|
||||
R.info += "2. Enter a sum of money and reference message for the new transaction.<br>"
|
||||
R.info += "3. Lock the transaction, it is now ready for your customer.<br>"
|
||||
R.info += "4. If at this stage you wish to modify or cancel your transaction, you may simply reset (unlock) your EFTPOS device.<br>"
|
||||
R.info += "5. Give your EFTPOS device to the customer, they must authenticate the transaction by swiping their ID card and entering their PIN number.<br>"
|
||||
R.info += "6. If done correctly, the transaction will be logged to both accounts with the reference you have entered, the terminal ID of your EFTPOS device and the money transferred across accounts.<br>"
|
||||
*/
|
||||
//Temptative new manual:
|
||||
R.info += "<b>First EFTPOS setup:</b><br>"
|
||||
R.info += "1. Memorise your EFTPOS command code (provided with all EFTPOS devices).<br>"
|
||||
R.info += "2. Connect the EFTPOS to the account in which you want to receive the funds.<br><br>"
|
||||
R.info += "<b>When starting a new transaction:</b><br>"
|
||||
R.info += "1. Enter the amount of money you want to charge and a purpose message for the new transaction.<br>"
|
||||
R.info += "2. Lock the new transaction. If you want to modify or cancel the transaction, you simply have to reset your EFTPOS device.<br>"
|
||||
R.info += "3. Give the EFTPOS device to your customer, he/she must finish the transaction by swiping their ID card or a charge card with enough funds.<br>"
|
||||
R.info += "4. If everything is done correctly, the money will be transferred. To unlock the device you will have to reset the EFTPOS device.<br>"
|
||||
link_account()
|
||||
|
||||
return INITIALIZE_HINT_LATELOAD
|
||||
|
||||
/obj/item/device/eftpos/proc/link_account()
|
||||
//Link to the station account, unless prelocked_account is set
|
||||
if(!prelocked_account)
|
||||
linked_account = SSeconomy.station_account
|
||||
else
|
||||
linked_account = SSeconomy.get_department_account(prelocked_account)
|
||||
|
||||
/obj/item/device/eftpos/LateInitialize()
|
||||
print_reference()
|
||||
|
||||
//create a short manual as well
|
||||
var/obj/item/weapon/paper/R = new(src.loc)
|
||||
R.name = "Steps to success: Correct EFTPOS Usage"
|
||||
//Temptative new manual:
|
||||
R.info += "<b>First EFTPOS setup:</b><br>"
|
||||
R.info += "1. Memorise your EFTPOS command code (provided with all EFTPOS devices).<br>"
|
||||
R.info += "2. Connect the EFTPOS to the account in which you want to receive the funds.<br><br>"
|
||||
R.info += "<b>When starting a new transaction:</b><br>"
|
||||
R.info += "1. Enter the amount of money you want to charge and a purpose message for the new transaction.<br>"
|
||||
R.info += "2. Lock the new transaction. If you want to modify or cancel the transaction, you simply have to reset your EFTPOS device.<br>"
|
||||
R.info += "3. Give the EFTPOS device to your customer, he/she must finish the transaction by swiping their ID card or a charge card with enough funds.<br>"
|
||||
R.info += "4. If everything is done correctly, the money will be transferred. To unlock the device you will have to reset the EFTPOS device.<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.offset_x += 0
|
||||
R.offset_y += 0
|
||||
R.ico += "paper_stamp-cent"
|
||||
R.stamped += /obj/item/weapon/stamp
|
||||
R.add_overlay(stampoverlay)
|
||||
R.stamps += "<HR><i>This paper has been stamped by the EFTPOS device.</i>"
|
||||
|
||||
//by default, connect to the station account
|
||||
//the user of the EFTPOS device can change the target account though, and no-one will be the wiser (except whoever's being charged)
|
||||
linked_account = SSeconomy.station_account
|
||||
//stamp the paper
|
||||
var/image/stampoverlay = image('icons/obj/bureaucracy.dmi')
|
||||
stampoverlay.icon_state = "paper_stamp-cent"
|
||||
if(!R.stamped)
|
||||
R.stamped = new
|
||||
R.offset_x += 0
|
||||
R.offset_y += 0
|
||||
R.ico += "paper_stamp-cent"
|
||||
R.stamped += /obj/item/weapon/stamp
|
||||
R.add_overlay(stampoverlay)
|
||||
R.stamps += "<HR><i>This paper has been stamped by the EFTPOS device.</i>"
|
||||
|
||||
/obj/item/device/eftpos/proc/print_reference()
|
||||
var/obj/item/weapon/paper/R = new(src.loc)
|
||||
@@ -103,7 +99,10 @@
|
||||
|
||||
dat += "<a href='?src=\ref[src];choice=trans_purpose'>Transaction purpose: [transaction_purpose]</a><br>"
|
||||
dat += "Value: <a href='?src=\ref[src];choice=trans_value'>$[transaction_amount]</a><br>"
|
||||
dat += "Linked account: <a href='?src=\ref[src];choice=link_account'>[linked_account ? linked_account.owner_name : "None"]</a><hr>"
|
||||
if(!prelocked_account)
|
||||
dat += "Linked account: <a href='?src=\ref[src];choice=link_account'>[linked_account ? linked_account.owner_name : "None"]</a><hr>"
|
||||
else
|
||||
dat += "Linked account: [linked_account.owner_name]<hr>"
|
||||
dat += "<a href='?src=\ref[src];choice=change_code'>Change access code</a><br>"
|
||||
dat += "<a href='?src=\ref[src];choice=change_id'>Change EFTPOS ID</a><br>"
|
||||
dat += "Scan card to reset access code <a href='?src=\ref[src];choice=reset'>\[------\]</a>"
|
||||
@@ -175,15 +174,16 @@
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>Incorrect code entered.</span>"
|
||||
if("link_account")
|
||||
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
|
||||
linked_account = SSeconomy.attempt_account_access(attempt_account_num, attempt_pin, 1)
|
||||
if(linked_account)
|
||||
if(linked_account.suspended)
|
||||
linked_account = null
|
||||
usr << "\icon[src]<span class='warning'>Account has been suspended.</span>"
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>Account not found.</span>"
|
||||
if (!prelocked_account)
|
||||
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
|
||||
linked_account = SSeconomy.attempt_account_access(attempt_account_num, attempt_pin, 1)
|
||||
if(linked_account)
|
||||
if(linked_account.suspended)
|
||||
linked_account = null
|
||||
usr << "\icon[src]<span class='warning'>Account has been suspended.</span>"
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>Account not found.</span>"
|
||||
if("trans_purpose")
|
||||
var/choice = sanitize(input("Enter reason for EFTPOS transaction", "Transaction purpose"))
|
||||
if(choice) transaction_purpose = choice
|
||||
@@ -237,53 +237,14 @@
|
||||
usr.visible_message("<span class='info'>\The [usr] swipes \the [ID_container] through \the [src].</span>")
|
||||
if(transaction_locked && !transaction_paid)
|
||||
if(linked_account)
|
||||
if(!linked_account.suspended)
|
||||
var/attempt_pin = ""
|
||||
var/datum/money_account/D = SSeconomy.get_account(C.associated_account_number)
|
||||
if(D.security_level)
|
||||
attempt_pin = input("Enter pin code", "EFTPOS transaction") as num
|
||||
D = null
|
||||
D = SSeconomy.attempt_account_access(C.associated_account_number, attempt_pin, 2)
|
||||
if(D)
|
||||
if(!D.suspended)
|
||||
if(transaction_amount <= D.money)
|
||||
playsound(src, 'sound/machines/chime.ogg', 50, 1)
|
||||
src.visible_message("\icon[src] \The [src] chimes.")
|
||||
transaction_paid = 1
|
||||
var/message = SSeconomy.transfer_money(C.associated_account_number, linked_account.account_number, transaction_purpose, machine_id, transaction_amount, null, usr)
|
||||
|
||||
//transfer the money
|
||||
D.money -= transaction_amount
|
||||
linked_account.money += transaction_amount
|
||||
|
||||
//create entries in the two account transaction logs
|
||||
var/datum/transaction/T = new()
|
||||
T.target_name = "[linked_account.owner_name] (via [eftpos_name])"
|
||||
T.purpose = transaction_purpose
|
||||
if(transaction_amount > 0)
|
||||
T.amount = "([transaction_amount])"
|
||||
else
|
||||
T.amount = "[transaction_amount]"
|
||||
T.source_terminal = machine_id
|
||||
T.date = worlddate2text()
|
||||
T.time = worldtime2text()
|
||||
SSeconomy.add_transaction_log(D,T)
|
||||
//
|
||||
T = new()
|
||||
T.target_name = D.owner_name
|
||||
T.purpose = transaction_purpose
|
||||
T.amount = "[transaction_amount]"
|
||||
T.source_terminal = machine_id
|
||||
T.date = worlddate2text()
|
||||
T.time = worldtime2text()
|
||||
SSeconomy.add_transaction_log(linked_account,T)
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>You don't have that much money!</span>"
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>Your account has been suspended.</span>"
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>Unable to access account. Check security settings and try again.</span>"
|
||||
if(message)
|
||||
to_chat(usr,"\icon[src]<span class='warning'>[message].</span>")
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>Connected account has been suspended.</span>"
|
||||
playsound(src, 'sound/machines/chime.ogg', 50, 1)
|
||||
src.visible_message("\icon[src] \The [src] chimes.")
|
||||
transaction_paid = 1
|
||||
else
|
||||
usr << "\icon[src]<span class='warning'>EFTPOS is not connected to an account.</span>"
|
||||
else if (istype(I, /obj/item/weapon/card/emag))
|
||||
@@ -299,5 +260,3 @@
|
||||
transaction_paid = 1
|
||||
else
|
||||
..()
|
||||
|
||||
//emag?
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
/datum/event/money_hacker/setup()
|
||||
end_time = world.time + 6000
|
||||
if(SSeconomy.all_money_accounts.len)
|
||||
affected_account = pick(SSeconomy.all_money_accounts)
|
||||
affected_account = SSeconomy.get_account(pick(SSeconomy.all_money_accounts))
|
||||
|
||||
account_hack_attempted = 1
|
||||
else
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/datum/event/money_lotto/start()
|
||||
winner_sum = pick(1, 50, 100, 500, 1000, 2000, 5000)
|
||||
if(SSeconomy.all_money_accounts.len)
|
||||
var/datum/money_account/D = pick(SSeconomy.all_money_accounts)
|
||||
var/datum/money_account/D = SSeconomy.get_account(pick(SSeconomy.all_money_accounts))
|
||||
winner_name = D.owner_name
|
||||
if(!D.suspended)
|
||||
D.money += winner_sum
|
||||
|
||||
@@ -83,65 +83,25 @@
|
||||
|
||||
//Check if a payment is required
|
||||
if(order_details["needs_payment"])
|
||||
var/transaction_amount = order_details["price_customer"];
|
||||
var/transaction_purpose = "Cargo Order #[order_details["order_id"]]";
|
||||
var/transaction_amount = order_details["price_customer"]
|
||||
var/transaction_purpose = "Cargo Order #[order_details["order_id"]]"
|
||||
var/transaction_terminal = "Modular Computer #[program.computer.network_card.identification_id]"
|
||||
|
||||
var/status = SSeconomy.transfer_money(id_card.associated_account_number, SScargo.supply_account.account_number,transaction_purpose,transaction_terminal,transaction_amount,null,usr)
|
||||
|
||||
var/datum/money_account/D = SSeconomy.get_account(id_card.associated_account_number)
|
||||
if(!D)
|
||||
status_message = "Unable to access account. Check security settings and try again."
|
||||
if(status)
|
||||
status_message = status
|
||||
return 1
|
||||
var/attempt_pin
|
||||
if(D.security_level)
|
||||
attempt_pin = input("Enter pin code", "EFTPOS transaction") as num
|
||||
D = null
|
||||
D = SSeconomy.attempt_account_access(id_card.associated_account_number, attempt_pin, 2)
|
||||
if(D)
|
||||
if(!D.suspended)
|
||||
if(transaction_amount <= D.money)
|
||||
playsound(program.computer, 'sound/machines/chime.ogg', 50, 1)
|
||||
|
||||
//transfer the money
|
||||
D.money -= transaction_amount
|
||||
SScargo.supply_account.money += transaction_amount
|
||||
playsound(program.computer, 'sound/machines/chime.ogg', 50, 1)
|
||||
|
||||
//create entries in the two account transaction logs
|
||||
var/datum/transaction/T = new()
|
||||
T.target_name = "[SScargo.supply_account.owner_name]"
|
||||
T.purpose = transaction_purpose
|
||||
if(transaction_amount > 0)
|
||||
T.amount = "([transaction_amount])"
|
||||
else
|
||||
T.amount = "[transaction_amount]"
|
||||
T.source_terminal = "Modular Computer #[program.computer.network_card.identification_id]"
|
||||
T.date = worlddate2text()
|
||||
T.time = worldtime2text()
|
||||
SSeconomy.add_transaction_log(D,T)
|
||||
//
|
||||
T = new()
|
||||
T.target_name = D.owner_name
|
||||
T.purpose = transaction_purpose
|
||||
T.amount = "[transaction_amount]"
|
||||
T.source_terminal = "Modular Computer #[program.computer.network_card.identification_id]"
|
||||
T.date = worlddate2text()
|
||||
T.time = worldtime2text()
|
||||
SSeconomy.add_transaction_log(SScargo.supply_account,T)
|
||||
|
||||
//Check if we have delivered it aswell or only paid
|
||||
if(order_details["status"] == "shipped")
|
||||
status_message = co.set_delivered(id_card.registered_name,1)
|
||||
else
|
||||
status_message = co.set_paid(id_card.registered_name)
|
||||
order_details = co.get_list()
|
||||
return 1
|
||||
else
|
||||
status_message = "You don't have that much money!"
|
||||
return 1
|
||||
else
|
||||
status_message = "Your account has been suspended."
|
||||
return 1
|
||||
//Check if we have delivered it aswell or only paid
|
||||
if(order_details["status"] == "shipped")
|
||||
status_message = co.set_delivered(id_card.registered_name,1)
|
||||
else
|
||||
status_message = "Unable to access account. Check security settings and try again."
|
||||
return 1
|
||||
status_message = co.set_paid(id_card.registered_name)
|
||||
order_details = co.get_list()
|
||||
|
||||
else
|
||||
//TODO: Add a sound effect here
|
||||
//If a payment is not needed and we are at the status shipped, then confirm the delivery
|
||||
|
||||
Reference in New Issue
Block a user