POSTerminalpublic class POSTerminal extends Terminal This class implements a Point Of Sale terminal.
It allows for crediting the on-card account and querying the current account
balance. |
Constructors Summary |
---|
POSTerminal(String hostName, int hostPort, byte[] staticKeyData)Creates a Point Of Sale terminal.
super(hostName, hostPort, staticKeyData);
|
Methods Summary |
---|
private void | credit(byte amount)Credits the on-card account.
// Request Message: [1-byte Credit Amount]
byte[] requestMessage = new byte[1];
requestMessage[0] = amount;
// Response Message: []
byte[] responseMessage = processRequest(CREDIT, requestMessage);
if (responseMessage != null) {
System.out.println("credit: [" + amount + "] => " + "OK");
} else {
System.out.println("credit: [" + amount + "] => " + "error");
}
| private void | getBalance()Gets the on-card account balance.
// Request Message: []
byte[] requestMessage = new byte[0];
// Response Message: [2-bytes Balance]
byte[] responseMessage = processRequest(GET_BALANCE, requestMessage);
if (responseMessage != null) {
// Retrieve the balance
short balance = getShort(responseMessage, 0);
System.out.println("getBalance: [] => " + "[ " + balance + " ]");
} else {
System.out.println("getBalance: [] => " + "error");
}
| public static void | main(java.lang.String[] args)Parses and runs the CLI command.
int i = parseCommonArgs(args);
if (i <= 0) {
usage();
System.exit(3);
}
POSTerminal terminal = new POSTerminal(hostName, port, staticKeyData);
terminal.powerUp();
terminal.selectApplet();
terminal.initializeSession();
for (; i < args.length; i++) {
if (args[i].equals("VERIFY")) {
if (++i < args.length) {
byte[] pin = args[i].getBytes();
terminal.verifyPIN(pin);
} else {
usage();
System.exit(3);
}
} else if (args[i].equals("GET_BALANCE")) {
terminal.getBalance();
} else if (args[i].equals("CREDIT")) {
if (++i < args.length) {
byte creditAmount = new Byte(args[i]).byteValue();
terminal.credit(creditAmount);
} else {
usage();
System.exit(3);
}
} else {
usage();
System.exit(3);
}
}
terminal.powerDown();
System.exit(0);
| private static void | usage()Prints the usage.
commonUsage();
System.out
.println("<command list>: ([VERIFY <pin>]|[GET_BALANCE]|[CREDIT <credit amount>])*");
|
|