TP-72001 | Negative reinforcement flow fix (#11897)
This commit is contained in:
@@ -168,11 +168,6 @@ class CustomPaymentActivity :
|
||||
loanType: String?
|
||||
) {
|
||||
this.loanAccountNumber = loanAccountNumber
|
||||
if (
|
||||
System.currentTimeMillis() - apiCallLastTime <=
|
||||
Constants.API_CALL_MULTI_CLICK_THRESOLD_DUR
|
||||
)
|
||||
return
|
||||
showLoader()
|
||||
NaviAnalytics.naviAnalytics.Payment().onPlPaymentInitiatePaymentCalled(loanType)
|
||||
paymentVM.setIsPaymentLoaderShowing(true)
|
||||
|
||||
@@ -7,29 +7,70 @@
|
||||
|
||||
package com.naviapp.payment_behaviour
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.navi.base.model.CtaData
|
||||
import com.navi.base.utils.orElse
|
||||
import com.navi.base.utils.orZero
|
||||
import com.navi.common.firebasedb.FirebaseDataHelper
|
||||
import com.navi.common.firebasedb.FirebaseDataReceiveListener
|
||||
import com.navi.common.firebasedb.FirebaseResponse
|
||||
import com.navi.common.firebasedb.FirebaseStatusType
|
||||
import com.navi.common.firebasedb.PAYMENT_STATUS
|
||||
import com.navi.common.listeners.FragmentInterchangeListener
|
||||
import com.navi.common.model.ModuleNameV2
|
||||
import com.navi.common.utils.ApiPollScheduler
|
||||
import com.navi.common.utils.observeNullable
|
||||
import com.navi.payment.model.common.PaymentSdkInitParams
|
||||
import com.navi.payment.model.common.PaymentSdkTypes
|
||||
import com.navi.payment.model.initiatesdk.PaymentPrefetchMethodRequest
|
||||
import com.navi.payment.nativepayment.router.NaviPaymentRouter
|
||||
import com.navi.payment.nativepayment.sharedviewmodel.NaviCheckoutViewModel
|
||||
import com.navi.payment.utils.Constants.FULL_PAYMENT_SCREEN
|
||||
import com.navi.payment.utils.PaymentSource
|
||||
import com.navi.paymentclients.model.InitiatePaymentRequest
|
||||
import com.naviapp.R
|
||||
import com.naviapp.analytics.utils.NaviAnalytics
|
||||
import com.naviapp.common.navigator.NaviDeepLinkNavigator
|
||||
import com.naviapp.custom_payments.listener.InitiatePaymentListener
|
||||
import com.naviapp.dashboard.DashboardBaseActivity
|
||||
import com.naviapp.databinding.ActivityContainerBinding
|
||||
import com.naviapp.models.SubPageStatusType
|
||||
import com.naviapp.part_prepayment.FragmentMapper
|
||||
import com.naviapp.part_prepayment.fragments.PartPrePaymentBaseFragment
|
||||
import com.naviapp.payment.activities.FeedbackActivity
|
||||
import com.naviapp.payment.models.Amount
|
||||
import com.naviapp.payment.viewmodel.PaymentVM
|
||||
import com.naviapp.utils.Constants
|
||||
import com.naviapp.utils.Constants.LOAN_TYPE
|
||||
import com.naviapp.utils.Constants.TYPE_PERSONAL_LOAN
|
||||
import com.naviapp.utils.IS_SYNC_FLOW
|
||||
import com.naviapp.utils.LOAN_ACCOUNT_NUMBER
|
||||
import com.naviapp.utils.LOAN_ACCOUNT_REQUEST_ID
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import java.util.Locale
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class PaymentBehaviourActivity : DashboardBaseActivity(), FragmentInterchangeListener {
|
||||
class PaymentBehaviourActivity :
|
||||
DashboardBaseActivity(), FragmentInterchangeListener, InitiatePaymentListener {
|
||||
private lateinit var binding: ActivityContainerBinding
|
||||
@Inject lateinit var fragmentMapper: FragmentMapper
|
||||
|
||||
private val paymentVM by viewModels<PaymentVM>()
|
||||
|
||||
private val naviCheckoutViewModel by viewModels<NaviCheckoutViewModel>()
|
||||
private var loanAccountNumber: String? = null
|
||||
|
||||
private var firebaseDataReceiveListener: FirebaseDataReceiveListener? = null
|
||||
private var firebaseDataHelper: FirebaseDataHelper? = null
|
||||
private var apiPollScheduler: ApiPollScheduler? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = DataBindingUtil.setContentView(this, R.layout.activity_container)
|
||||
@@ -40,6 +81,8 @@ class PaymentBehaviourActivity : DashboardBaseActivity(), FragmentInterchangeLis
|
||||
.orElse(SubPageStatusType.PAYMENT_BEHAVIOUR),
|
||||
intent?.extras ?: Bundle()
|
||||
)
|
||||
observePaymentListener()
|
||||
observeInitiatePaymentStatus()
|
||||
}
|
||||
|
||||
override val screenName: String
|
||||
@@ -98,4 +141,174 @@ class PaymentBehaviourActivity : DashboardBaseActivity(), FragmentInterchangeLis
|
||||
}
|
||||
} ?: run { finish() }
|
||||
}
|
||||
|
||||
override fun initiatePayment(
|
||||
amount: Amount,
|
||||
isPreClosure: Boolean,
|
||||
repaymentType: String?,
|
||||
sourceOfFunds: String?,
|
||||
otherSourceOfFunds: String?,
|
||||
partPrePaymentRescheduleType: String?,
|
||||
loanAccountNumber: String?,
|
||||
loanType: String?
|
||||
) {
|
||||
this.loanAccountNumber = loanAccountNumber
|
||||
showLoader()
|
||||
NaviAnalytics.naviAnalytics.Payment().onPlPaymentInitiatePaymentCalled(loanType)
|
||||
paymentVM.setIsPaymentLoaderShowing(true)
|
||||
val data =
|
||||
InitiatePaymentRequest(
|
||||
loanAccountNumber,
|
||||
com.navi.paymentclients.model.Amount(
|
||||
value = amount.value,
|
||||
currency = amount.currency,
|
||||
symbol = amount.symbol
|
||||
),
|
||||
isPreClosure,
|
||||
repaymentType,
|
||||
sourceOfFunds,
|
||||
otherSourceOfFunds,
|
||||
partPrePaymentRescheduleType
|
||||
)
|
||||
paymentVM.initiatePayment(data)
|
||||
}
|
||||
|
||||
private fun observePaymentListener() {
|
||||
paymentVM.initPaymentResponse.observeNullable(this) { paymentResponse ->
|
||||
val paymentSdkInitParams =
|
||||
PaymentSdkInitParams(
|
||||
token = paymentResponse?.tokenDetails?.token.orEmpty(),
|
||||
requestId = null,
|
||||
mintToken = false,
|
||||
paymentPreFetchMethodRequest =
|
||||
PaymentPrefetchMethodRequest(
|
||||
callSdkExitOnBack = false,
|
||||
previousScreenName = PaymentSource.PL.name
|
||||
),
|
||||
screenType = FULL_PAYMENT_SCREEN,
|
||||
paymentSource = PaymentSource.PL.name
|
||||
)
|
||||
naviCheckoutViewModel.initiatePayment(paymentSdkInitParams)
|
||||
}
|
||||
|
||||
paymentVM.paymentStatusData.observeNullable(this) {
|
||||
handleFirebaseResult(it.orEmpty(), PAYMENT_STATUS)
|
||||
}
|
||||
}
|
||||
|
||||
private fun observeInitiatePaymentStatus() {
|
||||
lifecycleScope.launchWhenResumed {
|
||||
naviCheckoutViewModel.paymentResponse.collect { data ->
|
||||
if (data) {
|
||||
hideLoader()
|
||||
NaviPaymentRouter.startPayment(
|
||||
composePaymentsResultLauncher,
|
||||
this@PaymentBehaviourActivity
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val composePaymentsResultLauncher =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
|
||||
if (result.resultCode == 0) return@registerForActivityResult
|
||||
val status =
|
||||
result
|
||||
?.data
|
||||
?.extras
|
||||
?.getString(
|
||||
com.navi.payment.utils.Constants.STATUS.uppercase(Locale.getDefault())
|
||||
)
|
||||
when (status) {
|
||||
PaymentSdkTypes.DISMISS_LOADER.name -> {}
|
||||
PaymentSdkTypes.TRANSACTION_SUCCESS.name -> {
|
||||
showLoader()
|
||||
apiPollInit()
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
private fun redirectToPaymentSuccessScreen() {
|
||||
val intent = Intent(this, FeedbackActivity::class.java)
|
||||
intent.putExtra(LOAN_ACCOUNT_NUMBER, loanAccountNumber)
|
||||
intent.putExtra(
|
||||
LOAN_ACCOUNT_REQUEST_ID,
|
||||
paymentVM.initPaymentResponse.value?.requestId.toString()
|
||||
)
|
||||
intent.putExtra(IS_SYNC_FLOW, true)
|
||||
intent.putExtra(LOAN_TYPE, TYPE_PERSONAL_LOAN)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
private fun apiPollInit() {
|
||||
val config = paymentVM.initPaymentResponse.value?.requestConfig
|
||||
val requestId = paymentVM.initPaymentResponse.value?.requestId.orEmpty()
|
||||
firebaseInit(
|
||||
requestId,
|
||||
PAYMENT_STATUS,
|
||||
paymentVM.initPaymentResponse.value?.notificationPath.orEmpty()
|
||||
)
|
||||
apiPollScheduler?.stopApiPoll()
|
||||
apiPollScheduler =
|
||||
ApiPollScheduler(
|
||||
initialDelay = config?.initialDelay?.toLong().orZero(),
|
||||
pollInterval =
|
||||
config
|
||||
?.interval
|
||||
?.toLong()
|
||||
.orElse(ApiPollScheduler.API_POLL_REPEAT_PERIOD_SECONDS),
|
||||
numberOfRetry = config?.numOfRetries.orElse(ApiPollScheduler.API_POLL_RETRY_COUNT),
|
||||
doOnTimeout = { hideLoader() }
|
||||
) {
|
||||
paymentVM.fetchSyncPaymentStatus(requestId)
|
||||
}
|
||||
apiPollScheduler?.scheduleApiPoll()
|
||||
}
|
||||
|
||||
private fun firebaseInit(requestId: String, type: String, notificationPath: String) {
|
||||
firebaseDataReceiveListener =
|
||||
object : FirebaseDataReceiveListener {
|
||||
override fun onDataReceive(firebaseResponse: FirebaseResponse?) {
|
||||
firebaseResponse?.let {
|
||||
apiPollScheduler?.stopApiPoll()
|
||||
handleFirebaseResult(it.status.orEmpty(), type)
|
||||
}
|
||||
}
|
||||
}
|
||||
firebaseDataHelper = null
|
||||
firebaseDataHelper = FirebaseDataHelper()
|
||||
firebaseDataHelper?.initFirebaseDataReceiver(
|
||||
lifecycle,
|
||||
firebaseDataReceiveListener,
|
||||
type,
|
||||
requestId,
|
||||
notificationPath
|
||||
)
|
||||
}
|
||||
|
||||
private fun handleFirebaseResult(status: String, type: String) {
|
||||
when (type) {
|
||||
PAYMENT_STATUS -> {
|
||||
if (
|
||||
TextUtils.equals(status, FirebaseStatusType.SUCCESS) ||
|
||||
TextUtils.equals(status, FirebaseStatusType.FAILURE)
|
||||
) {
|
||||
hideLoader()
|
||||
apiPollScheduler?.stopApiPoll()
|
||||
handlePgRepaymentStatus(status)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun handlePgRepaymentStatus(status: String) {
|
||||
when (status) {
|
||||
FirebaseStatusType.SUCCESS -> {
|
||||
redirectToPaymentSuccessScreen()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user