Display card metadata
Overview
Flow
SDK
fun getCachedCardMetadata(d1Task: D1Task, cardID: String) { // cardID: Digitised card ID
val d1PayWallet : D1PayWallet = d1Task.d1PayWallet
d1PayWallet.getCachedCardMetadata(cardID, object : D1Task.Callback<CardMetadata?> {
override fun onSuccess(data: CardMetadata?) {
data?.let {
val last4: String = it.last4Pan
val scheme: Scheme = it.scheme
// If the cached card metadata is not synchronized with the D1 backend,
// this API may not return `state`, `expiryDate`, or card art.
val expiryDate: String = it.expiryDate
val state: State = it.state
getCardAssets(it)
}
}
override fun onError(exception: D1Exception) {
// Refer to D1 SDK Integration – Error Management section
}
})
}
fun getCardAssets(cardMetadata: CardMetadata) {
cardMetadata.getAssetList(object : D1Task.Callback<List<CardAsset>> {
override fun onSuccess(data: List<CardAsset>) {
// Update the UI based on the card asset.
}
override fun onError(exception: D1Exception) {
// If card art is not available in the local cache,
// `cardMetadata.getAssetList()` returns `D1Exception.ErrorCode.ERROR_D1PAY_NO_CARD_ART_CACHE`.
// The issuer application can use this error code to display a local template image
// based on the payment network (`VISA`, `MASTERCARD`).
if (exception.errorCode == D1Exception.ErrorCode.ERROR_D1PAY_NO_CARD_ART_CACHE) {
if (cardMetadata.scheme == Scheme.MASTERCARD) {
// Update UI using MASTERCARD template image
} else if (cardMetadata.scheme == Scheme.VISA) {
// Update UI using VISA template image
}
}
}
})
}Last updated
Was this helpful?