API to talk with bank_server
- run
oppm install bank_api
The configuration file for the API is /etc/bank/api/conf.conf
Mandatory : yes
Type : string
Default : ""
Secret delivered by the server to authenticated trusted clients.
Can be "" for untrusted clients.
Mandatory : yes
Type : number
Default : 5
How long to wait for the server to answer before giving up with a timeout (-1) status
Mandatory : yes
Type : string
Default : "00000000-0000-0000-0000-000000000000"
The server network card address
local bank = require("bank_api")The first return value of all methods is a status code.
cbData is obtained with libCB.
Those methods can be called from any client.
Return the balance of the account
cbData's account will pay targetAccount amount
All this methods require a valid secret to be set in the api's configuration file
Return the newly create account's uuid
Without cbUUID, the srv will assume it is a magcard from open security and need less data.
Add amount to the account. If amount is negative, it will be removed form the account.
A account can't have a negative balance.
- 0 = OK
- 1 = NO_ACCOUNT
- 2 = ERROR_ACCOUNT
- 3 = ERROR_CB
- 4 = ERROR_AMOUNT
- 5 = ERROR_RECEIVING_ACCOUNT
- -1 = timeout
- -2 = wrong message
local libCB = require("libCB")
local bank = require("bank_api")
local PIN = "1234" --The card's pin should be asked to the user, not hard coded
local reader = libCB.waitForCB() --wait for a debit card to be available
local encryptedData = libCB.loadCB(reader) --load the debit card data
local cbData = libCB.getCB(encryptedData,PIN) --decrypt the data
--Since we already know the pin, the reader proxy could be given to getCB
--local reader = libCB.waitForCB()
--local cbData = libCB.getCB(reader,PIN)
local status,balance = bank_api.getCredit(cbData) --request the account's balance from the server
if(status == 0) then -- 0 = OK
print(cbData.uuid,balance)
end