From 6ef14862b49301139888b5ee2d2b6cab090a3f0e Mon Sep 17 00:00:00 2001 From: Ahmad Kaddour Date: Thu, 11 Jan 2024 18:59:12 +0300 Subject: [PATCH] Fixing onProductPurchased not called immediately (for consumable SKUs) --- iap/src/main/java/com/limurse/iap/BillingService.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/iap/src/main/java/com/limurse/iap/BillingService.kt b/iap/src/main/java/com/limurse/iap/BillingService.kt index 506edfa..2e82905 100644 --- a/iap/src/main/java/com/limurse/iap/BillingService.kt +++ b/iap/src/main/java/com/limurse/iap/BillingService.kt @@ -193,11 +193,12 @@ class BillingService( // Grant entitlement to the user. val productDetails = productDetails[purchase.products[0]] + val isProductConsumable = consumableKeys.contains(purchase.products[0]) when (productDetails?.productType) { BillingClient.ProductType.INAPP -> { // Consume the purchase when { - consumableKeys.contains(purchase.products[0]) -> { + isProductConsumable && purchase.purchaseState == Purchase.PurchaseState.PURCHASED -> { mBillingClient.consumeAsync( ConsumeParams.newBuilder() .setPurchaseToken(purchase.purchaseToken).build() @@ -227,7 +228,7 @@ class BillingService( } // If the state is PURCHASED, acknowledge the purchase if it hasn't been acknowledged yet. - if (!purchase.isAcknowledged && purchase.purchaseState == Purchase.PurchaseState.PURCHASED) { + if (!purchase.isAcknowledged && !isProductConsumable && purchase.purchaseState == Purchase.PurchaseState.PURCHASED) { val acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder() .setPurchaseToken(purchase.purchaseToken).build() mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, this)