TP-53347 | Issue Fix - Payment SDK Initialisation (#9265)
This commit is contained in:
committed by
GitHub
parent
512f8fdfea
commit
b81263d2e0
@@ -3,9 +3,15 @@ package com.navi.insurance.common
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import com.navi.common.juspay.HyperServicesHolder
|
||||
import com.navi.insurance.R
|
||||
import com.navi.insurance.analytics.NaviInsuranceAnalytics
|
||||
import com.navi.insurance.common.models.Action
|
||||
@@ -13,12 +19,30 @@ import com.navi.insurance.common.models.NaviActionType
|
||||
import com.navi.insurance.common.models.NewScreenActionData
|
||||
import com.navi.insurance.common.util.ActionHandler
|
||||
import com.navi.insurance.health.activity.BaseActivity
|
||||
import com.navi.insurance.health.activity.JusPayUtil
|
||||
import com.navi.insurance.health.fragment.BaseFragment
|
||||
import com.navi.insurance.util.observeNonNull
|
||||
import com.navi.payment.analytics.NaviPaymentScreenAnalytics
|
||||
import com.navi.payment.base.PaymentManager
|
||||
import com.navi.payment.model.initiatesdk.InitiatePaymentSDKConfig
|
||||
import com.navi.payment.model.initiatesdk.PaymentSDKProvider
|
||||
import com.navi.payment.model.juspay.JuspaySDKConfig
|
||||
import com.navi.payment.utils.NaviPaymentJusPayUtil
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import `in`.juspay.hypersdk.core.MerchantViewType
|
||||
import `in`.juspay.hypersdk.data.JuspayResponseHandler
|
||||
import `in`.juspay.hypersdk.ui.HyperPaymentsCallback
|
||||
import org.json.JSONObject
|
||||
import java.util.UUID
|
||||
|
||||
@AndroidEntryPoint
|
||||
abstract class GiBaseActivity : BaseActivity(), ActionHandler.ActionOwner {
|
||||
|
||||
private val paymentVM: PaymentManager by lazy { ViewModelProvider(this)[PaymentManager::class.java] }
|
||||
|
||||
private val paymentScreenAnalytics by lazy { NaviPaymentScreenAnalytics.naviAnalytics.PaymentMethodAnalytics() }
|
||||
|
||||
private val paymentAnalyticsTracker = NaviInsuranceAnalytics.instance.QuoteActivityAnalytics()
|
||||
companion object {
|
||||
const val KEY_SCREEN_IDENTIFIER = "screenIdentifier"
|
||||
}
|
||||
@@ -27,12 +51,88 @@ abstract class GiBaseActivity : BaseActivity(), ActionHandler.ActionOwner {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
initThirdPartySDKs()
|
||||
initPaymentObserver()
|
||||
val url = getLaunchFragmentUrl(savedInstanceState)
|
||||
url?.let {
|
||||
launchScreen(it, intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initPaymentObserver() {
|
||||
paymentVM.paymentSDKInitConfig.observeNonNull(this) {
|
||||
initiatePaymentSDKConfigs(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initiatePaymentSDKConfigs(it: List<InitiatePaymentSDKConfig>?) {
|
||||
it?.forEach {
|
||||
initiatePaymentSDKConfig ->
|
||||
initiatePaymentSDKConfigByProviderType(initiatePaymentSDKConfig)
|
||||
}
|
||||
}
|
||||
|
||||
private fun initiatePaymentSDKConfigByProviderType(initiatePaymentSDKConfig: InitiatePaymentSDKConfig) {
|
||||
when(initiatePaymentSDKConfig.provider.orEmpty()){
|
||||
PaymentSDKProvider.JUSPAY.name -> {
|
||||
initiateJuspaySDK(initiatePaymentSDKConfig as? JuspaySDKConfig)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun initThirdPartySDKs() {
|
||||
if (!HyperServicesHolder.isSDKInitialized()) {
|
||||
paymentVM.initiatePaymentSDK()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun initiateJuspaySDK(juspaySDKConfig: JuspaySDKConfig?) {
|
||||
juspaySDKConfig?.sdkInitiationDetails?.payload?.let {
|
||||
juspayPayload->
|
||||
if (HyperServicesHolder.isSDKInitialized().not()) {
|
||||
HyperServicesHolder.initiateSDKWithCallback(
|
||||
this,
|
||||
JusPayUtil.getSDKPayload(
|
||||
JusPayUtil.getInitiatePayloadFromPaymentConfig(juspayPayload),
|
||||
UUID.randomUUID().toString()
|
||||
),
|
||||
object : HyperPaymentsCallback {
|
||||
override fun onStartWaitingDialogCreated(p0: View?) {}
|
||||
override fun onEvent(data: JSONObject?, hander: JuspayResponseHandler?) {
|
||||
try {
|
||||
val response: JSONObject? = data?.optJSONObject(
|
||||
NaviPaymentJusPayUtil.ARG_PAYLOAD
|
||||
)
|
||||
paymentScreenAnalytics.sendEvent(
|
||||
NaviPaymentScreenAnalytics.JUSPAY_INITIALISE_RESPONSE,
|
||||
mapOf(
|
||||
Pair(
|
||||
"response",
|
||||
data.toString()
|
||||
)
|
||||
)
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
FirebaseCrashlytics.getInstance().recordException(e)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMerchantView(p0: ViewGroup?, p1: MerchantViewType?): View? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun createJuspaySafeWebViewClient(): WebViewClient? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
) { log ->
|
||||
paymentAnalyticsTracker.jusPayAdditionalTracking(log)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
open fun launchScreen(
|
||||
screenIdentifier: String,
|
||||
intent: Intent?,
|
||||
|
||||
Reference in New Issue
Block a user