mirror of
https://github.com/defold/extension-iap
synced 2025-06-27 02:17:51 +02:00
Merge pull request #58 from defold/Issue-47-index-out-of-bounds-exception
Added product and purchase null checks
This commit is contained in:
commit
649a8a1ebf
@ -376,9 +376,13 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
|
public void onPurchasesUpdated(BillingResult billingResult, List<Purchase> purchases) {
|
||||||
if (billingResult.getResponseCode() == BillingResponseCode.OK && purchases != null) {
|
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
|
||||||
for (Purchase purchase : purchases) {
|
if (purchases != null && !purchases.isEmpty()) {
|
||||||
handlePurchase(purchase, this.purchaseListener);
|
for (Purchase purchase : purchases) {
|
||||||
|
if (purchase != null) {
|
||||||
|
handlePurchase(purchase, this.purchaseListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -427,7 +431,12 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetailsList) {
|
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetailsList) {
|
||||||
if (billingResult.getResponseCode() == BillingResponseCode.OK && (productDetailsList != null) && !productDetailsList.isEmpty()) {
|
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 {
|
else {
|
||||||
Log.e(TAG, "Unable to get product details before buying: " + billingResult.getDebugMessage());
|
Log.e(TAG, "Unable to get product details before buying: " + billingResult.getDebugMessage());
|
||||||
@ -449,10 +458,12 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
|
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)
|
// cache products (cache will be used to speed up buying)
|
||||||
for (ProductDetails pd : productDetails) {
|
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
|
// add to list of all product details
|
||||||
allProductDetails.addAll(productDetails);
|
allProductDetails.addAll(productDetails);
|
||||||
@ -499,9 +510,11 @@ public class IapGooglePlay implements PurchasesUpdatedListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
|
public void onProductDetailsResponse(BillingResult billingResult, List<ProductDetails> productDetails) {
|
||||||
JSONArray a = new JSONArray();
|
JSONArray a = new JSONArray();
|
||||||
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
|
if ((billingResult.getResponseCode() == BillingResponseCode.OK) && (productDetails != null) && !productDetails.isEmpty()) {
|
||||||
for (ProductDetails pd : productDetails) {
|
for (ProductDetails pd : productDetails) {
|
||||||
a.put(convertProductDetails(pd));
|
if (pd != null) {
|
||||||
|
a.put(convertProductDetails(pd));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user