InAppBilling v3 IabResult Response Code BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED

Following the docs on the developer site, I recently applied InAppBilling v3 in my application. I have used the classes in the utils package provided in the TRIVIAL DRIVE example .

The problem I am facing is that the user has already purchased the app product already when starting the purchase flow again on another device, the play store dialog shows ITEM ALREADY SAVED , but the response code returned by IabResult does not match the IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED constant . The response code returned is actually one of the error codes in the IabHelper class (-1005 User canceled).

I would really love to know how I can get the actual response code instead of the error code. Any help would be greatly appreciated.

Below is the callback code

// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener =
        new IabHelper.OnIabPurchaseFinishedListener() {
            public void onIabPurchaseFinished(IabResult result, Purchase purchase) {

                if (result.isFailure()) {
                    if (result.getResponse() ==
                            IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                        //already owned
                        boolean isPremium = true;
                        SharedPrefsUtils.setPremium(BaseActivity.this, isPremium);
                        EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium));
                        //setWaitScreen(false);
                        return;
                    }
                    //handle error
                    complain(result.getResponse() + " " + "Error purchasing: " + result);
                    //setWaitScreen(false);
                    return;
                }
                if (!verifyDeveloperPayload(purchase)) {
                    //corrupted
                    complain("Error purchasing. Authenticity verification failed.");
                    //setWaitScreen(false);
                    return;
                }

                //successful
                if (purchase.getSku().equals(NO_ADS_PRODUCT_ID)) {
                    // bought the premium upgrade!
                    alert("Thank you for upgrading to premium!");
                    boolean isPremium = true;
                    SharedPrefsUtils.setPremium(BaseActivity.this, isPremium);
                    EventBus.getDefault().post(new InAppBillingUiUpdateEvent(isPremium));
                    //setWaitScreen(false);
                }
            }
        }; 

      

+3


source to share


1 answer


I finally managed to find the problem in the IabHelper code , so here it appears whenever the Activity.RESULT_CANCELED result code is returned in handleActivityResult . > the IabResult method for all such cases is committed with the user canceled (-1005) regardless of the reason. So to get the correct actual response code, replace the following code in handleActivityResult

 else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(IABHELPER_USER_CANCELLED, "User canceled.");
        if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
    }

      

with this



 else if (resultCode == Activity.RESULT_CANCELED) {
        logDebug("Purchase canceled - Response: " + getResponseDesc(responseCode));
        result = new IabResult(responseCode, null);
        if (mPurchaseListener != null) mPurchaseListener.onIabPurchaseFinished(result, null);
    }

      

hope this saves time

+4


source







All Articles