-
Notifications
You must be signed in to change notification settings - Fork 86
Description
- I have updated Purchases SDK to the latest version
- I have read the Contribution Guidelines
- I have searched the Community
- I have read docs.revenuecat.com
- I have searched for existing Github issues
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)
}
- Environment
- Platform: Android
- SDK version: 9.0.0
- OS version: All
- Android Studio version:
- How widespread is the issue. Percentage of devices affected. 100%
- Debug logs that reproduce the issue
- Steps to reproduce, with a description of expected vs. actual behavior
- 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.