Skip to content

Commit

Permalink
Fixing onProductPurchased not called immediately (for consumable SKUs)
Browse files Browse the repository at this point in the history
  • Loading branch information
a7madKaddour committed Jan 11, 2024
1 parent e5b9992 commit 6ef1486
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions iap/src/main/java/com/limurse/iap/BillingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6ef1486

Please sign in to comment.