Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class TapToPay
- Object
- PaymentTerminal
- TapToPay
Takes contactless card payments with the phone itself: Tap to Pay on iPhone and Tap to Pay on Android, over the Stripe Terminal SDK.
The customer holds their card or wallet to the back of the phone; there is no reader hardware. Neither OS lets an app read a payment card directly, so this always goes through Stripe, whose SDK carries the certified card-reading component and returns only the outcome.
What your server does
- Issues connection tokens (
POST /v1/terminal/connection_tokens), which the app fetches through aConnectionTokenProvider. - Creates a PaymentIntent for each sale with
payment_method_types[]=card_presentand hands its client secret to the app as the request’sTerminalPaymentRequest.getProviderReference(). - Confirms the PaymentIntent succeeded before fulfilling the order.
// From your server; placeholders here.
String clientSecretFromServer = "pi_123_secret_456";
ConnectionTokenProvider tokens = () -> {
AsyncResource<String> token = new AsyncResource<>();
token.complete("pst_test_connection_token");
return token;
};
if (TapToPay.isSupported()) {
TapToPay tap = new TapToPay(tokens, "tml_FDOtHwxAAdIJOh");
tap.setMerchantDisplayName("Corner Bakery");
TerminalPaymentRequest req = new TerminalPaymentRequest(450, "USD")
.setProviderReference(clientSecretFromServer);
tap.collect(req).ready(result -> {
if (result.isApproved()) {
// tell the server to verify result.getTransactionId()
}
});
}Platform requirements
- iOS: iPhone XS or newer on iOS 16.4 or later, and the Tap to Pay on iPhone entitlement, which Apple grants on request to apps of supported payment providers. The build adds the entitlement to the app; the provisioning profile must carry it too.
- Android: Android 8 (API 26) or later with NFC, not rooted, with Google Play services. Builds that use this package get a minimum SDK of 26.
- Simulator: a simulated phone that asks your token provider for a
token, then approves. An amount ending in
01(such as 1001) is declined, and one ending in02fails, so both paths can be tried.
Referencing this package is what adds the Stripe Terminal SDK to an Android or iOS build; an app that does not use it carries none of it.
Constructors
public TapToPay(ConnectionTokenProvider tokens, String locationId) |
Methods
public static boolean isSupported() | True when this device can take Tap to Pay payments: the build includes the SDK and the hardware and OS are supported. |
public void setMerchantDisplayName(String merchantDisplayName) | The name shown on the payment sheet. |
public void setSimulated(boolean simulated) | Uses Stripe’s simulated reader instead of the phone’s NFC, so a test mode integration can run end to end on any device. |
public boolean supports(TerminalOperation operation) | Takes a payment. |
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. |
Inherited methods
Constructor details
TapToPay
public TapToPay(ConnectionTokenProvider tokens, String locationId)Parameters
tokensConnectionTokenProvider- fetches connection tokens from your server
locationIdString- the Stripe location (
tml_...) the phone takes payments for
Method details
isSupported
public static boolean isSupported()Returns
collect(TerminalPaymentRequest) can run heresetMerchantDisplayName
public void setMerchantDisplayName(String merchantDisplayName)Parameters
merchantDisplayNameString- the name, or null for the default
setSimulated
public void setSimulated(boolean simulated)Parameters
simulatedboolean- true for the simulated reader
supports
public boolean supports(TerminalOperation operation)Takes a payment. The request needs the PaymentIntent’s client secret
as its TerminalPaymentRequest.getProviderReference().
The first payment also connects the phone as a reader, which can download its configuration and take a while; on iOS the merchant is asked to accept Apple’s terms the first time.
Parameters
operationTerminalOperation- the operation to ask about
Returns
capture_method=manual) and carried out with its
secret key, so the app never asks for one here.collect
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.