TP-70453 | expose vpa of primary account (#11372)
This commit is contained in:
@@ -40,6 +40,7 @@ import com.navi.pay.db.NaviPayAppEncryptedDatabase
|
||||
import com.navi.pay.utils.KEY_CUSTOMER_STATUS
|
||||
import com.navi.pay.utils.KEY_DEVICE_FINGERPRINT
|
||||
import com.navi.pay.utils.KEY_UPI_LITE_ACTIVE_ACCOUNT_INFO
|
||||
import com.navi.pay.utils.KEY_UPI_PRIMARY_ACCOUNT_VPA
|
||||
import com.navi.pay.utils.LITMUS_EXPERIMENT_NAVIPAY_ONECLICK
|
||||
import com.navi.pay.utils.RUPEE_SYMBOL
|
||||
import com.navi.pay.utils.getFormattedAmountWithDecimal
|
||||
@@ -316,4 +317,16 @@ constructor(
|
||||
"$RUPEE_SYMBOL${liteAccountInfo.balance.getFormattedAmountWithDecimal()}"
|
||||
else EMPTY
|
||||
}
|
||||
|
||||
fun getVpaOfPrimaryAccount(): String {
|
||||
val vpaOfPrimaryAccount =
|
||||
sharedPreferenceRepository
|
||||
.get()
|
||||
.getStringValueOnSameThread(
|
||||
key = KEY_UPI_PRIMARY_ACCOUNT_VPA,
|
||||
defValue = EMPTY,
|
||||
encrypt = true
|
||||
)
|
||||
return vpaOfPrimaryAccount
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,25 +7,43 @@
|
||||
|
||||
package com.navi.pay.common.usecase
|
||||
|
||||
import com.navi.base.utils.EMPTY
|
||||
import com.navi.pay.R
|
||||
import com.navi.pay.common.repository.SharedPreferenceRepository
|
||||
import com.navi.pay.onboarding.account.common.model.view.AccountEntity
|
||||
import com.navi.pay.onboarding.account.common.model.view.AccountStatus
|
||||
import com.navi.pay.onboarding.account.common.model.view.VpaStatus
|
||||
import com.navi.pay.onboarding.account.common.repository.AccountsRepository
|
||||
import com.navi.pay.onboarding.account.detail.model.view.LinkedAccountEntity
|
||||
import com.navi.pay.utils.KEY_UPI_PRIMARY_ACCOUNT_VPA
|
||||
import com.navi.pay.utils.getAccountTypeFormattedValue
|
||||
import com.navi.pay.utils.getMaskedAccountNumber
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
class LinkedAccountsUseCase
|
||||
@Inject
|
||||
constructor(private val accountsRepository: AccountsRepository) {
|
||||
|
||||
constructor(
|
||||
private val accountsRepository: AccountsRepository,
|
||||
private val sharedPreferenceRepository: SharedPreferenceRepository
|
||||
) {
|
||||
suspend fun execute(): Flow<List<LinkedAccountEntity>> {
|
||||
val activeAccountsAsFlow =
|
||||
accountsRepository.getAllAccountByStatusAsFlow(status = AccountStatus.ACTIVE)
|
||||
|
||||
val vpaOfPrimaryAccount =
|
||||
getPrimaryAccountVpa(activeAccounts = activeAccountsAsFlow.first())
|
||||
|
||||
if (vpaOfPrimaryAccount.isNotEmpty()) {
|
||||
sharedPreferenceRepository.saveStringValueSynchronously(
|
||||
key = KEY_UPI_PRIMARY_ACCOUNT_VPA,
|
||||
value = vpaOfPrimaryAccount,
|
||||
encrypt = true
|
||||
)
|
||||
}
|
||||
|
||||
return activeAccountsAsFlow.map { activeAccounts ->
|
||||
val buidMappedVpaEntities =
|
||||
accountsRepository.getBuidMappedVpaEntitiesByStatus(
|
||||
@@ -65,4 +83,15 @@ constructor(private val accountsRepository: AccountsRepository) {
|
||||
.sortedBy { !it.isAccountPrimary }
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun getPrimaryAccountVpa(activeAccounts: List<AccountEntity>): String {
|
||||
return activeAccounts
|
||||
.firstOrNull { it.isAccountPrimary }
|
||||
?.let { primaryAccount ->
|
||||
accountsRepository
|
||||
.getVpaEntityByBuid(buid = primaryAccount.bankAccountUniqueId)
|
||||
?.takeIf { it.status == VpaStatus.ACTIVE && it.isVpaPrimary }
|
||||
?.vpa ?: EMPTY
|
||||
} ?: EMPTY
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,9 @@
|
||||
package com.navi.pay.common.usecase
|
||||
|
||||
import androidx.room.withTransaction
|
||||
import com.navi.base.utils.EMPTY
|
||||
import com.navi.common.network.models.isSuccess
|
||||
import com.navi.pay.common.repository.SharedPreferenceRepository
|
||||
import com.navi.pay.common.sync.model.view.SyncEntity
|
||||
import com.navi.pay.common.sync.repository.SyncRepository
|
||||
import com.navi.pay.common.utils.DeviceInfoProvider
|
||||
@@ -25,6 +27,7 @@ import com.navi.pay.onboarding.account.common.repository.AccountsRepository
|
||||
import com.navi.pay.onboarding.account.linked.model.network.LinkedAccountItemResponse
|
||||
import com.navi.pay.onboarding.account.linked.model.network.LinkedAccountsRequest
|
||||
import com.navi.pay.onboarding.home.VpaQRCodeManager
|
||||
import com.navi.pay.utils.KEY_UPI_PRIMARY_ACCOUNT_VPA
|
||||
import com.navi.pay.utils.LINKED_ACCOUNTS_IN_DB_REFRESH_MIN_TIMESTAMP
|
||||
import com.navi.pay.utils.NAVI_PAY_SYNC_TABLE_LINKED_ACCOUNTS_KEY
|
||||
import com.navi.pay.utils.parallelMap
|
||||
@@ -43,7 +46,8 @@ constructor(
|
||||
private val bankRepository: BankRepository,
|
||||
private val vpaQRCodeManager: VpaQRCodeManager,
|
||||
private val syncRepository: SyncRepository,
|
||||
private val naviPayAppEncryptedDatabase: NaviPayAppEncryptedDatabase
|
||||
private val naviPayAppEncryptedDatabase: NaviPayAppEncryptedDatabase,
|
||||
private val sharedPreferenceRepository: SharedPreferenceRepository
|
||||
) {
|
||||
|
||||
suspend fun execute(skipLastSyncedTimestampCheck: Boolean = true) {
|
||||
@@ -169,12 +173,34 @@ constructor(
|
||||
|
||||
accountEntities.add(accountEntity)
|
||||
vpaEntities.addAll(vpaEntityList)
|
||||
checkAndUpdateVpaOfPrimaryAccount(
|
||||
accountEntity = accountEntity,
|
||||
vpaEntityList = vpaEntityList
|
||||
)
|
||||
}
|
||||
|
||||
accountsRepository.insertAllAccountEntity(accountEntities = accountEntities)
|
||||
accountsRepository.insertAllVpaEntity(vpaEntities = vpaEntities)
|
||||
}
|
||||
|
||||
private suspend fun checkAndUpdateVpaOfPrimaryAccount(
|
||||
accountEntity: AccountEntity,
|
||||
vpaEntityList: List<VpaEntity>
|
||||
) {
|
||||
if (accountEntity.isAccountPrimary) {
|
||||
val primaryVpa =
|
||||
vpaEntityList.firstOrNull { it.isVpaPrimary && it.status == VpaStatus.ACTIVE }?.vpa
|
||||
?: vpaEntityList.getOrNull(0)?.vpa
|
||||
?: EMPTY
|
||||
|
||||
sharedPreferenceRepository.saveStringValueSynchronously(
|
||||
key = KEY_UPI_PRIMARY_ACCOUNT_VPA,
|
||||
value = primaryVpa,
|
||||
encrypt = true
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun prepareVpaQRCodes(linkedAccountsItemResponse: List<LinkedAccountItemResponse>) {
|
||||
linkedAccountsItemResponse.forEach { linkedAccountItemResponse ->
|
||||
val primaryVpa =
|
||||
|
||||
@@ -74,6 +74,7 @@ const val KEY_IS_FIRST_TRANSACTION_SUCCESSFUL = "naviPayIsFirstTransactionSucces
|
||||
const val KEY_DB_ENCRYPTION = "naviPayKeyDbEncryption"
|
||||
const val KEY_UPI_LITE_ACTIVE = "upiLiteActive"
|
||||
const val KEY_UPI_LITE_NON_ACTIVE_ACCOUNT_PRESENT = "upiLiteNonActiveAccount"
|
||||
const val KEY_UPI_PRIMARY_ACCOUNT_VPA = "upiPrimaryAccountVpa"
|
||||
|
||||
val NAVI_PAY_ENCRYPT_SHARED_PREF_DATA_KEYS =
|
||||
listOf(
|
||||
@@ -85,7 +86,9 @@ val NAVI_PAY_ENCRYPT_SHARED_PREF_DATA_KEYS =
|
||||
KEY_PACKAGE_NAME,
|
||||
KEY_PROVIDER_NAME,
|
||||
KEY_EXTERNAL_CUSTOMER_ID,
|
||||
KEY_CUSTOMER_STATUS
|
||||
KEY_CUSTOMER_STATUS,
|
||||
KEY_UPI_LITE_ACTIVE_ACCOUNT_INFO,
|
||||
KEY_UPI_PRIMARY_ACCOUNT_VPA
|
||||
)
|
||||
const val KEY_NPCI_TOKEN = "npciToken"
|
||||
const val KEY_NPCI_TOKEN_STORED_TIME = "npciTokenStoredTime"
|
||||
|
||||
Reference in New Issue
Block a user