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

Handling IllegalStateException in case of mutiple Buy method call #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/android/WizPurchase.java
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ private int returnErrorCode(int error) {
else if (error == -1008) errorCode = UNKNOWN_ERROR;
else if (error == -1009) errorCode = NO_SUBSCRIPTIONS;
else if (error == -1010) errorCode = INVALID_CONSUMPTION;
else if (error == -1011) errorCode = INVALID_TRANSACTION_STATE;
else if (error == 1) errorCode = USER_CANCELLED;
else if (error == 2) errorCode = UNKNOWN_ERROR;
else if (error == 3) errorCode = CANNOT_PURCHASE;
Expand Down
14 changes: 13 additions & 1 deletion src/android/com/smartmobilesoftware/util/IabHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public class IabHelper {
public static final int IABHELPER_UNKNOWN_ERROR = -1008;
public static final int IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE = -1009;
public static final int IABHELPER_INVALID_CONSUMPTION = -1010;
public static final int IABHELPER_OPERATION_IN_PROGRESS = -1011;

// Keys for the responses from InAppBillingService
public static final String RESPONSE_CODE = "RESPONSE_CODE";
Expand Down Expand Up @@ -370,8 +371,19 @@ public void launchPurchaseFlow(Activity act, String sku, String itemType, int re
OnIabPurchaseFinishedListener listener, String extraData) {
checkNotDisposed();
checkSetupDone("launchPurchaseFlow");
flagStartAsync("launchPurchaseFlow");

IabResult result;
try {
flagStartAsync("launchPurchaseFlow");
}
catch (IllegalStateException e) {
logWarn("IllegalStateException while launching purchase flow for sku " + sku);
e.printStackTrace();

result = new IabResult(IABHELPER_OPERATION_IN_PROGRESS, "Async operation already in progress");
if (listener != null) listener.onIabPurchaseFinished(result, null);
return;
}

if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
Expand Down