Getting Started on Android
Introduction
The Software Development Kit for Android is a library with a simple set of tools that allow you to easily communicate with the Paysafe Wallet API. The SDK is written in Kotlin 1.9 using coroutines but Java is fully supported as well, using callback functions.
Requirements
- Android 7 (API Level 24) and above
- Android Gradle Plugin 7.4 and above
- Gradle 7.5 and above
- AndroidX
Integration
Update root-level settings.gradle.kts
file to include the Paysafe Maven repository:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://repository.paysafe.com/") }
}
}
Then add the dependency in your module-level build.gradle.kts
:
dependencies {
implementation("com.paysafe:paysafe-wallet-saas-android:<latest-version>")
}
Usage
All wallet operations are provided via the Wallet
singleton:
val wallet = Wallet.getInstance()
Configure the SDK
The SDK needs to be configured before first use. The configuration should be performed only once in the lifetime of the
application by calling the configure
method of the Wallet
instance. Mind that configure
is a suspend
function
that has to be called inside a coroutine scope.
lifecycleScope.launch {
// issue a <config-token> from your backend server
val configureResult = wallet.configure(
SdkConfiguration(
configToken = "<config-token>", /* the config token you have just issued */
baseUrl = "https://api.paysafe.com", /* or your own server, which proxies the requests to the Paysafe Wallet API */
context = this@MainActivity /* the activity context */
)
)
// use configureResult.digitalFingerprint for the authentication step
}
The configuration token is issued from your backend server. The steps to generate it are explained in SDK Configuration.
Authenticate User
To ensure secure access to customer data by the SDK, it is necessary to provide a customer token. Customer tokens
exclusively permit access to resources linked to the specific customer for whom the token was generated. Call the
authenticate
method of the Wallet
instance to set the customer token:
// issue a <customer-token> from your backend server, passing configureResult.digitalFingerprint
wallet.authenticate(AuthenticationConfiguration("<customer-token>"))
The customer token is issued from your backend server passing the digitalFingerprint
value from the configuration result.
More details on getting the customer token are available in SDK User Authentication.
Wallet Operations
If the Configure SDK and the Authenticate operations were successful, you can start using the SDK for wallet operations.
try {
val profile = wallet.getProfileService().getProfile(emptyList())
Log.d(TAG, profile.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
Java Support
Java Android applications are fully supported. Each asynchronous operation has a version with
suffix Async
which takes the same arguments with two additional: cancellation signal to allow cancellation
and a callback upon completion. All Async
functions complete on the main thread.