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
Contact Paysafe for latest artifacts.
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 */
apiEnvironment = ApiEnvironment.Production, /* set to Production or Test to direct API calls to the appropriate environment */
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.
The available ApiEnvironment
values and the corresponding base urls are:
Production
: https://api.paysafe.com/Test
: https://api.test.paysafe.com/
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())
}
SDK Configuration
wallet.configure(
SdkConfiguration(
configToken = "<config-token>",
apiEnvironment = ApiEnvironment.Production,
context = this@MainActivity,
)
)
You may also want to provide a customThemeResId
to the SdkConfiguration
for achieving a native look when the SDK opens a screen provided by Paysafe.
Below you can find out how.
UI Theme Configuration
The appearance of components in the SDK is fully customizable. A built-in design system provides global customization options, allowing you to override individual semantic colors to update all components using those colors. For more details, refer to UI Customization.
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.