Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class MdbCashlessTerminal

  1. Object
  2. PaymentTerminal
  3. MdbCashlessTerminal

A cashless reader on an MDB bus, driven by the app as the vending machine controller (VMC), following MDB/ICP level 1 cashless device commands.

MdbBus myAdapter = (block, timeout) -> new byte[0]; // your adapter board
MdbCashlessTerminal reader = new MdbCashlessTerminal(myAdapter);
reader.setItemNumber(12);
reader.collect(new TerminalPaymentRequest(250, "EUR")).ready(result -> {
    if (result.isApproved()) {
        boolean ok = true; // whether the machine dispensed item 12
        reader.completeVend(ok);
    }
});

A sale enables the reader and waits for the customer to present a card, then asks to vend the price. An approval is delivered before anything is dispensed; call completeVend(boolean) once the product is out, or not, so the reader settles or refunds. With setAutoComplete(boolean) the vend is reported successful at once, for a machine that cannot fail. The approval is an authorization: a vend never completed within five session timeouts is reported failed, and the reader refunds it. The resource completeVend(boolean) returns says whether the money was kept.

Amounts convert through the reader’s scale factor and decimal places from its setup answer.

Constructors

public MdbCashlessTerminal(MdbBus bus)

Methods

public void setItemNumber(int itemNumber)The item number reported with each vend; 0xFFFF (the default) means unspecified.
public void setAutoComplete(boolean autoComplete)Reports every approved vend as dispensed at once.
public void setSessionTimeout(int sessionTimeout)How long a sale waits for a card and for the reader’s answer.
public boolean supports(TerminalOperation operation)Whether this terminal can perform operation.
public AsyncResource<TerminalResult> collect(TerminalPaymentRequest request)Takes a payment: a sale, or a pre-authorization when the request says so.
public AsyncResource<Boolean> completeVend(boolean dispensed)Tells the reader whether the approved product was dispensed.
public void cancel()Cancels a sale still waiting for a card or an approval.
protected void start(Runnable task)Runs task on a thread of its own; tests override it.
protected void deliver(Runnable task)Hands a result to the app on the EDT; tests override it.
protected void pause(int millis)Waits between polls; tests override it.

Inherited methods

Constructor details

MdbCashlessTerminal

public MdbCashlessTerminal(MdbBus bus)

Parameters

bus MdbBus
the adapter to the MDB bus

Method details

setItemNumber

public void setItemNumber(int itemNumber)
The item number reported with each vend; 0xFFFF (the default) means unspecified.

Parameters

itemNumber int
the product’s number

setAutoComplete

public void setAutoComplete(boolean autoComplete)
Reports every approved vend as dispensed at once.

Parameters

autoComplete boolean
true to skip completeVend(boolean)

setSessionTimeout

public void setSessionTimeout(int sessionTimeout)
How long a sale waits for a card and for the reader’s answer. Defaults to a minute.

Parameters

sessionTimeout int
the limit in milliseconds

supports

public boolean supports(TerminalOperation operation)
Whether this terminal can perform operation.

Parameters

operation TerminalOperation
the operation to ask about

Returns

true when collect(TerminalPaymentRequest) or the matching method can carry it out

collect

public AsyncResource<TerminalResult> collect(TerminalPaymentRequest request)
Takes a payment: a sale, or a pre-authorization when the request says so.

Parameters

request TerminalPaymentRequest
what to charge

Returns

the outcome, delivered on the EDT

completeVend

public AsyncResource<Boolean> completeVend(boolean dispensed)
Tells the reader whether the approved product was dispensed. A failed vend is refunded by the reader.

Parameters

dispensed boolean
true when the customer got the product

Returns

true once the reader has kept the payment, false when it refunded it or the vend could not be reported to it (check the reader’s journal)

cancel

public void cancel()
Cancels a sale still waiting for a card or an approval.

start

protected void start(Runnable task)
Runs task on a thread of its own; tests override it.

Parameters

task Runnable
the blocking work

deliver

protected void deliver(Runnable task)
Hands a result to the app on the EDT; tests override it.

Parameters

task Runnable
the delivery

pause

protected void pause(int millis)
Waits between polls; tests override it.

Parameters

millis int
how long