NTP-35382 | fixed lite mandate creation polling case (#14881)

This commit is contained in:
Shaurya Rehan
2025-02-06 16:14:40 +05:30
committed by GitHub
parent 83c9ce3795
commit 2044e048bc

View File

@@ -3892,9 +3892,9 @@ constructor(
onOnboardingTriggered = { updateTriggerDismissBottomSheet() },
onPspEvaluated = {
pspEvaluationResult = it
if (pspEvaluationResult.psp == null)
if (pspEvaluationResult?.psp == null)
return@evaluateAndOnboardPspForLiteActions
if (pspEvaluationResult.isOnboardingTriggered == true) {
if (pspEvaluationResult?.isOnboardingTriggered == true) {
resetPreviousLinkedAccountsSize()
}
},
@@ -4474,21 +4474,26 @@ constructor(
}
else -> {
// creation failed, delete cached mandate info
deleteLiteMandateInfo()
updateUiStateAndResetCheckBalanceState(uiState = UpiLiteUiState.MAIN_SCREEN)
updateBottomSheetUiState(
showBottomSheet = true,
bottomSheetStateChange = true,
bottomSheetUiState = UpiLiteBottomSheetType.AutoTopUpSetupFailedBottomSheet,
)
handleMandateCreationFailedCase()
}
}
}
private suspend fun handleMandateCreationFailedCase() {
deleteLiteMandateInfo()
updateUiStateAndResetCheckBalanceState(uiState = UpiLiteUiState.MAIN_SCREEN)
updateBottomSheetUiState(
showBottomSheet = true,
bottomSheetStateChange = true,
bottomSheetUiState = UpiLiteBottomSheetType.AutoTopUpSetupFailedBottomSheet,
)
}
private suspend fun startFirstExecution(
linkedAccountEntity: LinkedAccountEntity,
lrn: String,
executionAmount: String,
showSuccessLottie: Boolean = true,
) {
val upiRequestId = upiRequestIdUseCase.execute()
initiateMandateExecution(
@@ -4496,6 +4501,7 @@ constructor(
linkedAccountEntity = linkedAccountEntity,
lrn = lrn,
executionAmount = executionAmount,
showSuccessLottie = showSuccessLottie,
)
}
@@ -4505,6 +4511,7 @@ constructor(
linkedAccountEntity: LinkedAccountEntity,
lrn: String,
executionAmount: String,
showSuccessLottie: Boolean = true,
) {
val executeMandateRequest =
ExecuteMandateRequest(
@@ -4561,6 +4568,7 @@ constructor(
accountId = linkedAccountEntity.accountId,
lrn = lrn,
arpc = executeMandateApiResponse.data!!.arpc,
showSuccessLottie = showSuccessLottie,
)
}
MandateResponseState.PENDING.name -> {
@@ -4631,7 +4639,7 @@ constructor(
initialTopUpStatus = InitialTopUpStatus.SUCCESS,
accountId = accountId,
lrn = lrn,
upiRequestId = "",
upiRequestId = upiRequestId,
)
}
@@ -4816,6 +4824,7 @@ constructor(
)
.lrn
handleMandateCreationPollingResponse(
liteMandateInfo = liteMandateInfo,
mandateStatusApiResponse = mandateCreationStatusApiResponse,
upiRequestId = liteMandateInfo.upiRequestId,
accountId = liteMandateInfo.bankAccountUniqueId.orEmpty(),
@@ -4863,6 +4872,7 @@ constructor(
}
private suspend fun handleMandateCreationPollingResponse(
liteMandateInfo: MandateItem,
mandateStatusApiResponse: RepoResult<MandateStatusResponse>,
upiRequestId: String,
accountId: String,
@@ -4878,19 +4888,30 @@ constructor(
naviApiPoller.stopPolling()
when (mandateStatusResponse.state) {
MandateResponseState.SUCCESS.name -> {
handleExecutionSuccessCase(
upiRequestId = upiRequestId,
accountId = accountId,
// Mandate is created, proceed for first execution
saveMandateInfoToCache(
mandateInfo =
liteMandateInfo.copy(
status = MandateStatus.CREATED.name,
upiRequestId = upiRequestId,
)
)
val metaData =
getLiteMandateMetaDataFromMap(
liteMandateResponseInfo = liteMandateInfo.liteMandateResponseInfo
)
val topUpAmount = metaData.topUpAmount.orEmpty()
startFirstExecution(
linkedAccountEntity =
linkedAccounts.value.first { it.accountId == accountId },
lrn = lrn,
executionAmount = topUpAmount,
showSuccessLottie = false,
)
}
MandateResponseState.FAILURE.name -> {
handleExecutionFailedCase(
upiRequestId = upiRequestId,
accountId = accountId,
lrn = lrn,
)
// Mandate is not created, no need to revoke mandate
handleMandateCreationFailedCase()
}
else -> {
// Do nothing