简体   繁体   中英

In-App purchase V3 item you requested not available

I know this question is everywhere in Stack-overflow and there are many answers to this question but I am unable to resolve it. I have tried many answers but still not able to solve the issue, I know that I am doing some silly mistake somewhere in my code, can anyone help me out finding the issue?

Here is My screen-shot for in-app products :-

在此处输入图片说明

Declared permissions inside Manifest :-

 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="com.android.vending.BILLING" /> <uses-permission android:name="com.android.vending.CHECK_LICENSE" /> 

Defining SKU as :-

public static final String SKU1 = "gas"; public static final String SKU2 = "infinite_gas";

Purchase Method :-

public void launchPurchaseFlow(Activity act, String sku, String itemType,
        int requestCode, OnIabPurchaseFinishedListener listener,
        String extraData) {
    checkNotDisposed();
    checkSetupDone("launchPurchaseFlow");
    flagStartAsync("launchPurchaseFlow");
    IabResult result;

    if (itemType.equals(ITEM_TYPE_SUBS) && !mSubscriptionsSupported) {
        IabResult r = new IabResult(IABHELPER_SUBSCRIPTIONS_NOT_AVAILABLE,
                "Subscriptions are not available.");
        flagEndAsync();
        if (listener != null)
            listener.onIabPurchaseFinished(r, null);
        return;
    }
    try {
        logDebug("Constructing buy intent for " + sku + ", item type: "
                + itemType);
        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));
            flagEndAsync();
            result = new IabResult(response, "Unable to buy item");
            if (listener != null)
                listener.onIabPurchaseFinished(result, null);
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle
                .getParcelable(RESPONSE_BUY_INTENT);
        logDebug("Launching buy intent for " + sku + ". Request code: "
                + requestCode);
        mRequestCode = requestCode;
        mPurchaseListener = listener;
        mPurchasingItemType = itemType;
        act.startIntentSenderForResult(pendingIntent.getIntentSender(),
                requestCode, new Intent(), Integer.valueOf(0),
                Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        logError("SendIntentException while launching purchase flow for sku "
                + sku);
        e.printStackTrace();
        flagEndAsync();

        result = new IabResult(IABHELPER_SEND_INTENT_FAILED,
                "Failed to send intent.");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    } catch (RemoteException e) {
        logError("RemoteException while launching purchase flow for sku "
                + sku);
        e.printStackTrace();
        flagEndAsync();

        result = new IabResult(IABHELPER_REMOTE_EXCEPTION,
                "Remote exception while starting purchase flow");
        if (listener != null)
            listener.onIabPurchaseFinished(result, null);
    }
}

Bind Service Intent :-

Intent serviceIntent = new Intent(
                "com.android.vending.billing.InAppBillingService.BIND");
        serviceIntent.setPackage("com.android.vending");
        if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0)
                .isEmpty()) {
            // service available to handle that Intent
            mContext.bindService(serviceIntent, mServiceConn,
                    Context.BIND_AUTO_CREATE);

Consume Method :-

void consume(Purchase itemInfo) throws IabException {
        checkNotDisposed();
        checkSetupDone("consume");

        if (!itemInfo.mItemType.equals(ITEM_TYPE_INAPP)) {
            throw new IabException(IABHELPER_INVALID_CONSUMPTION,
                    "Items of type '" + itemInfo.mItemType
                            + "' can't be consumed.");
        }

        try {
            String token = itemInfo.getToken();
            String sku = itemInfo.getSku();
            if (token == null || token.equals("")) {
                logError("Can't consume " + sku + ". No token.");
                throw new IabException(IABHELPER_MISSING_TOKEN,
                        "PurchaseInfo is missing token for sku: " + sku + " "
                                + itemInfo);
            }

            logDebug("Consuming sku: " + sku + ", token: " + token);
            int response = mService.consumePurchase(3,
                    mContext.getPackageName(), token);
            if (response == BILLING_RESPONSE_RESULT_OK) {
                logDebug("Successfully consumed sku: " + sku);
            } else {
                logDebug("Error consuming consuming sku " + sku + ". "
                        + getResponseDesc(response));
                throw new IabException(response, "Error consuming sku " + sku);
            }
        } catch (RemoteException e) {
            throw new IabException(IABHELPER_REMOTE_EXCEPTION,
                    "Remote exception while consuming. PurchaseInfo: "
                            + itemInfo, e);
        }
    }

Error while purchasing :-

在此处输入图片说明

Note :- The Application in Alpha testing phase is published. Do i need to Approve my tester account from somewhere ?

Here are the whole process i do :-

  1. Uploaded the signed apk with release certificated to developer console. I have published my apk to alpha channel. I have listed my product Ids to developer console. I have activated my product Ids and on developer console it is marked as Active. I have listed the test account in developer console. I have installed the same apk that I uploaded to developer console to my deveice. The device is logged in with the test account not the developer account. The Id that I use in my app is same as I had listed on console as per logcat message.

Any help will be greatly appreciated

Thanks in advance.

yes , i solved the problem , i was missing with this last and very important step :-

Open opt-in url with test account and click on "Become a tester"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM