Skip to content

[Bug] Cannot upgrade any subscription on RevenueCat SDK v9.0.0 #2531

@shawn-lin-013

Description

@shawn-lin-013

Describe the bug
After purchasing the monthly subscription, the upgrade to the yearly subscription fails every time.
The logcat shows that the issue is caused by "Couldn't find existing purchase for SKU."
However, we can find the purchased monthly subscription in both the Querying Purchases result and activeSubscriptions, so we believe the purchased monthly subscription does exist and is valid.

After further investigation, we found that this issue may be caused by the migration to BillingClient v8.0.0, as Google has removed the ability to query purchase history.

Root Cause:
In toMapOfGooglePurchaseWrapper(), the key of the map is purchaseToken.sha1(),
but in findPurchaseInActivePurchases(), the code uses purchasesByProductId[productId] to retrieve the StoreTransaction from the map created by toMapOfGooglePurchaseWrapper() — which leads to a mismatch between the key (purchaseToken.sha1()) and the lookup (productId).

Logcat

PurchasesError(code=PurchaseInvalidError, underlyingErrorMessage=Couldn't find existing purchase for SKU: XXXXXX, message='One or more of the arguments provided are invalid.')

function toMapOfGooglePurchaseWrapper in QueryPurchasesByTypeUseCase.kt

private fun List<Purchase>.toMapOfGooglePurchaseWrapper(
    @ProductType productType: String,
): Map<String, StoreTransaction> {
    return this.associate { purchase ->
        val hash = purchase.purchaseToken.sha1()
        hash to purchase.toStoreTransaction(productType.toRevenueCatProductType())
    }
}

function findPurchaseInActivePurchases in BillingWrapper.kt

val purchasesRecordWrapper = purchasesByProductId[productId]
if (purchasesRecordWrapper != null) {
    onCompletion(purchasesRecordWrapper)
} else {
    val message = PurchaseStrings.NO_EXISTING_PURCHASE.format(productId)
    val error = PurchasesError(PurchasesErrorCode.PurchaseInvalidError, message)
    onError(error)
}
  1. Environment
    1. Platform: Android
    2. SDK version: 9.0.0
    3. OS version: All
    4. Android Studio version:
    5. How widespread is the issue. Percentage of devices affected. 100%
  2. Debug logs that reproduce the issue
  3. Steps to reproduce, with a description of expected vs. actual behavior
  4. Other information (e.g. stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc.)
    Additional context
    Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions