3

This question is very similar to Purchased subscription not returned in inventory & Android billing - error you own this item but the answers provided in them did not solve my problem.

I have the latest code from https://code.google.com/p/marketbilling/. My signed apk is installed on the device and is uploaded as a draft on the Play Store. My subscription purchase exists in Google Wallet Merchant Center and shows up in queryPurchases and queryInventoryAsync but it shows up as null in my PurchaseActivity.

This code is from queryPurchases method in IabHelper.java and displays purchase information:

        for (int i = 0; i < purchaseDataList.size(); ++i) {
            String purchaseData = purchaseDataList.get(i);
            String signature = signatureList.get(i);
            String sku = ownedSkus.get(i);

            logDebug("Purchase Data: "+purchaseData);

            if (Security.verifyPurchase(mSignatureBase64, purchaseData, signature)) {
                logDebug("Sku is owned: " + sku);
                Purchase purchase = new Purchase(itemType, purchaseData, signature);

                logDebug("Purchase Data: "+purchase);

                if (TextUtils.isEmpty(purchase.getToken())) {
                    logWarn("BUG: empty/null token!");
                    logDebug("Purchase data: " + purchaseData);
                }

                // Record ownership and token
                inv.addPurchase(purchase);

                logDebug("Get Purchase Data: "+ inv.getPurchase(sku));
            }
            else {
                logWarn("Purchase signature verification **FAILED**. Not adding item.");
                logDebug("   Purchase data: " + purchaseData);
                logDebug("   Signature: " + signature);
                verificationFailed = true;
            }
        }

This method "queryInventoryAsync" is from the IabHelper.java class and returns inventory information:

public void queryInventoryAsync(final boolean querySkuDetails,
                           final List<String> moreSkus,
                           final QueryInventoryFinishedListener listener) {
    final Handler handler = new Handler();
    checkNotDisposed();
    checkSetupDone("queryInventory");
    flagStartAsync("refresh inventory");
    (new Thread(new Runnable() {
        public void run() {
            IabResult result = new IabResult(BILLING_RESPONSE_RESULT_OK, "Inventory refresh successful.");
            Inventory inv = null;
            try {
                inv = queryInventory(querySkuDetails, moreSkus);
            }
            catch (IabException ex) {
                result = ex.getResult();
            }

            flagEndAsync();

            final IabResult result_f = result;
            final Inventory inv_f = inv;
            if (!mDisposed && listener != null) {
                handler.post(new Runnable() {
                    public void run() {
                        listener.onQueryInventoryFinished(result_f, inv_f);
                        logDebug("Result: "+ result_f.getResponse() + " inventory: "+ inv_f.getAllOwnedSkus().get(0));
                    }
                });
            }
        }
    })).start();
}

This is from my PurchaseActivity:

IabHelper.QueryInventoryFinishedListener mInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
    public void onQueryInventoryFinished(IabResult result, Inventory inventory) {

        // Is it a failure?
        if (result.isFailure()) {
            Log.i(TAG, "Failed to query inventory: " + result);
            return;
        }else{
            //This returns false
            Log.i(TAG, "Query inventory was successful: " + inventory.hasPurchase(sku)); 
        }

        // Do we have the premium upgrade?
        //This returns null
        Purchase premiumPurchase = inventory.getPurchase(sku);

Although queryPurchases and queryInventoryAsync show that a purchase exists for my device and email account, getPurchase(sku) shows Purchase as null and hasPurchase(sku) returns false.

Does anyone have any ideas why this is happening? Thanks!

Community
  • 1
  • 1
yprabhu
  • 199
  • 2
  • 9
  • 1
    are you sure that the app that you are launching is the signed app? with the same account? – Mun0n Mar 05 '14 at 17:08
  • @jmunoz Yes. I'm very sure. – yprabhu Mar 05 '14 at 17:16
  • Ok, just want to be sure of this fact. Did you try with the example app. I've tried with this sample app, upload it as a draft and check that it's working...later I've copied the lines that I've needed – Mun0n Mar 05 '14 at 18:28
  • Did you ever find the cause of this? I'm having a similar issue. I make a query for all sku details and then check if any of them are already purchased. If I make the call to get all details synchronously, it detects the purchased items. If I do it asynchronously, the call to getPurchase always returns null. – Benzino Apr 02 '14 at 13:08
  • @Benzino Make sure that you're passing the correct sku and that it is not null. In my case, there was a typo in the sku. – yprabhu Apr 14 '14 at 14:14

1 Answers1

1

I had the same problem and solved it in this way

  • Upload draft application as alpha or beta with some version code.
  • Login on device with account which has active subscription.
  • Install signed application on this device with same version as in alpha/beta release.
Zakharov Roman
  • 739
  • 3
  • 13
  • 31