diff --git a/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java b/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java index d815b9b..e848f52 100644 --- a/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java +++ b/dependencies/android/src/org/haxe/extension/iap/InAppPurchase.java @@ -41,6 +41,7 @@ public void run() { } catch (Exception exception) { // see: https://github.com/openfl/extension-iap/issues/28 Log.e("IAP", "Failed to launch purchase flow.", exception); + InAppPurchase.callback.call("loggerCallback", new Object[] { "AndroidFailedToLaunchPurchaseFlow" }); mPurchaseFinishedListener.onIabPurchaseFinished( new IabResult(IabHelper.BILLING_RESPONSE_RESULT_ERROR, null), null); @@ -86,7 +87,9 @@ public static void queryInventory (final boolean querySkuDetails, String[] moreS public void run() { try { InAppPurchase.inAppPurchaseHelper.queryInventoryAsync(querySkuDetails, moreSkus, mGotInventoryListener); + InAppPurchase.callback.call("loggerCallback", new Object[] { "AndroidQueryInventorySuccessful" }); } catch(Exception e) { + InAppPurchase.callback.call("onQueryInventoryException", new Object[] { e.getMessage() }); Log.d("IAP", e.getMessage()); } } @@ -134,9 +137,7 @@ public void onIabSetupFinished (final IabResult result) { Extension.callbackHandler.post (new Runnable () { @Override public void run () { - InAppPurchase.callback.call ("onStarted", new Object[] { "Failure" }); - } }); diff --git a/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java b/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java index 417ce52..7af2551 100755 --- a/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java +++ b/dependencies/android/src/org/haxe/extension/iap/util/IabHelper.java @@ -403,7 +403,15 @@ public void launchPurchaseFlow(Activity act, String sku, String itemType, int re try { logDebug("Constructing buy intent for " + sku + ", item type: " + itemType); + // This is where it has a null pointer exception in our code base (source repo is slightly ahead) + if (mService == null || mContext == null) { + result = new IabResult(IABHELPER_SEND_INTENT_FAILED, "mService or mContext is null. Initialization was not correct"); + listener.onIabPurchaseFinished(result, null); + return; + } + Bundle buyIntentBundle = mService.getBuyIntent(3, mContext.getPackageName(), sku, itemType, extraData); + // int response = getResponseCodeFromBundle(buyIntentBundle); if (response != BILLING_RESPONSE_RESULT_OK) { logError("Unable to buy item, Error response: " + getResponseDesc(response)); diff --git a/extension/iap/IAPEvent.hx b/extension/iap/IAPEvent.hx index 7a7ce49..069bc10 100644 --- a/extension/iap/IAPEvent.hx +++ b/extension/iap/IAPEvent.hx @@ -24,6 +24,9 @@ class IAPEvent extends Event { public static inline var DOWNLOAD_COMPLETE = "downloadComplete"; public static inline var DOWNLOAD_START = "downloadStart"; public static inline var DOWNLOAD_PROGRESS = "downloadProgress"; + + public static inline var IAP_LOGGING_EVENT = "loggingEvent"; + public static inline var IAP_QUERY_INVENTORY_EXCEPTION = "queryInventoryException"; public var productID:String; public var productsData:Array; diff --git a/extension/iap/Inventory.hx b/extension/iap/Inventory.hx index 2922ed8..c0435bd 100644 --- a/extension/iap/Inventory.hx +++ b/extension/iap/Inventory.hx @@ -1,5 +1,8 @@ package extension.iap; +import extension.iap.IAP; +import extension.iap.IAPEvent; + /** * Represents a block of information about in-app items. * An Inventory is returned by such methods as {@link IAP#queryInventory}. @@ -71,7 +74,13 @@ class Inventory */ public function erasePurchase(productId:String) :Void { - if (purchaseMap.exists(productId)) purchaseMap.remove(productId); + if (purchaseMap.exists(productId)) { + purchaseMap.remove(productId); + } else { + var evt:IAPEvent = new IAPEvent (IAPEvent.IAP_LOGGING_EVENT, productId); + evt.message = "AndroidPaymentsProductIdNotFoundInPurchaseMap"; + IAP.dispatcher.dispatchEvent (evt); + } } } diff --git a/extension/iap/android/IAP.hx b/extension/iap/android/IAP.hx index 7a13b7a..dd21ce2 100644 --- a/extension/iap/android/IAP.hx +++ b/extension/iap/android/IAP.hx @@ -73,7 +73,6 @@ import openfl.utils.JNI; */ public static function initialize (publicKey:String = ""):Void { - if (funcInit == null) { funcInit = JNI.createStaticMethod ("org/haxe/extension/iap/InAppPurchase", "initialize", "(Ljava/lang/String;Lorg/haxe/lime/HaxeObject;)V"); } @@ -257,6 +256,23 @@ private class IAPHandler { IAP.dispatcher.dispatchEvent (evt); } + public function loggerCallback(response:String):Void { + var productID:String = ""; + productID = lastPurchaseRequest; //temporal fix + var evt:IAPEvent = new IAPEvent (IAPEvent.IAP_LOGGING_EVENT, productID); + evt.message = response; + IAP.dispatcher.dispatchEvent (evt); + } + + public function onQueryInventoryException(response:String):Void { + var productID:String = ""; + productID = lastPurchaseRequest; //temporal fix + var evt:IAPEvent = new IAPEvent (IAPEvent.IAP_QUERY_INVENTORY_EXCEPTION, productID); + evt.message = response; + IAP.dispatcher.dispatchEvent (evt); + + } + /////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////