Connect to a reader
Connect your application to a Stripe Terminal reader.
Note
If you haven’t chosen a reader yet, compare the available Terminal readers and choose one that best suits your needs.
Tap to Pay on Android (TTPA) lets users accept in-person contactless payments with compatible NFC-equipped Android devices. TTPA requires the latest version of the Terminal Android SDK. TTPA supports Visa, Mastercard, and American Express contactless cards and NFC-based mobile wallets (Apple Pay, Google Pay, and Samsung Pay). TTPA is an extension to the Terminal Android SDK and enables payments directly in your Android app.
Follow these steps to connect your app to the Tap to Pay reader on a supported Android device:
- Initialize the SDK for TTPA.
- Discover readers using the SDK to confirm device compatibility.
- Connect to a reader using the SDK to accept payments.
- Handle unexpected disconnects to make sure your user can continue to accept payments if the reader disconnects unexpectedly.
If your application runs on a device that doesn’t meet the supported device criteria, the SDK returns a TerminalException that provides additional context in an onFailure callback.
Initialize the SDK
TTPA operates in a dedicated process to make transactions more secure. In this process, a second instance of your Application is created. To avoid any unexpected errors caused by running your code in this process, you can skip initialization in your Application in this process by checking TapToPay..
Discover readers
Use the discoverReaders method to determine hardware support for Tap to Pay on the Android device. discoverReaders verifies the following requirements about the Android device:
- Has a functioning, integrated NFC sensor and ARM-based processor
- Runs Android 13 or later
- Has a keystore with hardware support for ECDH (
FEATURE_version must be 100 or later)HARDWARE_ KEYSTORE - For the non-simulated version of the Tap to Pay reader, the application isn’t debuggable.
Your application must be in the foreground for the Tap to Pay reader service to successfully start.
If your application runs on a device that doesn’t meet the requirements above, the onFailure callback returns with a TerminalException that contains a TerminalErrorCode and additional context. The failures at this stage aren’t actionable by the end user.
You can’t use the non-simulated, production version of the Tap to Pay reader with debuggable applications or with the device’s developer options enabled. To test your integration with the Tap to Pay on Android reader, set TapToPayDiscoveryConfiguration. to true during reader discovery. You must set this value to false in the release version of your application.
To check if a device meets the Tap to Pay hardware and OS requirements at runtime, use the Terminal.supportsReadersOfType function. As part of initializing the Terminal SDK, this function requires your end-user to accept permission requests to access the location and bluetooth. This function takes approximately 10 milliseconds to run on most devices.
Connect to a reader
Note
In version 5. of the Android SDK, you can use the easyConnect method to combine reader discovery and connection into a single API call to simplify integration. See the SDK migration guide for details.
To accept Tap to Pay payments, provide the discovered reader from the previous step to the connectReader method.
connectReader verifies the Android device meets the following requirements:
- It isn’t rooted and device bootloader is locked and unchanged
- It uses Google Mobile Services and has the Google Play Store app installed
- It has a stable connection to the internet
- It runs the unmodified manufacturer provided OS
- The application uses Tap to Pay SDK version 2.20.0 or later
- Developer options are disabled for the non-simulated version of the Tap to Pay reader
If your application runs on a device that doesn’t meet the requirements above, the onFailure callback returns with a TerminalException that contains a TerminalErrorCode and additional context. The end user can take action on some of the failure reasons. For example:
STRIPE_: The user can connect to a stable internet source.API_ CONNECTION_ ERROR TAP_: The user can upgrade their operating system, if an update is available from the device manufacturer.TO_ PAY_ UNSUPPORTED_ ANDROID_ VERSION
You must register your reader to a location upon connection. To do so, create and use a TapToPayConnectionConfiguration with the locationId set to the relevant location ID when connecting.
Handle unexpected disconnects
Unexpected disconnects might occur between your app and the reader. For example, the Tap to Pay reader might unexpectedly disconnect because:
- Android OS terminates the Tap to Pay reader service due to memory constraints.
- The device loses internet connectivity.
There are two ways you can handle this:
Automatically attempt reconnection
You can set autoReconnectOnUnexpectedDisconnect to true to enable the SDK to automatically attempt reconnection when an unexpected disconnection occurs. The SDK defaults to this behavior if you omit this setting. Optionally, you can also implement TapToPayReaderListener for auto reconnect callbacks in your app.
When the SDK automatically attempts reconnection, the following occurs:
- When a disconnect occurs, the SDK automatically attempts to reconnect and notifies you through
onReaderReconnectStarted. Make sure your app announces that the connection was lost and a reconnection is in progress.- You can use the
Cancelableobject to stop the reconnection attempt at any time.
- You can use the
- If the SDK successfully reconnects to the reader, Stripe notifies you through
onReaderReconnectSucceeded. Make sure your app announces that the connection was restored and to continue normal operations. - If the SDK can’t reconnect to the reader, Stripe notifies you through both
onReaderReconnectFailedandTapToPayReaderListener.. Make sure your app announces that an unexpected disconnect occurred.onDisconnect
Handle the disconnect manually
To handle disconnection yourself, you must:
- Set
autoReconnectOnUnexpectedDisconnecttofalseto disable the default auto reconnection. - Implement
TapToPayReaderListenerfor itsonDisconnectcallback.
This allows your app to reconnect to the Tap to Pay reader and, when appropriate, notify the user of what went wrong and how they can enable access to Tap to Pay. End users can resolve certain errors, such as internet connectivity issues.
Caution
If you handle disconnection manually without disabling auto reconnection, it can cause conflicts that break the reader session.
Next steps
You’ve connected your application to the reader. Next, collect your first Stripe Terminal payment.
The BBPOS and Chipper™ name and logo are trademarks or registered trademarks of BBPOS Limited in the United States or other countries. The Verifone® name and logo are either trademarks or registered trademarks of Verifone in the United States and/or other countries. Use of the trademarks doesn’t imply any endorsement by BBPOS or Verifone.