In-App purchase V3 item you requested not available - android

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 :-
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"

Related

Intent failed with Canceled on SpeechFactory.fromSubscription (LUIS azure, android sdk)

I am getting the following message when trying to analyze an utterance with LUIS using the cognitive service android SDK:
Final result received: Intent failed with Canceled. Did you enter your Language Understanding subscription? WebSocket Upgrade failed with an authentication error (403). Please check the subscription key or the authorization token, and the region name., intent:
I am able to get an utterance evaluation via REST using the same Subscription key , and App ID passed to the SpeechFactory methods.
Moreover, continuous recognition through the Android SDK works as well.
Anyone is getting my same issue ?
source available at https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/master/samples/java/android/sdkdemo/app/src/main/java/com/microsoft/cognitiveservices/speech/samples/sdkdemo/MainActivity.java .
Code here:
recognizeIntentButton.setOnClickListener(view -> {
final String logTag = "intent";
final ArrayList<String> content = new ArrayList<>();
disableButtons();
clearTextBox();
content.add("");
content.add("");
try {
final SpeechFactory intentFactory = SpeechFactory.fromSubscription(LanguageUnderstandingSubscriptionKey, LanguageUnderstandingServiceRegion);
final IntentRecognizer reco = intentFactory.createIntentRecognizerWithStream(createMicrophoneStream());
LanguageUnderstandingModel intentModel = LanguageUnderstandingModel.fromAppId(LanguageUnderstandingAppId);
for (Map.Entry<String, String> entry : intentIdMap.entrySet()) {
reco.addIntent(entry.getKey(), intentModel, entry.getValue());
}
reco.IntermediateResultReceived.addEventListener((o, intentRecognitionResultEventArgs) -> {
final String s = intentRecognitionResultEventArgs.getResult().getText();
Log.i(logTag, "Intermediate result received: " + s);
content.set(0, s);
setRecognizedText(TextUtils.join(System.lineSeparator(), content));
});
final Future<IntentRecognitionResult> task = reco.recognizeAsync();
setOnTaskCompletedListener(task, result -> {
Log.i(logTag, "Continuous recognition stopped.");
String s = result.getText();
if (result.getReason() != RecognitionStatus.Recognized) {
s = "Intent failed with " + result.getReason() + ". Did you enter your Language Understanding subscription?" + System.lineSeparator() + result.getErrorDetails();
}
String intentId = result.getIntentId();
String intent = "";
if (intentIdMap.containsKey(intentId)) {
intent = intentIdMap.get(intentId);
}
Log.i(logTag, "Final result received: " + s + ", intent: " + intent);
content.set(0, s);
content.set(1, " [intent: " + intent + "]");
setRecognizedText(TextUtils.join(System.lineSeparator(), content));
enableButtons();
});
} catch (Exception ex) {
System.out.println(ex.getMessage());
displayException(ex);
}
});
}

Unable to test In App Subscription

