Class MdbCashlessTerminal

java.lang.Object
com.codename1.payment.terminal.PaymentTerminal
com.codename1.payment.terminal.mdb.MdbCashlessTerminal

public class MdbCashlessTerminal extends PaymentTerminal

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.

  • Constructor Details

    • MdbCashlessTerminal

      public MdbCashlessTerminal(MdbBus bus)
      Parameters
      • bus: 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: the product's number
    • setAutoComplete

      public void setAutoComplete(boolean autoComplete)

      Reports every approved vend as dispensed at once.

      Parameters
    • 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: the limit in milliseconds
    • supports

      public boolean supports(TerminalOperation operation)
      Description copied from class: PaymentTerminal

      Whether this terminal can perform operation.

      Parameters
      • operation: the operation to ask about
      Returns

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

      Specified by:
      supports in class PaymentTerminal
    • collect

      Description copied from class: PaymentTerminal

      Takes a payment: a sale, or a pre-authorization when the request says so.

      Parameters
      • request: what to charge
      Returns

      the outcome, delivered on the EDT

      Specified by:
      collect in class PaymentTerminal
    • 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: 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.
      Specified by:
      cancel in class PaymentTerminal
    • start

      protected void start(Runnable task)

      Runs task on a thread of its own; tests override it.

      Parameters
      • task: the blocking work
    • deliver

      protected void deliver(Runnable task)

      Hands a result to the app on the EDT; tests override it.

      Parameters
      • task: the delivery
    • pause

      protected void pause(int millis)

      Waits between polls; tests override it.

      Parameters
      • millis: how long