Package-level declarations
Requirements
Tooling
AGP version
>=8.6.0Gradle version
>=8.7
App Permissions
android.Manifest.permission.NFC– the SDK uses the NFC feature of the Android device to communicate with the payment card/mobile wallet. Without this permission the Tap on Phone solution will not work.android.Manifest.permission.VIBRATE– the SDK uses the Vibrate feature of the Android device for the required Haptics and to indicate a card has been read.android.permission.INTERNET– the SDK requires access to internet to communicate to backend services – assumption is that all partner applications will be online so it should not be an additional permission for most partners.android.permission.ACCESS_NETWORK_STATE– ensures that the SDK can communicate before attempting a transaction.
Miscellaneous
Applications should prevent the screen from sleeping while waiting to accept a tap.
Usage
The main entry point is a factory method: MoovSDK.createTerminal. This initializes a terminal instance which ensures a secure environment. This method should be called as early in the application's lifecycle as is practical, as it may take a significant amount of time to complete the device attestation.
Creating an EMV authorization will grab exclusive access to the device's NFC reader, allowing tap of an EMV card.
There are two main paths to accept EMV payments:
Create an authorization via the SDK and create the
transferseparatelyDirectly create a
transferfrom the SDK
For more context on these two options, please see the Moov API documentation.
Initialization
SDK initialization requires MoovSDK.onApplicationCreated to be called in the app's Application.onCreate method. Additionally, MoovSDK.isApplicationProcess should be used to determine whether or not the app should proceed with any initialization logic in its onCreate method.
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// initialize the Moov SDK
MoovSDK.onApplicationCreated(this, logger)
// return if not being called from the main process
if (!MoovSDK.isApplicationProcess()) {
return
}
// proceed to initialize the app
}
}The SDKLogger which must be passed into onApplicationCreated is to enable debugging in the case of failed taps in production. The data passed to this logger will never contain PCI or PII data, so they are safe to share over standard communication channels. When reporting issues with production taps to Moov support, please include the contents of this log.
Terminal configuration lifetime
Terminal configurations expire 48 hours after they are issued. Fetch a fresh configuration from the Moov API rather than caching one indefinitely.
When a configuration has expired, createTerminal returns TerminalCreationResult.TerminalConfigurationExpired. It is the only result that should trigger a refetch and retry: fetch a new configuration from the Moov API and call createTerminal again.
when (val result = MoovSDK.createTerminal(context, terminalConfig)) {
is TerminalCreationResult.Created -> { /* use result.terminal */ }
is TerminalCreationResult.TerminalConfigurationExpired -> {
val fresh = fetchTerminalConfigurationFromYourBackend()
MoovSDK.createTerminal(context, fresh)
}
else -> { /* handle other failures */ }
}To refresh before that happens, read Terminal.configurationExpiresAt. It reports when the configuration backing the terminal expires, so the app can refetch while the terminal is idle rather than discovering the expiry mid-transaction. It is null for sandbox terminals, whose configurations carry no expiry.
val expiresAt = terminal.configurationExpiresAt
if (expiresAt != null && Instant.now().isAfter(expiresAt.minus(Duration.ofHours(2)))) {
// refresh during a quiet moment rather than with a customer waiting
}A terminal whose configuration expires while the app is running fails at authorization time with TapAuthorizationError.ConfigurationExpired, from both createTapAuthorization and createTapTransfer. The flow emits it and completes without starting a reader session, so no card is read. Recovery is the same as at creation, and the terminal cannot be reused: dispose it, create a new one from a fresh configuration, and authorize again.
is TapAuthorizationError.ConfigurationExpired -> {
terminal.dispose()
val fresh = fetchTerminalConfigurationFromYourBackend()
// MoovSDK.createTerminal(context, fresh), then retry the authorization
}Because recreating a terminal runs device attestation, handling this event costs the merchant a visible delay with a customer waiting. Treat it as the backstop and refresh proactively.
The SDK holds the configuration in memory only. After process death, or after a long period in the background, call createTerminal again rather than assuming the SDK still holds a terminal.
Examples
External transfer creation
This method accepts the EMV tap, authorizes the transaction with the card network, and returns a token which can be passed into the createTransfer API.
val terminalConfig = fetchTerminalConfig() // fetch the terminal config from the Moov API
val terminal = MoovSDK.createTerminal(
applicationContext,
terminalConfig,
)
val authorization = terminal.createTapAuthorization(
TapAuthorizationParams(
tapAmount = TapAmount(
amount = 100uL,
currency = Currency.getInstance("USD"),
),
customerAccountId = MID("962aa592-5993-49d6-ae54-d6d6ab917c66"),
)) {
LOG.d(TAG, "EMV message received: $it")
}
}
// now, create the transfer externally using the authorization as the sourceTo attach a tip and/or surcharge breakdown, populate TapAmount.tip and/or TapAmount.surcharge. Both components are descriptive — they must already be included in amount, and amount must be strictly greater than tip + surcharge:
TapAmount(
amount = 1150uL, // caller-computed total: 1000 base + 100 tip + 50 surcharge
currency = Currency.getInstance("USD"),
tip = 100uL,
surcharge = 50uL,
)Surcharge is gated by the merchant's surchargeEnabled capability.
Direct transfer creation
This method accepts the EMV tap, authorizes the transaction with the card network, creates a transfer on the Moov platform, and returns the transfer ID.
val terminalConfig = fetchTerminalConfig() // fetch the terminal config from the Moov API
val terminal = MoovSDK.createTerminal(
applicationContext,
terminalConfig,
)
val transferID = terminal.createTapTransfer(
CreateTapTransferParams(
tapAuthorizationParams = TapAuthorizationParams(
tapAmount = TapAmount(
amount = 100uL,
currency = Currency.getInstance("USD"),
),
customerAccountId = MID("962aa592-5993-49d6-ae54-d6d6ab917c66"),
),
partnerAccountId = MID("fd35bc72-fa52-4fef-a0f5-f99fa1280aeb"),
destinationPaymentMethodId = MID("19a76ccb-be73-4394-a9ca-701c0a20fd8a"),
description = "A fancy widget",
)) {
LOG.d(TAG, "EMV message received: $it")
}
}