Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing nullpointer in bugsnag. #41

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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" });

}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 3 additions & 0 deletions extension/iap/IAPEvent.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IAProduct>;
Expand Down
11 changes: 10 additions & 1 deletion extension/iap/Inventory.hx
Original file line number Diff line number Diff line change
@@ -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}.
Expand Down Expand Up @@ -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);
}
}

}
18 changes: 17 additions & 1 deletion extension/iap/android/IAP.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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);

}

///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

Expand Down