diff --git a/extension-iap/src/java/com/defold/iap/IapGooglePlay.java b/extension-iap/src/java/com/defold/iap/IapGooglePlay.java index 2ac57b7..1d366b4 100644 --- a/extension-iap/src/java/com/defold/iap/IapGooglePlay.java +++ b/extension-iap/src/java/com/defold/iap/IapGooglePlay.java @@ -376,9 +376,13 @@ public void onConsumeResponse(BillingResult billingResult, String purchaseToken) */ @Override public void onPurchasesUpdated(BillingResult billingResult, List purchases) { - if (billingResult.getResponseCode() == BillingResponseCode.OK && purchases != null) { - for (Purchase purchase : purchases) { - handlePurchase(purchase, this.purchaseListener); + if (billingResult.getResponseCode() == BillingResponseCode.OK) { + if (purchases != null && !purchases.isEmpty()) { + for (Purchase purchase : purchases) { + if (purchase != null) { + handlePurchase(purchase, this.purchaseListener); + } + } } } else { @@ -427,7 +431,12 @@ public void buy(final String product, final String token, final IPurchaseListene @Override public void onProductDetailsResponse(BillingResult billingResult, List productDetailsList) { if (billingResult.getResponseCode() == BillingResponseCode.OK && (productDetailsList != null) && !productDetailsList.isEmpty()) { - buyProduct(productDetailsList.get(0), token, purchaseListener); + for (ProductDetails productDetails : productDetailsList) { + if (productDetails != null) { + buyProduct(productDetails, token, purchaseListener); + break; + } + } } else { Log.e(TAG, "Unable to get product details before buying: " + billingResult.getDebugMessage()); @@ -449,10 +458,12 @@ private void queryProductDetailsAsync(final List productList, final Prod @Override public void onProductDetailsResponse(BillingResult billingResult, List productDetails) { - if (productDetails != null) { + if (productDetails != null && !productDetails.isEmpty()) { // cache products (cache will be used to speed up buying) for (ProductDetails pd : productDetails) { - IapGooglePlay.this.products.put(pd.getProductId(), pd); + if (pd != null) { + IapGooglePlay.this.products.put(pd.getProductId(), pd); + } } // add to list of all product details allProductDetails.addAll(productDetails); @@ -499,9 +510,11 @@ public void listItems(final String products, final IListProductsListener product @Override public void onProductDetailsResponse(BillingResult billingResult, List productDetails) { JSONArray a = new JSONArray(); - if (billingResult.getResponseCode() == BillingResponseCode.OK) { + if ((billingResult.getResponseCode() == BillingResponseCode.OK) && (productDetails != null) && !productDetails.isEmpty()) { for (ProductDetails pd : productDetails) { - a.put(convertProductDetails(pd)); + if (pd != null) { + a.put(convertProductDetails(pd)); + } } } else {