From 5b66ea6ef6751226f9c8b81921b4e5c61fb19db2 Mon Sep 17 00:00:00 2001 From: Surik Date: Wed, 10 Apr 2024 15:58:10 +0400 Subject: [PATCH 1/2] Updated logic to fix rare cases for acknowledging purchases issue --- .../android/sdk/internal/QProductCenterManager.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt index 0009f57d..e910c40a 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt @@ -89,6 +89,8 @@ internal class QProductCenterManager internal constructor( private var advertisingID: String? = null private var pendingInitRequestData: InitRequestData? = null + private var processingPurchases: List = emptyList() + private var converter: PurchaseConverter = GooglePurchaseConverter() @Volatile @@ -616,6 +618,8 @@ internal class QProductCenterManager internal constructor( val completedPurchases = purchases.filter { it.purchaseState == Purchase.PurchaseState.PURCHASED } + processingPurchases = completedPurchases + val purchasesInfo = converter.convertPurchases(completedPurchases) val handledPurchasesCallback = @@ -658,6 +662,17 @@ internal class QProductCenterManager internal constructor( loadStoreProductsIfPossible() + if (processingPurchases.isNotEmpty()) { + processingPurchases.forEach { + if (!handledPurchasesCache.shouldHandlePurchase(it)) { return@forEach } + + handledPurchasesCache.saveHandledPurchase(it) + } + + billingService.consumePurchases(processingPurchases.toList()) + processingPurchases = emptyList() + } + handleCachedPurchases() callback?.onSuccess(launchResult) From 735590f5a9881c5c18eca0699423f330775af174 Mon Sep 17 00:00:00 2001 From: Surik Sarkisyan Date: Wed, 10 Apr 2024 17:03:43 +0400 Subject: [PATCH 2/2] Update sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt Co-authored-by: Kamo Spertsyan --- .../android/sdk/internal/QProductCenterManager.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt index e910c40a..428a43ed 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/QProductCenterManager.kt @@ -663,11 +663,7 @@ internal class QProductCenterManager internal constructor( loadStoreProductsIfPossible() if (processingPurchases.isNotEmpty()) { - processingPurchases.forEach { - if (!handledPurchasesCache.shouldHandlePurchase(it)) { return@forEach } - - handledPurchasesCache.saveHandledPurchase(it) - } + handledPurchasesCache.saveHandledPurchases(processingPurchases) billingService.consumePurchases(processingPurchases.toList()) processingPurchases = emptyList()