Skip to content

Commit

Permalink
Added null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
britzl committed Feb 6, 2023
1 parent f97a7ee commit d74c97d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 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 @@ -362,9 +362,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 @@ -413,7 +417,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 @@ -435,10 +444,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 @@ -485,9 +496,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
2 changes: 1 addition & 1 deletion game.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ target_sdk_version = 29

[project]
title = extension-iap
dependencies = https://github.com/andsve/dirtylarry/archive/master.zip
dependencies#0 = https://github.com/andsve/dirtylarry/archive/master.zip

[library]
include_dirs = extension-iap
Expand Down

0 comments on commit d74c97d

Please sign in to comment.