Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
fix: Address PR comments
Browse files Browse the repository at this point in the history
-LEARNER-9845
  • Loading branch information
omerhabib26 committed Feb 16, 2024
1 parent 49b9d4f commit f09bde6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ class CourseModalDialogFragment : DialogFragment() {
errorMessage = errorMessage,
retryListener = retryListener
)
binding.layoutUpgradeBtn.root.setVisibility(false)
// Hide the upgrade button if the course SKU is not available on Play Console.
if (errorMessage.requestType == ErrorMessage.NO_SKU_CODE) {
binding.layoutUpgradeBtn.root.setVisibility(false)
}
}

private fun enableUpgradeButton(enable: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.ProductDetails.OneTimePurchaseOfferDetails
import com.android.billingclient.api.Purchase
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -98,27 +99,34 @@ class InAppPurchasesViewModel @Inject constructor(
viewModelScope.launch {
val response = billingProcessor.querySyncDetails(courseSku)
val productDetail = response.productDetailsList?.firstOrNull()
val billingResult = response.billingResult

if (productDetail?.productId == courseSku) {
productDetail.oneTimePurchaseOfferDetails?.let {
_productPrice.postEvent(it)
iapAnalytics.setPrice(it.formattedPrice)
iapAnalytics.trackIAPEvent(Analytics.Events.IAP_LOAD_PRICE_TIME)
} ?: dispatchError(
requestType = ErrorMessage.PRICE_CODE,
throwable = InAppPurchasesException(
httpErrorCode = response.billingResult.responseCode,
errorMessage = response.billingResult.debugMessage,
when {
billingResult.responseCode == BillingClient.BillingResponseCode.OK && productDetail == null -> {
dispatchError(
requestType = ErrorMessage.NO_SKU_CODE,
throwable = InAppPurchasesException(
httpErrorCode = billingResult.responseCode,
errorMessage = billingResult.debugMessage
)
)
)
} else {
dispatchError(
requestType = ErrorMessage.NO_SKU_CODE,
throwable = InAppPurchasesException(
httpErrorCode = response.billingResult.responseCode,
errorMessage = response.billingResult.debugMessage,
}

productDetail?.productId == courseSku && productDetail.oneTimePurchaseOfferDetails != null -> {
_productPrice.postEvent(productDetail.oneTimePurchaseOfferDetails!!)
iapAnalytics.setPrice(productDetail.oneTimePurchaseOfferDetails?.formattedPrice!!)
iapAnalytics.trackIAPEvent(Analytics.Events.IAP_LOAD_PRICE_TIME)
}

else -> {
dispatchError(
requestType = ErrorMessage.PRICE_CODE,
throwable = InAppPurchasesException(
httpErrorCode = response.billingResult.responseCode,
errorMessage = response.billingResult.debugMessage,
)
)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class InAppPurchasesDialog @Inject constructor(
errorMsg = feedbackErrorMessage
)

ErrorMessage.PRICE_CODE -> iapAnalytics.trackIAPEvent(
ErrorMessage.PRICE_CODE,
ErrorMessage.NO_SKU_CODE -> iapAnalytics.trackIAPEvent(
eventName = Analytics.Events.IAP_PRICE_LOAD_ERROR,
errorMsg = feedbackErrorMessage
)
Expand Down

0 comments on commit f09bde6

Please sign in to comment.