Class PaymentTerminal
- Direct Known Subclasses:
AdyenCloudTerminal, 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidcancel()Asks the terminal to abandon the operation in progress.Takes money a pre-authorization reserved.abstract AsyncResource<TerminalResult> collect(TerminalPaymentRequest request) Takes a payment: a sale, or a pre-authorization when the request says so.protected static AsyncResource<TerminalResult> A resource that has already failed witherror; for implementations.Finds out what became of a payment -- the way to settle aTerminalOutcomeUnknownException.protected TerminalOperationmissingCapability(TerminalPaymentRequest request) Rejects a request that asks for an option this terminal lacks; for implementations.Closes the day's batch and reports its totals.refund(TerminalRefundRequest request) Returns money to a card.Cancels a payment that has not settled yet, so it never reaches the customer's statement.abstract booleansupports(TerminalOperation operation) Whether this terminal can performoperation.protected static AsyncResource<TerminalResult> unsupported(TerminalOperation operation) A resource that has already failed because this terminal cannot performoperation; for implementations.
-
Constructor Details
-
PaymentTerminal
public PaymentTerminal()
-
-
Method Details
-
supports
Whether this terminal can perform
operation.Parameters
operation: the operation to ask about
Returns
true when
collect(TerminalPaymentRequest)or the matching method can carry it out -
collect
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
-
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.CANCELEDwhen the cancel won. Does nothing when nothing is in progress. -
capture
Takes money a pre-authorization reserved. Needs
TerminalOperation.CAPTURE.Parameters
-
transactionId: the pre-authorization'sTerminalResult.getTransactionId() -
amount: the amount to take, in the minor unit; at most the reserved amount on most acquirers -
currency: the ISO 4217 code
Returns
the outcome, delivered on the EDT
-
-
reverse
Cancels a payment that has not settled yet, so it never reaches the customer's statement. Once settled, use
refund(TerminalRefundRequest). NeedsTerminalOperation.REVERSAL.Parameters
transactionId: the payment'sTerminalResult.getTransactionId()
Returns
the outcome, delivered on the EDT
-
refund
Returns money to a card. Needs
TerminalOperation.REFUND, orTerminalOperation.UNLINKED_REFUNDwhen the request names no payment.Parameters
request: what to return, and to which payment
Returns
the outcome, delivered on the EDT
-
lookup
Finds out what became of a payment -- the way to settle a
TerminalOutcomeUnknownException. NeedsTerminalOperation.LOOKUP.Parameters
reference: the payment'sTerminalPaymentRequest.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
Closes the day's batch and reports its totals. Needs
TerminalOperation.RECONCILIATION.Returns
the report, delivered on the EDT
-
unsupported
A resource that has already failed because this terminal cannot perform
operation; for implementations.Parameters
operation: the operation refused
Returns
a failed resource
-
failed
A resource that has already failed with
error; for implementations.Parameters
error: why
Returns
a failed resource
-
missingCapability
Rejects a request that asks for an option this terminal lacks; for implementations.
Parameters
request: the request about to be started
Returns
the operation the request needs and this terminal lacks, or null when it can run
-