I couldn't find a way to test InApp Subscription with the test product ID by google i.e. private final String productID = "android.test.purchased"; // Test Product ID by Google
In the docs it is not written anywhere that InAPP subscription couldn't be tested with test product nor it is mentioned anywhere,how to test InApp subscription.
I have implemented my code following docs(InAppV3).
The doc says:
Implementing Subscriptions:
Launching a purchase flow for a subscription is similar to launching the purchase flow for a product, with the exception that the product type must be set to "subs". The purchase result is delivered to your Activity's onActivityResult method, exactly as in the case of in-app products.
and I have also implemented that properly.
My app is working if I replace "inapp" with "subs",i.e. it is working perfectly for products and not for subscriptions.
When I change "inapp" to "subs" then the purchase is returning:
09-24 14:01:12.943: I/(16929): isBillingSupported() - success : return 0
09-24 14:01:12.943: D/Finsky(2598): [281] InAppBillingUtils.getPreferredAccount: com.kgandroid.inappsubscriptiondemo: Account from first account - [MOn42QuZgF98vxJi0p3wAN3rfzQ]
09-24 14:01:12.943: I/(16929): getPurchases() - success return Bundle
09-24 14:01:12.943: I/(16929): getPurchases() - "RESPONSE_CODE" return 0
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_ITEM_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_PURCHASE_DATA_LIST" return []
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_DATA_SIGNATURE" return null
09-24 14:01:12.943: I/(16929): getPurchases() - "INAPP_CONTINUATION_TOKEN" return null
As you can see no details for android.test.purchased is returning.The test inapp purchase dialog is also not opening.
The relevant purchase code(Though it is not related to the problem I guess):
void purchase()
{
if (!blnBind) return;
if (mService == null) return;
ArrayList<String> skuList = new ArrayList<String>();
skuList.add(productID);
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("ITEM_ID_LIST", skuList);
Bundle skuDetails;
try {
skuDetails = mService.getSkuDetails(3, getPackageName(), "subs", querySkus);
System.out.println(skuDetails);
Toast.makeText(context, "getSkuDetails() - success return Bundle", Toast.LENGTH_SHORT).show();
Log.i(tag, "getSkuDetails() - success return Bundle");
} catch (RemoteException e) {
e.printStackTrace();
Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getSkuDetails() - fail!");
return;
}
int response = skuDetails.getInt("RESPONSE_CODE");
Toast.makeText(context, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getSkuDetails() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) return;
ArrayList<String> responseList = skuDetails.getStringArrayList("DETAILS_LIST");
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\" return " + responseList.toString());
if (responseList.size() == 0) return;
for (String thisResponse : responseList) {
try {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String title = object.getString("title");
String price = object.getString("price");
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"productId\" return " + sku);
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"title\" return " + title);
Log.i(tag, "getSkuDetails() - \"DETAILS_LIST\":\"price\" return " + price);
if (!sku.equals(productID)) continue;
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), sku, "subs", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
Toast.makeText(context, "getBuyIntent() - success return Bundle", Toast.LENGTH_SHORT).show();
Log.i(tag, "getBuyIntent() - success return Bundle");
response = buyIntentBundle.getInt("RESPONSE_CODE");
//Toast.makeText(context, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response), Toast.LENGTH_SHORT).show();
Log.i(tag, "getBuyIntent() - \"RESPONSE_CODE\" return " + String.valueOf(response));
if (response != 0) continue;
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), 0, 0, 0);
} catch (JSONException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
//Toast.makeText(context, "getSkuDetails() - fail!", Toast.LENGTH_SHORT).show();
Log.w(tag, "getBuyIntent() - fail!");
} catch (SendIntentException e) {
e.printStackTrace();
}
}
}
Does subscription supports test purchases??
If not,how to test subscription??
If yes,why google is returning null??
Any related docs or links will be also helpful.
I've never tried testing subs using the Test Product ID ("android.test.purchased") and I'm not sure it would work as seems to be a Product ID not a Subscription ID. I use real subscription IDs (that I create on Google Play Developer Console), but I use an account other than my developer account (i.e. the one you use to publish the app).
If you go to https://play.google.com/apps/publish/ then click on Settings, you'll see a field called "Gmail accounts with testing access". You can type one or more gmail addresses for accounts with which you want to test your purchases. Any account added there that purchases a subscription will not be charged and subscriptions will last for 24 hours. (source: http://developer.android.com/google/play/billing/billing_testing.html and my own experience)
That works for me. Although I did seem to have found a bug: Trying to cancel an Android test subscription gives me a 500 response code
Good luck with your app!
Edit:
From Google Docs (http://developer.android.com/google/play/billing/billing_testing.html#billing-testing-test)
You cannot use your developer account to test the complete in-app
purchase process because Google payments does not let you buy items
from yourself.
Have you tried using another account?

Android inventory.getSkuDetails() returning null

Hi i'm trying to add in app purchases to my app i have set up my in app purchases on the developer console which are set to active i have then queried them which yesterday was working perfectly i retrieved all the details but today its coming back as null. the only thing that has changed is that i had to uninstall the app and re-run it. I have checked my skus both in the app and on the developer console which match exactly when i run IabHelper start setup i get a result of ok. And then i call IabHelper.QueryInventoryFinishedListener and that results back as being ok but when i try access anything from the inventory it comes back as null. does anyone know why? or if i'm doing some wrong in my code?
in my on Create();
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
Log.v("Menu", "Problem setting up In-app Billing: " + result);
}
// Hooray, IAB is fully set up!
Log.v("Menu", "INAPP BILLING SETUP COMPLETE: " + result);
ArrayList<String> skuList = new ArrayList<String> ();
skuList.add("myapp.consumable.inapppurchase_id_1");
skuList.add("myapp.consumable.inapppurchase_id_2");
skuList.add("myapp.consumable.inapppurchase_id_3");
skuList.add("myapp.permanant.inapppurchase_id_6");
skuArray = new JSONArray(skuList);
mHelper.queryInventoryAsync(true, skuList, mQueryFinishedListener);
}
});
Then i heres my code for the QueryListener
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
if (result.isFailure()) {
Log.v("Menu", "RESULT FALIURE");
return;
}
Log.v("Menu", "this +" + skuArray);
Log.v("Menu", "Inventory +" + inventory);
for(int i = 0; i < skuArray.length(); i++){
try {
String SKU = skuArray.getString(i);
if(inventory.getSkuDetails(SKU) != null){
Log.v("Menu", "SKU = " + SKU);
Log.v("Menu", "SKU" + SKU + "= " + inventory.getSkuDetails(SKU));
updateProductData("price",inventory.getSkuDetails(SKU).getPrice(),i);
updateProductData("id",inventory.getSkuDetails(SKU).getSku(),i);
}else{
Log.v("Menu", "SKU RETURNED NULL" + SKU);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
Ok i spoke to Google about this issue. And they say they have made changes which requires the apk to be published before adding in app purchases they recommend uploading the apk to alpha testing channel and published (not in draft mode).
Ill give it a try and feed back if it works
After I published my alpha apk to google play the billing started to work again.

Android InApp Billing v3, google play dialog not showing

I'm currently migrating IAB v2 to v3.
In v2, if you owned specific item that you try to buy, Google Play dialog shows "you already own this item" with red text color. In v3, i can get error response 5 (Item Already Owned) but Google Play dialog never show up to screen.
I'm using latest sample code IabHelper and it seems like returning with not starting intent if response is not 0.
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));
Is it possible to behavior same as v2? or should i create dialog saying with "already owned" in my App?
Is it possible to behavior same as v2? or should i create dialog saying with "already owned" in my App?
Yes, this issue has been reported and an update IAB v3 repository is available here.
The crash you mention is fixed with this repo.
Note:
As reported by Bruno Oliveira.

How to use nonce with Google in app billing api V3

I am trying to implement in app purchase in my android application. I am using In app billing API v3 for implementing IAP (in app purchase). For reference I am following Google provided trivialdrive sample. In launchPurchaseFlow method
public void launchPurchaseFlow(Activity act, String sku, String itemType, int requestCode,
OnIabPurchaseFinishedListener listener, String extraData) {
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.");
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));
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();
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();
result = new IabResult(IABHELPER_REMOTE_EXCEPTION, "Remote exception while starting purchase flow");
if (listener != null) listener.onIabPurchaseFinished(result, null);
}
}
In the above code getBuyIntent does not expect nonce, we have extradata in which we pass developerpayload (specific to each purchase item).
Here I am not able to figure out how to pass nonce as it was passed in API V2 and received as response on successful purchase. Is there no need of nonce in V3?
Thanks
When using IAB API v3, simply use the original JSON response you receive from Google Play and perform an OpenSSL verification on it, using the signature and public RSA.
It's best that you perform this check through your own API, as bundling the public RSA key inside your application is unsafe. Here's a PHP sample for this OpenSSL verification.
As that sample illustrates, it simply takes the parameters from the request: the response data and the signature and verifies it using the public key.
You only need to tamper with the original JSON data inside your app and on your API for purposes related to figuring out what the user bought, not for verifying the validity of the purchase itself.
So in short: don't worry about the nonce. IAB API v3 dropped it and you shouldn't concern yourself with its absence.
APIv3 returns orderId, which can be used as nonce to avoid replay attacks.

Categories

Resources