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

public abstract class PaymentTerminal

  1. Object
  2. PaymentTerminal

Known subtypesAdyenCloudTerminal, MdbCashlessTerminal, SquareTerminal, StripeReaderTerminal, TapToPay, ZvtTerminal

A card terminal: takes in-person payments and, where the terminal supports it, everything a point of sale does around them – refunds, reversals, pre-authorizations and their capture, lookups after a lost connection, and the end-of-day reconciliation.

Every operation answers the same way: a resource that completes on the EDT with a TerminalResult once the terminal decided – approved, declined, canceled or failed. It completes with an error only when the terminal could not be asked at all (no connection, a rejected credential, a malformed answer), so a decline is never an exception. One error is special: a TerminalOutcomeUnknownException means the card may have been charged, and the app must look the payment up before charging again.

Not every terminal can do everything. supports(TerminalOperation) says what this one can; an unsupported operation completes with an UnsupportedOperationException without touching the card.

For every operation, TerminalResult.Status.APPROVED means the operation went through: the sale was charged, the reversal or refund was accepted, the capture took the money. A lookup reports the payment’s own status instead.

One operation that drives the terminal itself (a sale, or a refund taken on the card) runs at a time per terminal; starting a second completes it with an IllegalStateException and leaves the first alone. Operations a provider carries out on its servers without the terminal may run alongside one.

The implementations in this tree:

  • com.codename1.payment.terminal.tap.TapToPay – the phone itself reads the card (Tap to Pay on iPhone and Android, over the Stripe Terminal SDK).
  • com.codename1.payment.terminal.stripe.StripeReaderTerminal – a Stripe smart reader on the counter, driven over Stripe’s API.
  • com.codename1.payment.terminal.adyen.AdyenCloudTerminal and AdyenLocalTerminal – any Adyen terminal, through Adyen’s cloud or directly over the shop’s network.
  • com.codename1.payment.terminal.square.SquareTerminal – a Square Terminal, through Square’s API.

Constructors

public PaymentTerminal()

Methods

public abstract boolean supports(TerminalOperation operation)Whether this terminal can perform operation.
public abstract AsyncResource<TerminalResult> collect(TerminalPaymentRequest request)Takes a payment: a sale, or a pre-authorization when the request says so.
public abstract void cancel()Asks the terminal to abandon the operation in progress.
public AsyncResource<TerminalResult> capture(String transactionId, long amount, String currency)Takes money a pre-authorization reserved.
public AsyncResource<TerminalResult> reverse(String transactionId)Cancels a payment that has not settled yet, so it never reaches the customer’s statement.
public AsyncResource<TerminalResult> refund(TerminalRefundRequest request)Returns money to a card.
public AsyncResource<TerminalResult> lookup(String reference)Finds out what became of a payment – the way to settle a TerminalOutcomeUnknownException.
public AsyncResource<TerminalReconciliation> reconcile()Closes the day’s batch and reports its totals.
protected static AsyncResource<TerminalResult> unsupported(TerminalOperation operation)A resource that has already failed because this terminal cannot perform operation; for implementations.
protected static AsyncResource<TerminalResult> failed(Throwable error)A resource that has already failed with error; for implementations.
protected TerminalOperation missingCapability(TerminalPaymentRequest request)Rejects a request that asks for an option this terminal lacks; for implementations.

Inherited methods

Constructor details

PaymentTerminal

public PaymentTerminal()

Method details

supports

public abstract 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 abstract 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

cancel

public abstract void cancel()

Asks the terminal to abandon the operation in progress.

Best effort: a card that was already read may still be approved, so the outcome is whatever the operation delivers, TerminalResult.Status.CANCELED when the cancel won. Does nothing when nothing is in progress.

capture

public AsyncResource<TerminalResult> capture(String transactionId, long amount, String currency)
Takes money a pre-authorization reserved. Needs TerminalOperation.CAPTURE.

Parameters

transactionId String
the pre-authorization’s TerminalResult.getTransactionId()
amount long
the amount to take, in the minor unit; at most the reserved amount on most acquirers
currency String
the ISO 4217 code

Returns

the outcome, delivered on the EDT

reverse

public AsyncResource<TerminalResult> reverse(String transactionId)
Cancels a payment that has not settled yet, so it never reaches the customer’s statement. Once settled, use refund(TerminalRefundRequest). Needs TerminalOperation.REVERSAL.

Parameters

transactionId String
the payment’s TerminalResult.getTransactionId()

Returns

the outcome, delivered on the EDT

refund

public AsyncResource<TerminalResult> refund(TerminalRefundRequest request)
Returns money to a card. Needs TerminalOperation.REFUND, or TerminalOperation.UNLINKED_REFUND when the request names no payment.

Parameters

request TerminalRefundRequest
what to return, and to which payment

Returns

the outcome, delivered on the EDT

lookup

public AsyncResource<TerminalResult> lookup(String reference)
Finds out what became of a payment – the way to settle a TerminalOutcomeUnknownException. Needs TerminalOperation.LOOKUP.

Parameters

reference String
the payment’s TerminalPaymentRequest.getReference(), or its transaction ID where the terminal accepts one

Returns

the payment’s result as the terminal or provider recorded it; completes with an error when it has no such payment

reconcile

public AsyncResource<TerminalReconciliation> reconcile()
Closes the day’s batch and reports its totals. Needs TerminalOperation.RECONCILIATION.

Returns

the report, delivered on the EDT

unsupported

protected static AsyncResource<TerminalResult> unsupported(TerminalOperation operation)
A resource that has already failed because this terminal cannot perform operation; for implementations.

Parameters

operation TerminalOperation
the operation refused

Returns

a failed resource

failed

protected static AsyncResource<TerminalResult> failed(Throwable error)
A resource that has already failed with error; for implementations.

Parameters

error Throwable
why

Returns

a failed resource

missingCapability

protected TerminalOperation missingCapability(TerminalPaymentRequest request)
Rejects a request that asks for an option this terminal lacks; for implementations.

Parameters

request TerminalPaymentRequest
the request about to be started

Returns

the operation the request needs and this terminal lacks, or null when it can run