Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public abstract class PaymentTerminal
- Object
- 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.AdyenCloudTerminalandAdyenLocalTerminal– 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
Inherited methods
Constructor details
PaymentTerminal
public PaymentTerminal()Method details
supports
public abstract boolean supports(TerminalOperation operation)operation.Parameters
operationTerminalOperation- the operation to ask about
Returns
collect(TerminalPaymentRequest) or the matching method
can carry it outcollect
public abstract AsyncResource<TerminalResult> collect(TerminalPaymentRequest request)Parameters
requestTerminalPaymentRequest- what to charge
Returns
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)TerminalOperation.CAPTURE.Parameters
transactionIdString- the pre-authorization’s
TerminalResult.getTransactionId() amountlong- the amount to take, in the minor unit; at most the reserved amount on most acquirers
currencyString- the ISO 4217 code
Returns
reverse
public AsyncResource<TerminalResult> reverse(String transactionId)refund(TerminalRefundRequest). Needs TerminalOperation.REVERSAL.Parameters
transactionIdString- the payment’s
TerminalResult.getTransactionId()
Returns
refund
public AsyncResource<TerminalResult> refund(TerminalRefundRequest request)TerminalOperation.REFUND, or
TerminalOperation.UNLINKED_REFUND when the request names no
payment.Parameters
requestTerminalRefundRequest- what to return, and to which payment
Returns
lookup
public AsyncResource<TerminalResult> lookup(String reference)TerminalOutcomeUnknownException. Needs TerminalOperation.LOOKUP.Parameters
referenceString- the payment’s
TerminalPaymentRequest.getReference(), or its transaction ID where the terminal accepts one
Returns
reconcile
public AsyncResource<TerminalReconciliation> reconcile()TerminalOperation.RECONCILIATION.Returns
unsupported
protected static AsyncResource<TerminalResult> unsupported(TerminalOperation operation)operation; for implementations.Parameters
operationTerminalOperation- the operation refused
Returns
failed
protected static AsyncResource<TerminalResult> failed(Throwable error)error; for implementations.Parameters
errorThrowable- why
Returns
missingCapability
protected TerminalOperation missingCapability(TerminalPaymentRequest request)Parameters
requestTerminalPaymentRequest- the request about to be started