Cards SDK for Android¶
The Cards SDK is a solution to ease the integration with the Alviere services.
Features¶
- Card Issuance
- Digital Wallet
- Incentives
Requirements¶
- Android Studio Hedgehog or above
- Android 6.0 (API level 23) or above
- Java 11+
Installation¶
Maven Central¶
1. Add Maven Central to project repositories
repositories {
// ...
mavenCentral()
}
2. Add SDK dependency to module's build.gradle file using the latest version.
dependencies {
// ...
implementation 'com.alviere.android:cards:X.Y.Z'
}
Manual¶
1. Get the latest version of Cards SDK provided by Alviere and add the files to your .m2 path location. Depending on your operation system, these are the default paths.
- Windows:
C:\Users\<User_Name>\.m2
- Linux:
/home/<User_Name>/.m2
- Mac:
/Users/<user_name>/.m2
2. Add a maven path to include the .m2 path location in project repositories.
Add the new path before mavenCentral()
to respect fetch order.
repositories {
// ...
maven { url "file:/path/to/repo/m2repository/" } // Or use mavenLocal() for default path.
mavenCentral()
}
3. Add SDK dependency to module's build.gradle file using the version provided by Alviere.
dependencies {
// ...
implementation 'com.alviere.android:cards:X.Y.Z'
}
Java Version Support¶
Make sure you have enabled Java 11 language feature support. To do so, guarantee that the following configurations are on the module's build.gradle file.
android {
// ...
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}
Usage¶
On your android application class, setup Alviere Initialization.
class AndroidApplication : Application() {
override fun onCreate() {
super.onCreate()
Alviere.init(this)
}
}
Card Issuance¶
This section describes how to issue and manage cards with the Alviere platform. To start, get the CardsSdk service interface instance or use with Dependency Injection.
private val cardsService = CardsSdk.service
Coroutine Usage¶
Every SDK entry function without UI is a suspend function to run inside a kotlin coroutine.
Internal code will run with withContext(Dispatchers.IO)
and will return an object of type Response<T>
.
val response = cardsService.request(...)
when (response) {
is Response.Success -> { response.data }
is Response.Error -> { response.metadata }
}
Callback Usage¶
For every suspend function there is a callback function. UI functions will always work only thru callbacks and callbacks will always run on the main thread. Callbacks Source
Create Card¶
To create a new issued card, use the Cards SDK service method cardsService.createCard
. Pass
the session_token
, the wallet_uuid
and the IssueCardRequest
model.
val model = IssueCardRequest(...)
cardsService.createCard(
sessionToken = session_token,
walletUuid = wallet_uuid,
data = model,
)
The result of this action will return the newly created IssuedCardDetailsModel
on
Response.Success
and any errors will be returned on Response.Error
.
Create Non-Reloadable Prepaid Card¶
To create a new non-reloadable prepaid card, use the Cards SDK service method
cardsService.createNonReloadablePrepaidCard
. Pass the session_token
, the account_uuid
,
and the NonReloadablePrepaidCardRequest
model.
val model = NonReloadablePrepaidCardRequest(...)
cardsService.createCard(
sessionToken = session_token,
accountUuid = account_uuid,
data = model,
)
The result of this action will return the newly created IssuedCardDetailsModel
on
Response.Success
and any errors will be returned on Response.Error
.
List Cards¶
To get a list of cards from a wallet, use the Cards SDK service method cardsService.listCards
. Pass
the session_token
, the wallet_uuid
and the limit
/offset
, optionally.
cardsService.listCards(
sessionToken = session_token,
walletUuid = wallet_uuid,
)
The result of this action will return the user's wallet cards List<IssuedCardDetailsModel>
on
Response.Success
and any errors will be returned on Response.Error
.
Get Card¶
To get a card, use the Cards SDK service method cardsService.getCard
. Pass
the session_token
, the wallet_uuid
and the card_uuid
.
cardsService.getCard(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
)
The result of this action will return the issued card of a wallet IssuedCardDetailsModel
on
Response.Success
and any errors will be returned on Response.Error
.
Get Card Image¶
To get a card image, use the Cards SDK service method cardsService.getCardImage
. Pass
the session_token
, the wallet_uuid
and the card_uuid
.
cardsService.getCardImage(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
)
The result of this action will return the issued card image Android Bitmap
on
Response.Success
and any errors will be returned on Response.Error
.
Get Card Sensitive Data¶
To get a card sensitive data, use the Cards SDK service method cardsService.getCardSensitiveData
. Pass
the session_token
, the wallet_uuid
and the card_uuid
.
cardsService.getCardSensitiveData(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
)
The result of this action will return the issued card sensitive data IssuedCardSensitiveDataModel
on
Response.Success
and any errors will be returned on Response.Error
.
Update Card¶
To update a card, use the Cards SDK service method cardsService.updateCard
. Pass
the session_token
, the wallet_uuid
, the card_uuid
and the CardUpdateRequest
model.
val model = CardUpdateRequest(...)
cardsService.updateCard(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
data = model,
)
The result of this action will return the updated card IssuedCardDetailsModel
on
Response.Success
and any errors will be returned on Response.Error
.
Activate Card¶
To activate a card, use the Cards SDK service method cardsService.activateCard
. Pass
the session_token
, the wallet_uuid
, the card_uuid
and the ActivateCardRequest
model.
val model = ActivateCardRequest(...)
cardsService.activateCard(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
data = model,
)
The result of this action will return on
Response.Success
and any errors will be returned on Response.Error
.
Freeze Card¶
To freeze a card, use the Cards SDK service method cardsService.freezeCard
. Pass
the session_token
, the wallet_uuid
and the card_uuid
.
cardsService.freezeCard(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
)
The result of this action will return on
Response.Success
and any errors will be returned on Response.Error
.
Unfreeze Card¶
To unfreeze a card, use the Cards SDK service method cardsService.unfreezeCard
. Pass
the session_token
, the wallet_uuid
and the card_uuid
.
cardsService.unfreezeCard(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
)
The result of this action will return on
Response.Success
and any errors will be returned on Response.Error
.
Cancel Card¶
To cancel a card, use the Cards SDK service method cardsService.cancelCard
. Pass
the session_token
, the wallet_uuid
and the card_uuid
.
cardsService.cancelCard(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
)
The result of this action will return on
Response.Success
and any errors will be returned on Response.Error
.
Set Card PIN¶
To set a card PIN, use the Cards SDK service method cardsService.setCardPin
. Pass
the session_token
, the card_uuid
and the CardPinRequest
model.
val model = CardPinRequest(...)
cardsService.cancelCard(
sessionToken = session_token,
cardUuid = card_uuid,
data = model,
)
The result of this action will return on
Response.Success
and any errors will be returned on Response.Error
.
Reissue or Replace Card¶
To reissue or replace card, use the Cards SDK service method cardsService.reissueReplaceCard
. Pass
the session_token
, the card_uuid
and the ReissueReplaceCardRequest
model.
val model = CardPinRequest(...)
cardsService.reissueReplaceCard(
sessionToken = session_token,
cardUuid = card_uuid,
data = model,
)
The result of this action will return on
Response.Success
and any errors will be returned on Response.Error
.
Digital Wallet¶
This section outlines the integration with Alviere to manage digital wallets of Google and Samsung. To start, get the CardsSdk service interface instance or use with Dependency Injection.
private val cardsService = CardsSdk.service
Coroutine Usage¶
Every SDK entry function without UI is a suspend function to run inside a kotlin coroutine.
Internal code will run with withContext(Dispatchers.IO)
and will return an object of type Response<T>
.
val response = cardsService.request(...)
when (response) {
is Response.Success -> { response.data }
is Response.Error -> { response.metadata }
}
Callback Usage¶
For every suspend function there is a callback function. UI functions will always work only thru callbacks and callbacks will always run on the main thread. Callbacks Source
Add Card¶
Google Digital Wallet¶
The Add card to Google digital wallet is implemented through requesting a provisioning request from Alviere services and then receiving a result from Google SDK's on onActivityResult. This solution is limited and deprecated but we don't have control over this design by Google.
To get started, set the Cards SDK event listener.
CardsSdk.setEventListener(addCardDigitalWalletSdkCallback)
Check Google digital wallet support¶
Before using this feature, we should check if Google digital wallet is supported by checking if is the default payment method and get the active wallet ID and stable hardware ID needed to prepare a Provisioning Request by using:
private val googleWalletSupport: GoogleWalletSupport by lazy {
cardsService.getGoogleWalletSupport(requireActivity())
}
googleWalletSupport.getGoogleWalletStatusInfo(object : GoogleWalletStatusInfoListener {
override fun onGetStatusInfo(statusInfo: GoogleWalletStatusInfo) {
when (statusInfo.status) {
GoogleWalletStatus.DEFAULT_WALLET -> {
walletId = statusInfo.walletId
hardwareId = statusInfo.hardwareId
}
GoogleWalletStatus.NOT_DEFAULT_WALLET -> { ... }
GoogleWalletStatus.MISSING_INFO -> { ... }
GoogleWalletStatus.NOT_SUPPORTED -> { ... }
}
}
})
Check Google digital wallet card token status¶
Before showing a UI button to add a card to Google digital wallet, we should check the previews wallet support and if card is already added to this wallet by using:
private val googleWalletSupport: GoogleWalletSupport by lazy {
cardsService.getGoogleWalletSupport(requireActivity())
}
googleWalletSupport.getCardTokenStatus(
last4Digits = last_four_digits
cardBrand = CardBrandModel.MASTERCARD,
cardTokenStatusListener = object : CardTokenStatusListener {
override fun onGetStatus(isTokenized: Boolean) {
// ...
}
}
)
Add Card - Provisioning and Google SDK result¶
To add a card to Google digital wallet, use the Cards SDK service method cardsService.addCardDigitalWalletGoogle. Pass
the activity_for_result
, the session_token
, the wallet_uuid
, the card_uuid
, and the AddCardGoogleRequest
model.
Add cardsService.handleAddCardDigitalWalletGoogle
to activity onActivityResult
.
val model = AddCardGoogleRequest(...)
cardsService.addCardDigitalWalletGoogle(
activity = activity_for_result,
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
data = model,
)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
cardsService.handleAddCardDigitalWalletGoogle(requestCode, resultCode)
}
The result of this action will return on onProvisioningRequestGoogleSuccess()
after receiving a
provisioning request from Alviere services and onAddCardGoogleSuccess()
if success adding a card
to Google digital wallet and any errors will be returned on
onEvent(event: String, metadata: Map<String, String>?)
, both from the callback.
Samsung Digital Wallet¶
The Add card to Samsung digital wallet is implemented through Activity or through the navigation controller. To get started, set the Cards SDK event listener.
CardsSdk.setEventListener(addCardDigitalWalletSdkCallback)
Check Samsung wallet support¶
Before adding a card to Samsung wallet, we can optionally check if Samsung wallet is supported by using
private val samsungWalletSupport: SamsungWalletSupport by lazy {
cardsService.getSamsungWalletSupport(context, samsung_service_id)
}
samsungWalletSupport.checkSamsungWalletSupport(object : SupportStatusListener {
override fun onGetStatus(supported: Boolean) {
// ...
}
})
Compose¶
To start using this feature with Compose, wrap AddCardDigitalWalletSamsungScreen inside a typical
navigation composable, pass the session_token
, the wallet_uuid
,the card_uuid
,
the CardBrandModel
, the samsung_service_id
assigned by the Samsung Pay Developers portal
and and the action to close the view.
AddCardDigitalWalletSamsungScreen(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
cardBrand = CardBrandModel.MASTERCARD,
samsungServiceId = samsung_service_id,
onCloseAction = navController::navigateUp,
)
Compose From Activity¶
To start using this feature with Compose from an activity, create a new activity and set the composable content
AddCardDigitalWalletSamsungScreen inside onCreate, pass the session_token
, the wallet_uuid
,the card_uuid
,
the CardBrandModel
, the samsung_service_id
assigned by the Samsung Pay Developers portal
and and the action to close the view.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
AddCardDigitalWalletSamsungScreen(
sessionToken = session_token,
walletUuid = wallet_uuid,
cardUuid = card_uuid,
cardBrand = CardBrandModel.MASTERCARD,
samsungServiceId = samsung_service_id,
onCloseAction = ::finish,
)
}
}
}
The result of this action will return on
onAddCardSamsungSuccess()
and any errors will be returned on
onEvent(event: String, metadata: Map<String, String>?)
, both from the callback.
Incentives¶
This section describes how to manage incentives with the Alviere platform. To start, get the CardsSdk service interface instance or use with Dependency Injection.
private val cardsService = CardsSdk.service
Coroutine Usage¶
Every SDK entry function without UI is a suspend function to run inside a kotlin coroutine.
Internal code will run with withContext(Dispatchers.IO)
and will return an object of type Response<T>
.
val response = cardsService.request(...)
when (response) {
is Response.Success -> { response.data }
is Response.Error -> { response.metadata }
}
Callback Usage¶
For every suspend function there is a callback function. UI functions will always work only thru callbacks and callbacks will always run on the main thread. Callbacks Source
List Incentive Rules¶
To get a list of incentive rules, use the Cards SDK service method cardsService.listIncentiveRules
. Pass
the session_token
and the limit
/offset
/incentiveScope
/incentiveType
, optionally.
cardsService.listIncentiveRules(
sessionToken = session_token,
)
The result of this action will return the incentive rules List<IncentiveRuleDetailsModel>
on
Response.Success
and any errors will be returned on Response.Error
.
Get Incentive Rule¶
To get a incentive rule, use the Cards SDK service method cardsService.getIncentiveRule
. Pass
the session_token
and the rule_uuid
.
cardsService.getIncentiveRule(
sessionToken = session_token,
ruleUuid = rule_uuid,
)
The result of this action will return the incentive rule IncentiveRuleDetailsModel
on
Response.Success
and any errors will be returned on Response.Error
.
Customization Object¶
To start, create a CardsCustomize
object and set it by CardsSdk.setCustomize.
This object has a default customizations for every UI feature of the SDK. Navigate through the object source code to check all possible configurations and change any value.
val customize = CardsCustomize(
digitalWalletCustomize = DigitalWalletCustomize(
samsungAddCardMessageRes = R.string.message_samsung_add_card,
samsungMessageTextStyle = alviereTitleLRegular.copy(
fontSize = 20.sp,
)
),
)
CardsSdk.setCustomize(customize)
Text and Localization¶
The CardsCustomize
by default uses String Resources from strings.xml.
This allows string keys to be override directly in your string resources file and new languages can be added.
Currently, the SDK only supports english.
Fonts¶
The CardsCustomize
uses Compose TextStyle
for every text configuration and this includes font family.
Currently, the default value is FontFamily.SansSerif
.
Customization Theme¶
The Cards SDK uses a color schema CardsSdkColors
to customize the Colors of every UI feature
and this allows a more robust implementation on top of MaterialTheme
, including light and dark mode.
By default, the Cards SDK uses a default light mode color schema, but you can configure dark mode,
or use a custom color schema CardsSdkColors
as explained below.
@Composable
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable () -> Unit,
) {
val colorScheme = if (darkTheme) darkScheme else lightScheme
val cardsSdkColors = if (darkTheme) darkCardsSdkColorPalette else lightCardsSdkColorPalette
CompositionLocalProvider(
LocalCardsSdkColorPalette provides cardsSdkColors,
) {
MaterialTheme(
colorScheme = colorScheme,
content = content,
)
}
}
The lightCardsSdkColorPalette
and darkCardsSdkColorPalette
can be recreated by
using the same functions and changing the default colors.
val cardsSdkColors = if (darkTheme) {
CardsSdkColors(
digitalWalletTokens = digitalWalletDarkColors(
background = Color.Black,
),
)
} else {
CardsSdkColors(
digitalWalletTokens = digitalWalletLightColors(
background = Color.Black,
),
)
}