Toru
Toru

Reputation: 1264

"One or more of the arguments provided are invalid" on upgrading to higher tier via RevenueCat in Android app

My Android app integrates RevenueCat SDK v8.3.1 and offers several subscription tiers to users. The error in the title happens for some users. As far as I recognized there are two users amongst thousands of users. (It's in production environment and not something like test user issue)

Non-fatal Exception: com.revenuecat.purchases.PurchasesTransactionException One or more of the arguments provided are invalid.

The actual function code called when user try to upgrade their subscription:

fun selectSubscriptionPlan(activity: Activity, product: StoreProduct) {
        if (uiState.value.isPurchasing) return

        viewModelScope.launch {
            if (Purchases.sharedInstance.isAnonymous) {
                // Block to purchase if the signing-in to RevenueCat has never succeeded even at this point.
                _effect.emit(Effect.DisplayErrorMessage(activity.getString(R.string.message_anonymous_user)))
                return@launch
            }
            try {
                val params = PurchaseParams.Builder(activity, product)

                // To ensure the uiState.value.activeSubscriptionProduct is up to date.
                fetchCustomerInfo()

                uiState.value.activeSubscriptionProduct?.let { currentSubscription ->
                    if (product != currentSubscription) {
                        val currentProductId = currentSubscription.id.split(":").first()
                        val newProductId = product.id.split(":").first()
                        val isCrossGrade = currentProductId == newProductId
                        val isUpgrade =
                            pricePerYear(product) > pricePerYear(currentSubscription)
                        val replacementMode = if (isCrossGrade) {
                            GoogleReplacementMode.WITHOUT_PRORATION
                        } else if (isUpgrade) {
                            GoogleReplacementMode.CHARGE_PRORATED_PRICE
                        } else {
                            GoogleReplacementMode.DEFERRED
                        }
                        params.googleReplacementMode(replacementMode)
                        params.oldProductId(currentProductId)

                        FirebaseCrashlytics.getInstance()
                            .log("Parameters: currentProductId=$currentProductId, newProductId=$newProductId, isCrossGrade=$isCrossGrade, isUpgrade=$isUpgrade, replacementMode=$replacementMode")
                    }
                }
                _uiState.value = uiState.value.copy(isPurchasing = true)
                val result = Purchases.sharedInstance.awaitPurchase(params.build())
                if (result.customerInfo.activeSubscriptions.contains(product.id)) {
                    _effect.emit(Effect.DisplaySuccessMessage(message = activity.getString(R.string.message_purchase_succeeded)))
                    updateSubscriptionStatus(isSubscribed = true)
                    fetchCustomerInfo()
                }
            } catch (e: PurchasesTransactionException) {
                if (!e.userCancelled) {
                    _effect.emit(Effect.DisplayErrorMessage(e.message))
                }
                FirebaseCrashlytics.getInstance().recordException(e)
            } finally {
                _uiState.value = uiState.value.copy(isPurchasing = false)
            }
        }
    }

I can observe that the log I put in Crashlytics when the error occurs says the production IDs are valid and replacement mode should also be valid.

Parameters: currentProductId=airfriend_pro, newProductId=airfriend_mega, isCrossGrade=false, isUpgrade=true, replacementMode=CHARGE_PRORATED_PRICE

I also ask the user to 1) check their payment method on their Google account is valid and also 2) sign-out/sign-in into the Google account again but he says the issue remains.

FYI: The stack trace in Crashlytics:

          Non-fatal Exception: com.revenuecat.purchases.PurchasesTransactionException: One or more of the arguments provided are invalid.
       at com.revenuecat.purchases.CoroutinesExtensionsCommonKt$awaitPurchase$2$2.invoke(CoroutinesExtensionsCommon.kt:60)
       at com.revenuecat.purchases.CoroutinesExtensionsCommonKt$awaitPurchase$2$2.invoke(CoroutinesExtensionsCommon.kt:55)
       at com.revenuecat.purchases.ListenerConversionsCommonKt$purchaseCompletedCallback$1.onError(ListenerConversionsCommon.kt:22)
       at com.revenuecat.purchases.PurchasesOrchestrator$dispatch$1.invoke(PurchasesOrchestrator.kt:944)
       at com.revenuecat.purchases.PurchasesOrchestrator$dispatch$1.invoke(PurchasesOrchestrator.kt:943)
       at com.revenuecat.purchases.PurchasesOrchestrator.dispatch$lambda$17(PurchasesOrchestrator.kt:845)
       at androidx.appcompat.widget.TooltipCompatHandler$$ExternalSyntheticLambda0.run(R8$$SyntheticClass:9)
       at android.os.Handler.handleCallback(Handler.java:958)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:230)
       at android.os.Looper.loop(Looper.java:319)
       at android.app.ActivityThread.main(ActivityThread.java:9063)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:588)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)

Upvotes: 0

Views: 29

Answers (0)

Related Questions