Class 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Asks the terminal to abandon the operation in progress.Takes money a pre-authorization reserved.collect(TerminalPaymentRequest request) Takes a payment: a sale, or a pre-authorization when the request says so.The reader this terminal drives.Finds out what became of a payment -- the way to settle aTerminalOutcomeUnknownException.refund(TerminalRefundRequest request) Returns money to a card.Cancels a payment that has not settled yet, so it never reaches the customer's statement.protected voidRunstaskon the EDT afterdelaymilliseconds.voidsetApiBase(String apiBase) Sends requests to another base URL thanhttps://api.stripe.com, such as a server of yours that adds the secret key.voidsetMaxWait(long maxWait) How long a payment may wait for the customer before it is canceled and reported asTerminalResult.Status.FAILED.voidsetPollInterval(int pollInterval) How often the reader is polled while a payment is in progress, in milliseconds.voidsetTransport(TerminalTransport transport) Replaces the HTTP transport.booleansupports(TerminalOperation operation) Whether this terminal can performoperation.Methods inherited from class PaymentTerminal
failed, missingCapability, reconcile, unsupported
-
Constructor Details
-
StripeReaderTerminal
Parameters
-
readerId: the reader's ID,tmr_... -
apiKey: sent as a bearer token; a restricted Stripe key, or whatever your own server expects whensetApiBase(String)points there. May be null when the transport authenticates by itself.
-
-
-
Method Details
-
getReaderId
The reader this terminal drives. -
setApiBase
Sends requests to another base URL than
https://api.stripe.com, such as a server of yours that adds the secret key.Parameters
apiBase: the base URL, with no trailing slash
-
setTransport
Replaces the HTTP transport.
Parameters
transport: 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: 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: the limit in milliseconds
-
supports
Description copied from class:PaymentTerminalWhether this terminal can perform
operation.Parameters
operation: the operation to ask about
Returns
true when
PaymentTerminal.collect(TerminalPaymentRequest)or the matching method can carry it out- Specified by:
supportsin classPaymentTerminal
-
collect
Description copied from class:PaymentTerminalTakes 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
- Specified by:
collectin classPaymentTerminal
-
cancel
public void cancel()Description copied from class:PaymentTerminalAsks 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.- Specified by:
cancelin classPaymentTerminal
-
capture
Description copied from class:PaymentTerminalTakes 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
- Overrides:
capturein classPaymentTerminal
-
-
reverse
Description copied from class:PaymentTerminalCancels a payment that has not settled yet, so it never reaches the customer's statement. Once settled, use
PaymentTerminal.refund(TerminalRefundRequest). NeedsTerminalOperation.REVERSAL.Parameters
transactionId: the payment'sTerminalResult.getTransactionId()
Returns
the outcome, delivered on the EDT
- Overrides:
reversein classPaymentTerminal
-
refund
Description copied from class:PaymentTerminalReturns 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
- Overrides:
refundin classPaymentTerminal
-
lookup
Description copied from class:PaymentTerminalFinds 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
- Overrides:
lookupin classPaymentTerminal
-
schedule
Runs
taskon the EDT afterdelaymilliseconds. Overridable so a subclass can drive the polling from its own clock.Parameters
-
delay: the delay in milliseconds -
task: what to run
-
-