From 1b84e8274639b3f1f45e8ee41399b2e12f6eab62 Mon Sep 17 00:00:00 2001 From: "omer.habib" Date: Tue, 24 Sep 2024 19:57:57 +0500 Subject: [PATCH] fix: Address PR comments --- app/src/main/java/org/openedx/app/di/ScreenModule.kt | 2 +- .../org/openedx/core/domain/interactor/IAPInteractor.kt | 7 ------- .../org/openedx/core/presentation/iap/IAPEventLogger.kt | 9 +++++---- .../org/openedx/core/presentation/iap/IAPViewModel.kt | 6 +++++- .../presentation/container/CourseContainerViewModel.kt | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/openedx/app/di/ScreenModule.kt b/app/src/main/java/org/openedx/app/di/ScreenModule.kt index ea448812a..fda48a168 100644 --- a/app/src/main/java/org/openedx/app/di/ScreenModule.kt +++ b/app/src/main/java/org/openedx/app/di/ScreenModule.kt @@ -448,7 +448,7 @@ val screenModule = module { } single { IAPRepository(get()) } - factory { IAPInteractor(get(), get(), get(), get(), get(), get()) } + factory { IAPInteractor(get(), get(), get(), get(), get()) } viewModel { (iapFlow: IAPFlow, purchaseFlowData: PurchaseFlowData) -> IAPViewModel( iapFlow = iapFlow, diff --git a/core/src/main/java/org/openedx/core/domain/interactor/IAPInteractor.kt b/core/src/main/java/org/openedx/core/domain/interactor/IAPInteractor.kt index f5f96f496..970d4ef9e 100644 --- a/core/src/main/java/org/openedx/core/domain/interactor/IAPInteractor.kt +++ b/core/src/main/java/org/openedx/core/domain/interactor/IAPInteractor.kt @@ -18,7 +18,6 @@ import org.openedx.core.module.billing.getCourseSku import org.openedx.core.module.billing.getPriceAmount import org.openedx.core.presentation.global.AppData import org.openedx.core.presentation.iap.IAPRequestType -import org.openedx.core.system.notifier.IAPNotifier import org.openedx.core.utils.EmailUtil class IAPInteractor( @@ -27,7 +26,6 @@ class IAPInteractor( private val config: Config, private val repository: IAPRepository, private val preferencesManager: CorePreferences, - private val iapNotifier: IAPNotifier, ) { private val iapConfig get() = preferencesManager.appConfig.iapConfig @@ -74,10 +72,6 @@ class IAPInteractor( return basketResponse.basketId } - private suspend fun processCheckout(basketId: Long) { - repository.proceedCheckout(basketId) - } - suspend fun purchaseItem( activity: FragmentActivity, productInfo: ProductInfo, @@ -139,7 +133,6 @@ class IAPInteractor( }?.let { oneTimeProductDetails -> val courseSku = purchase.getCourseSku() ?: return@let val basketId = addToBasket(courseSku) - processCheckout(basketId) executeOrder( basketId = basketId, purchaseToken = purchase.purchaseToken, diff --git a/core/src/main/java/org/openedx/core/presentation/iap/IAPEventLogger.kt b/core/src/main/java/org/openedx/core/presentation/iap/IAPEventLogger.kt index ed0b7fe79..6dfa06eff 100644 --- a/core/src/main/java/org/openedx/core/presentation/iap/IAPEventLogger.kt +++ b/core/src/main/java/org/openedx/core/presentation/iap/IAPEventLogger.kt @@ -25,17 +25,17 @@ class IAPEventLogger( }.toMutableMap()) } - fun purchaseErrorEvent(error: String) { + private fun purchaseErrorEvent(error: String) { logIAPEvent(IAPAnalyticsEvent.IAP_PAYMENT_ERROR, buildMap { put(IAPAnalyticsKeys.ERROR.key, error) }.toMutableMap()) } - fun canceledByUserEvent() { + private fun canceledByUserEvent() { logIAPEvent(IAPAnalyticsEvent.IAP_PAYMENT_CANCELED) } - fun courseUpgradeErrorEvent(error: String) { + private fun courseUpgradeErrorEvent(error: String) { logIAPEvent(IAPAnalyticsEvent.IAP_COURSE_UPGRADE_ERROR, buildMap { put(IAPAnalyticsKeys.ERROR.key, error) }.toMutableMap()) @@ -47,7 +47,7 @@ class IAPEventLogger( }.toMutableMap()) } - fun logExceptionEvent(iapException: IAPException){ + fun logExceptionEvent(iapException: IAPException) { val feedbackErrorMessage: String = iapException.getFormattedErrorMessage() when (iapException.requestType) { IAPRequestType.PAYMENT_SDK_CODE -> { @@ -69,6 +69,7 @@ class IAPEventLogger( } } } + fun logIAPErrorActionEvent(alertType: String, action: String) { logIAPEvent(IAPAnalyticsEvent.IAP_ERROR_ALERT_ACTION, buildMap { put(IAPAnalyticsKeys.ERROR_ALERT_TYPE.key, alertType) diff --git a/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt b/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt index 7459748e2..56190d82c 100644 --- a/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt +++ b/core/src/main/java/org/openedx/core/presentation/iap/IAPViewModel.kt @@ -154,9 +154,13 @@ class IAPViewModel( return } + addToBasket(productInfo.courseSku) + } + + private fun addToBasket(courseSku: String) { viewModelScope.launch(Dispatchers.IO) { runCatching { - iapInteractor.addToBasket(productInfo.courseSku) + iapInteractor.addToBasket(courseSku) }.onSuccess { basketId -> purchaseFlowData.basketId = basketId _uiState.value = IAPUIState.PurchaseProduct diff --git a/course/src/main/java/org/openedx/course/presentation/container/CourseContainerViewModel.kt b/course/src/main/java/org/openedx/course/presentation/container/CourseContainerViewModel.kt index ae5754241..af74b2a6e 100644 --- a/course/src/main/java/org/openedx/course/presentation/container/CourseContainerViewModel.kt +++ b/course/src/main/java/org/openedx/course/presentation/container/CourseContainerViewModel.kt @@ -304,7 +304,7 @@ class CourseContainerViewModel( ?.apply { _iapState.value = IAPUIState.Loading(loaderType = IAPLoaderType.PRICE) runCatching { - iapInteractor.loadPrice(purchaseFlowData.productInfo?.storeSku!! + "_") + iapInteractor.loadPrice(purchaseFlowData.productInfo?.storeSku!!) }.onSuccess { this.formattedPrice = it.formattedPrice this.price = it.getPriceAmount()