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

public class StripeReaderTerminal

  1. Object
  2. PaymentTerminal
  3. 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 set metadata[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

public String getReaderId()The reader this terminal drives.
public void setApiBase(String apiBase)Sends requests to another base URL than https://api.stripe.com, such as a server of yours that adds the secret key.
public void setTransport(TerminalTransport transport)Replaces the HTTP transport.
public void setPollInterval(int pollInterval)How often the reader is polled while a payment is in progress, in milliseconds.
public void setMaxWait(long maxWait)How long a payment may wait for the customer before it is canceled and reported as TerminalResult.Status.FAILED.
public boolean supports(TerminalOperation operation)Whether this terminal can perform operation.
public AsyncResource<TerminalResult> collect(TerminalPaymentRequest request)Takes a payment: a sale, or a pre-authorization when the request says so.
public 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.
protected void schedule(int delay, Runnable task)Runs task on the EDT after delay milliseconds.

Inherited methods

Constructor details

StripeReaderTerminal

public StripeReaderTerminal(String readerId, String apiKey)

Parameters

readerId String
the reader’s ID, tmr_...
apiKey String
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()
The reader this terminal drives.

setApiBase

public void setApiBase(String apiBase)
Sends requests to another base URL than https://api.stripe.com, such as a server of yours that adds the secret key.

Parameters

apiBase String
the base URL, with no trailing slash

setTransport

public void setTransport(TerminalTransport transport)
Replaces the HTTP transport.

Parameters

transport TerminalTransport
the transport

setPollInterval

public void setPollInterval(int pollInterval)
How often the reader is polled while a payment is in progress, in milliseconds. Defaults to one second.

Parameters

pollInterval int
the interval in milliseconds

setMaxWait

public void setMaxWait(long maxWait)
How long a payment may wait for the customer before it is canceled and reported as TerminalResult.Status.FAILED. Defaults to five minutes.

Parameters

maxWait long
the limit in milliseconds

supports

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

schedule

protected void schedule(int delay, Runnable task)
Runs task on the EDT after delay milliseconds. Overridable so a subclass can drive the polling from its own clock.

Parameters

delay int
the delay in milliseconds
task Runnable
what to run