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

Commit

Permalink
fix: Add Alert Dialog in case of missing SKU on Store (#1847)
Browse files Browse the repository at this point in the history
fix: Add Alert Dialog in case missing SKU on Store

- Added an alert in case of course SKU doesn't exist on PlayConsole
- added ErrorMessage type for `sku`

-LEARNER-9845
  • Loading branch information
omerhabib26 authored Feb 21, 2024
1 parent 2b52504 commit e0a44da
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,17 @@ data class ErrorMessage(
const val PAYMENT_SDK_CODE = 0x204
const val COURSE_REFRESH_CODE = 0x205
const val PRICE_CODE = 0x206
const val NO_SKU_CODE = 0x207
}

private fun isPreUpgradeErrorType(): Boolean = requestType == PRICE_CODE ||
requestType == ADD_TO_BASKET_CODE || requestType == CHECKOUT_CODE ||
requestType == PAYMENT_SDK_CODE
private fun isPreUpgradeErrorType(): Boolean =
requestType in setOf(
PRICE_CODE,
NO_SKU_CODE,
ADD_TO_BASKET_CODE,
CHECKOUT_CODE,
PAYMENT_SDK_CODE
)

fun isPostUpgradeErrorType(): Boolean = !isPreUpgradeErrorType()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ object InAppPurchasesUtils {

else -> when (requestType) {
ErrorMessage.PAYMENT_SDK_CODE -> R.string.error_payment_not_processed
ErrorMessage.PRICE_CODE -> R.string.error_price_not_fetched
ErrorMessage.PRICE_CODE,
ErrorMessage.NO_SKU_CODE -> R.string.error_price_not_fetched

ErrorMessage.COURSE_REFRESH_CODE -> R.string.error_course_not_fullfilled
else -> R.string.general_error_message
}
Expand Down
29 changes: 9 additions & 20 deletions OpenEdXMobile/src/main/java/org/edx/mobile/util/TextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,26 +207,15 @@ public static StringBuilder getFormattedErrorMessage(int requestType, int errorC
if (requestType == 0) {
return body;
}
String endpoint;
switch (requestType) {
case ErrorMessage.ADD_TO_BASKET_CODE:
endpoint = "basket";
break;
case ErrorMessage.CHECKOUT_CODE:
endpoint = "checkout";
break;
case ErrorMessage.EXECUTE_ORDER_CODE:
endpoint = "execute";
break;
case ErrorMessage.PAYMENT_SDK_CODE:
endpoint = "payment";
break;
case ErrorMessage.PRICE_CODE:
endpoint = "price";
break;
default:
endpoint = "unhandledError";
}
String endpoint = switch (requestType) {
case ErrorMessage.ADD_TO_BASKET_CODE -> "basket";
case ErrorMessage.CHECKOUT_CODE -> "checkout";
case ErrorMessage.EXECUTE_ORDER_CODE -> "execute";
case ErrorMessage.PAYMENT_SDK_CODE -> "payment";
case ErrorMessage.PRICE_CODE -> "price";
case ErrorMessage.NO_SKU_CODE -> "sku";
default -> "unhandledError";
};
body.append(String.format("%s", endpoint));
// change the default value to -1 cuz in case of BillingClient return errorCode 0 for price load.
if (errorCode == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ class CourseModalDialogFragment : DialogFragment() {
errorMessage = errorMessage,
retryListener = retryListener
)
// 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,19 +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)
when {
billingResult.responseCode == BillingClient.BillingResponseCode.OK && productDetail == null -> {
dispatchError(
requestType = ErrorMessage.NO_SKU_CODE,
throwable = InAppPurchasesException(
httpErrorCode = billingResult.responseCode,
errorMessage = 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)
} ?: dispatchError(
requestType = ErrorMessage.PRICE_CODE,
throwable = InAppPurchasesException(
httpErrorCode = response.billingResult.responseCode,
errorMessage = response.billingResult.debugMessage,
}

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 All @@ -104,8 +105,18 @@ class InAppPurchasesDialog @Inject constructor(
errorMessage.getHttpErrorCode()
)

var (@StringRes positiveBtnResId, @StringRes negativeBtnResId) = when (errorMessage.requestType) {
ErrorMessage.NO_SKU_CODE -> {
R.string.label_ok to 0
}

else -> {
R.string.label_close to
if (retryListener != null) R.string.label_cancel else R.string.label_get_help
}
}

var actionTaken: String = Analytics.Values.ACTION_CLOSE
@StringRes var positiveBtnResId = R.string.label_close
if (retryListener != null) {
when (errorMessage.getHttpErrorCode()) {
HttpStatus.NOT_ACCEPTABLE -> {
Expand Down Expand Up @@ -135,15 +146,17 @@ class InAppPurchasesDialog @Inject constructor(
}
} ?: run { trackAlertCloseEvent(feedbackErrorMessage) }
},
context.getString(if (retryListener != null) R.string.label_cancel else R.string.label_get_help),
if (negativeBtnResId != 0) context.getString(negativeBtnResId) else "",
{ _, _ ->
if (retryListener != null) {
trackAlertCloseEvent(feedbackErrorMessage)
if (context is DialogFragment) {
context.dismiss()
}
} else {
showFeedbackScreen(context, feedbackErrorMessage)
if (errorMessage.requestType != ErrorMessage.NO_SKU_CODE) {
showFeedbackScreen(context, feedbackErrorMessage)
}
}
}, false
).show(context.childFragmentManager, null)
Expand Down

0 comments on commit e0a44da

Please sign in to comment.