Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class StripeReaderTerminal
- Object
- PaymentTerminal
- StripeReaderTerminal
A Stripe smart reader (WisePOS E, S700, S710) on the counter, driven through Stripe’s server-driven integration.
The reader is on the store’s network and registered to a Stripe location; nothing here talks to it directly. Each payment is a request to Stripe’s API that hands a PaymentIntent to the reader, followed by polling the reader’s action until the customer has tapped. That is plain HTTPS, so this works on every platform – the desktop ports, mobile and the web – with no native SDK.
Credentials
Stripe’s API takes a secret key, which must not ship in an app a
customer can install. For a point-of-sale app on a till you control, use
a restricted key limited to Terminal readers and PaymentIntents.
Otherwise point setApiBase(String) at your own server, which adds the
key and forwards the same paths to https://api.stripe.com – the API key
passed here can then be your own session token, or null.
String restrictedKey = null; // null: your server adds the key
StripeReaderTerminal reader = new StripeReaderTerminal("tmr_FDOt2wlRZEdpd7", restrictedKey);
reader.collect(new TerminalPaymentRequest(1250, "USD")).ready(result -> {
if (result.isApproved()) {
// Confirm result.getTransactionId() on your server, then fulfill.
}
});A request with a TerminalPaymentRequest.getProviderReference() uses
that PaymentIntent (pi_...), created by your server, as it is: its
amount, capture method and metadata are the server’s. Without one, a
card-present PaymentIntent is created first, with manual capture for a
pre-authorization and the request’s reference in its metadata, where
lookup(String) finds it.
What else it does
capture(String, long, String)captures a pre-authorization.reverse(String)cancels a PaymentIntent that is not captured yet.refund(TerminalRefundRequest)refunds a payment by its PaymentIntent ID. Stripe refunds a card-present payment to the card without the reader, so unlinked refunds are not supported.lookup(String)reads a PaymentIntent by ID (pi_...), or finds one by the reference a sale was started with. The ID is the reliable key: Stripe’s search trails its writes by up to a minute, and a PaymentIntent your server created carries no reference unless it setmetadata[reference].- Tipping on the reader needs a tipping configuration on the reader’s Stripe location.
Settlement happens on Stripe’s side, so there is no reconciliation, and cashback is not offered.
Constructors
public StripeReaderTerminal(String readerId, String apiKey) |
Methods
Inherited methods
Constructor details
StripeReaderTerminal
public StripeReaderTerminal(String readerId, String apiKey)Parameters
readerIdString- the reader’s ID,
tmr_... apiKeyString- sent as a bearer token; a restricted Stripe key, or
whatever your own server expects when
setApiBase(String)points there. May be null when the transport authenticates by itself.
Method details
getReaderId
public String getReaderId()setApiBase
public void setApiBase(String apiBase)https://api.stripe.com,
such as a server of yours that adds the secret key.Parameters
apiBaseString- the base URL, with no trailing slash
setTransport
public void setTransport(TerminalTransport transport)Parameters
transportTerminalTransport- the transport
setPollInterval
public void setPollInterval(int pollInterval)Parameters
pollIntervalint- the interval in milliseconds
setMaxWait
public void setMaxWait(long maxWait)TerminalResult.Status.FAILED. Defaults to five minutes.Parameters
maxWaitlong- the limit in milliseconds
supports
public boolean supports(TerminalOperation operation)operation.Parameters
operationTerminalOperation- the operation to ask about
Returns
collect(TerminalPaymentRequest) or the matching method
can carry it outcollect
public AsyncResource<TerminalResult> collect(TerminalPaymentRequest request)Parameters
requestTerminalPaymentRequest- what to charge
Returns
cancel
public 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
schedule
protected void schedule(int delay, Runnable task)task on the EDT after delay milliseconds. Overridable so a
subclass can drive the polling from its own clock.Parameters
delayint- the delay in milliseconds
taskRunnable- what to run