Skip to content

Commit

Permalink
Merge pull request #58 from defold/Issue-47-index-out-of-bounds-excep…
Browse files Browse the repository at this point in the history
…tion

Added product and purchase null checks
  • Loading branch information
britzl authored Feb 7, 2023
2 parents 5c09447 + d74c97d commit 649a8a1
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions extension-iap/src/java/com/defold/iap/IapGooglePlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,13 @@ public void onConsumeResponse(BillingResult billingResult, String purchaseToken)
*/
@Override
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> 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 {
Expand Down Expand Up @@ -427,7 +431,12 @@ public void buy(final String product, final String token, final IPurchaseListene
@Override
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> 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());
Expand All @@ -449,10 +458,12 @@ private void queryProductDetailsAsync(final List<String> productList, final Prod

@Override
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> 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);
Expand Down Expand Up @@ -499,9 +510,11 @@ public void listItems(final String products, final IListProductsListener product
@Override
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> 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 {
Expand Down

0 comments on commit 649a8a1

Please sign in to comment.