Skip to content

Commit

Permalink
fix: Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Sep 24, 2024
1 parent 59d3790 commit 1b84e82
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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 -> {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1b84e82

Please sign in to comment.