Class 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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Asks the terminal to abandon the operation in progress.collect(TerminalPaymentRequest request) Takes a payment: a sale, or a pre-authorization when the request says so.static booleanTrue when this device can take Tap to Pay payments: the build includes the SDK and the hardware and OS are supported.voidsetMerchantDisplayName(String merchantDisplayName) The name shown on the payment sheet.voidsetSimulated(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.booleansupports(TerminalOperation operation) Takes a payment.Methods inherited from class PaymentTerminal
capture, failed, lookup, missingCapability, reconcile, refund, reverse, unsupported
-
Constructor Details
-
TapToPay
Parameters
-
tokens: fetches connection tokens from your server -
locationId: the Stripe location (tml_...) the phone takes payments for
-
-
-
Method Details
-
isSupported
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. False in an app whose build was not given the SDK, and on platforms with none (desktop, web).
Returns
whether
collect(TerminalPaymentRequest)can run here -
setMerchantDisplayName
The name shown on the payment sheet. Defaults to the name on the Stripe account.
Parameters
merchantDisplayName: the name, or null for the default
-
setSimulated
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. Requires a test mode PaymentIntent.
Parameters
simulated: true for the simulated reader
-
supports
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
request: what to charge
Returns
the outcome, delivered on the EDT Sales only. A pre-authorization, capture, refund or reversal is decided by the PaymentIntent your server creates (
capture_method=manual) and carried out with its secret key, so the app never asks for one here.- 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
-