libgdx / gdx-pay

A libGDX cross-platform API for InApp purchasing.
Apache License 2.0
225 stars 83 forks source link

A NullPointerException when calling android.test.canceled #137

Closed klisiewicz closed 5 years ago

klisiewicz commented 7 years ago

Hi, I have encountered an error when testing a Google Play static response product

android.test.canceled

Basically in the V3GoogleInAppBillingService.GdxPayAsyncOperationResultListener the result code is = -1 which is considered as a valid response, but later in PurchaseResponseActivityResultConverter.convertToTransaction the operation String purchaseDataString = responseData.getStringExtra("INAPP_PURCHASE_DATA"); results in a null string.

This is the full stack trace: Caused by: java.lang.NullPointerException at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) at org.json.JSONTokener.nextValue(JSONTokener.java:94) at org.json.JSONObject.<init>(JSONObject.java:155) at org.json.JSONObject.<init>(JSONObject.java:172) at com.badlogic.gdx.pay.android.googleplay.billing.converter.InAppPurchaseDataToTransactionConverter.convertJSONPurchaseToTransaction(InAppPurchaseDataToTransactionConverter.java:27) at com.badlogic.gdx.pay.android.googleplay.billing.converter.PurchaseResponseActivityResultConverter.convertToTransaction(PurchaseResponseActivityResultConverter.java:27) at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService.convertPurchaseResponseDataToTransaction(V3GoogleInAppBillingService.java:255) at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService.access$300(V3GoogleInAppBillingService.java:39) at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService$2.handleResultOk(V3GoogleInAppBillingService.java:240) at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService$2.onEvent(V3GoogleInAppBillingService.java:225) at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService.onGdxPayActivityEvent(V3GoogleInAppBillingService.java:393) at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService.access$800(V3GoogleInAppBillingService.java:39) at com.badlogic.gdx.pay.android.googleplay.billing.V3GoogleInAppBillingService$V3GoogleInAppBillingServiceAndroidEventListener.onActivityResult(V3GoogleInAppBillingService.java:403) at com.badlogic.gdx.backends.android.AndroidApplication.onActivityResult(AndroidApplication.java:472)

Regards

keesvandieren commented 6 years ago

Can you create a PR for this? I can review it and commit it.

Thanks in advance!

piotr-j commented 6 years ago

Ive been investigating this and refunded issue. Best i can come up with is that that these things dont quite work as real purchases in these cases. This in addition to #163 could probably be solved by throwing JSONException when in app data is null. What do you think?

MrStahlfelge commented 5 years ago

As @keesvandieren said, we are willing to review PRs on this.

MrStahlfelge commented 5 years ago

Fixed with PR #188 and published with the latest 0.11.4-SNAPSHOT