I have working android project integrated with in app purchase.
now I created new application with different package name, added in app product with same sku in console.
now in android studio updated licence key with new app from console. Changed package name.
from all I understand it should work.
But I am not able to get sku detail on listner.
But the tab-listener is not giving detail of any sku.
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// Handle failure
}
else {
// now here inventory does not skus information
}
}
Publish your apk (alpha/ beta group) to make it work.
Related
I have a really strange problem with Google In-app billing API.
I want to get the details of my available subscriptions to show their localised price on the UI. I'm using the IabHelper to query the details of the SKUs I specify, but the result contains no products, but after I purchase the subscription it's working, even if I cancel the subscription then and reinstall the app.
Here is my code:
List<String> additionalSkus = new ArrayList<>();
for (Subscription subscription : subscriptions) {
additionalSkus.add(subscription.getSku());
}
iabHelper.queryInventoryAsync(true, additionalSkus, new IabHelper.QueryInventoryFinishedListener() {
#Override
public void onQueryInventoryFinished(IabResult result, Inventory inv) {
if (iabHelper == null || result.isFailure()) {
Log.i("subs", result.getMessage());
}
for (Subscription subscription : subscriptions) {
SkuDetails skuDetails = inv.getSkuDetails(subscription.getSku());
if (skuDetails != null) {
subscription.setLocalizedPrice(skuDetails.getPrice());
Log.i("subs", subscription.getLocalizedPrice());
}
}
}
});
I have everything set up right about the In-app billing process. My products are active, I have a published beta APK, I can even get the details of my managed products, and purchase managed products and subscriptions, but this isn't working.
If you're using the latest version of IabHelper class, you should note that the function arguments relevant to additional skus to query are split to moreItemSkus (PRODUCT skus) and moreSubsSkus (SUBSCRIPTIONS skus).
public void queryInventoryAsync(final boolean querySkuDetails, final List<String> moreItemSkus,
final List<String> moreSubsSkus, final QueryInventoryFinishedListener listener)
In your case, your call should be
iabHelper.queryInventoryAsync(true, null, additionalSkus, new IabHelper.QueryInventoryFinishedListener() ...
I am using Google's In-App Billing for my Android app.
I used the IabHelper class from Google's how to, as their billing seems extremely complicated.
My issue is I want to know if the purchase is successful or not. I think I'm following the process correctly, but in my logs I see a lot of users that get the upgrade, but whose purchase never shows up in my Google Play payments account. (i.e. they get the upgrade for free).
I'm logging the GP order ids, sometimes its a number like,
GPA.1234-5678-9123-1234
But sometimes its like,
1234567891234.1234567891234
Normally I think its the non GPA orders that don't get charged.
Also I think you can put an order through, then cancel it, and still get the upgrade?
How do you ensure the user really paid?
Code:
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, final Purchase purchase) {
if (result.isFailure()) {
showMessage("Google Billing Purchase Error");
return;
} else if (purchase.getSku().equals(sku)) {
IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
showMessage("Google Billing Error");
return;
} else {
if (inventory.hasPurchase(sku)) {
showMessage("Thank you for upgrading");
grantUpgrade();
// ** This line gets call, but no payment occurs.
}
}
}
};
mHelper.queryInventoryAsync(mReceivedInventoryListener);
}
}
};
mHelper.launchPurchaseFlow(this, sku, 10001, mPurchaseFinishedListener, "");
*** updated to check "inventory.hasPurchase(sku)" but still see users who get the upgrade but don't pay.
** maybe the users are using Freedom hack? Anyway to prevent this?
if (result.isFailure()) {
//If the user aborts or any other problems it will jump here
}
else {
//The user purchased some item, check out which it is
mIsPremium = inventory.hasPurchase(SKU_ANY_ITEM);
}
So concerning your question, this code already verify whether the user really purchased the item !
Purchase premiumPurchase = inventory.getPurchase(SKU);
boolean mIsPremium = (premiumPurchase != null
&& verifyDeveloperPayload(premiumPurchase));
if(mIsPremium){
...
}
The Google Play Store keeps track of purchases for you, so you shouldn't assume that just because a purchase was successful, the item will stay purchased. It's possible for a user to get a refund for a purchase. For this reason, you need to query the user's inventory every time you launch and adjust your grants appropriately. You would need to do this check anyways in order to support users that expect to have the grant when they switch to a new device or uninstall/reinstall the app.
I am testing my app with a managed item that I purchased.
Then I wanted to try to purchase the product with the same id again (with purchase flow). I therefore have cleared all play store data. After that I was able to purchase the product again.
Now I am wondering that if a user cleans the play store data accidentally (or looses his/her purchase for any other reason), will he/she then loose his/her purchase?
I didn't expect that behavior, because I thought that the purchase information is stored on google's remote servers.
Code example:
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (mHelper == null)
return;
if (result.isFailure()) {
// handle error here
return;
} else {
if (inventory.hasPurchase(PremiumUtils.SKU_AD_FREE)){
// User paid to remove the Ads - so hide 'em
hideAd();
}
else{
// Free user - annoy him with ads ;)
showAd();
}
return;
}
}
};
I am trying to test In App purchases for my android app:
I already read the android developer sites about testing and I already have worked successfully with the play stores build in test/fake product-items like android.test.purchased, android.test.canceled ...
Now I would like to test In App purchases with my own real products. Therefore I have specified my own products in the Google Play Store Developer Console.I also have added test account in LICENSE TESTING then I have published the app in beta. the version number and build number of the app publish in beta is the same to the app that I install on android device for testing.
I have compare base64EncodedPublicKey and is the same to Base64-encoded RSA public key to the app in the console.
Android device that I am using to purchase the item. I have reset the google play to have only one account that is the account that has been added already for testing in Android console. And I have added the test account to for the beta app that i have published. then I have download the app to my device.
My question is: i have already make everything as I read the android guideline and some tutorial. but why when I click button to buy the item, I have this error: This version of the application is not configured for billing through google play. check the help center for more information.
I have publish my app nearly two weak ago. but i still got this error.
Here is my code:
#Override
protected void onStart() {
super.onStart();
//Toast.makeText(DetailActivity.this, "On Start", Toast.LENGTH_SHORT).show();
String base64EncodedPublicKey ="";
mHelper = new IabHelper(this, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
#Override
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
Log.d(TAG, "In-app Billing setup failed: " + result);
Toast.makeText(DetailActivity.this, "Fail", Toast.LENGTH_SHORT).show();
} else {
Log.d(TAG, "In-app Billing is set up OK");
Toast.makeText(DetailActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data)
{
if (!mHelper.handleActivityResult(requestCode,resultCode, data)) {
super.onActivityResult(requestCode, resultCode, data);
}
}
public void buyMethod(View v){
//mHelper.launchPurchaseFlow(this, ITEM_SKU, 10001, mPurchaseFinishedListener, "storyone");
mHelper.queryInventoryAsync(mGotInventoryListener);
}
//make purchase payment
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener
= new IabHelper.OnIabPurchaseFinishedListener() {
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
if (result.isFailure()) {
Log.d(TAG, "Error purchasing: " + result);
Toast.makeText(DetailActivity.this, "Buy Fail", Toast.LENGTH_SHORT).show();
return;
}
else if (purchase.getSku().equals(ITEM_SKU)) {
//
Toast.makeText(DetailActivity.this, "Buy Success", Toast.LENGTH_SHORT).show();
}
}
};
//check use has already make payment
IabHelper.QueryInventoryFinishedListener mGotInventoryListener
= new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result,
Inventory inventory) {
if (result.isFailure()) {
// handle error here
}
else {
// does the user have the premium upgrade?
boolean mIsPremium = inventory.hasPurchase(ITEM_SKU);
if (mIsPremium){
Toast.makeText(DetailActivity.this, "You already buy this product", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(DetailActivity.this, "Not Yet buy this product", Toast.LENGTH_SHORT).show();
mHelper.launchPurchaseFlow(DetailActivity.this, ITEM_SKU, 10001, mPurchaseFinishedListener, "storyone");
}
// update UI accordingly
}
}
};
#Override
public void onDestroy() {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
You have to be a tester for this app, so you have to be listed in the beta test (or join the Google+ group for the test) AND have to enable the beta test for your account by going to the link given in Google Play developer console.
Furthermore, your application has to be signed with the same certificate as the one in the Play Store beta test, so try it with the same apk that you uploaded to Google Play (e.g. not a debug version, but the release version you uploaded).
Complete list of things required.
Prerequisites:
AndroidManifest must include "com.android.vending.BILLING" permission.
APK is built in release mode.
APK is signed with the release certificate(s).
APK is uploaded to alpha/beta distribution channel (previously - as a draft)
to the developer console at least once. (takes some time ~2h-24h).
IAB products are published and their status set to active.
Test account(s) is added in developer console.
Testing requirements:
Test APK has the same versionCode as the one uploaded to developer console.
Test APK is signed with the same certificate(s) as the one uploaded to
dev.console.
Test account (not developer) - is the main account on the device.
Test account is opted-in as a tester and it's linked to a valid payment method.
Original answer here
I am working on my first android app. I really learned a lot on stack overflow. But I with my current problem I did not find a solution yet.
I tried to implement "in app purchase". I did the following things:
1) In the developer console I uploaded a signed apk in alpha and beta test. I also added a test user to the account and for testing I am using that account. Additionally I added some "In app products(managed)" with the status active.
2) Like described on http://developer.android.com/training/in-app-billing/index.html I downloaded the necessary lib field, copied code from the example project TrivialDrive and followed all the steps which result to the coding:
// called when the app is started
public void setupConnectionToGooglePlay(final Context context) {
this.context = context;
mHelper = new IabHelper(context, base64EncodedPublicKey);
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh no, there was a problem. --> no error message shown to
// the user!
Toast.makeText(context, "No connection to google:" + result, Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "connection to google:" + result, Toast.LENGTH_LONG).show();
// If connection is established:
get List of all in App Purchase products
getListOfInAppPurchaseProducts();
}
}
});
}
When executing this part of code I get the result, that the connection was established successfully. Hence the method getListOfInAppPurchaseProducts() is called.
private void getListOfInAppPurchaseProducts() {
IabHelper.QueryInventoryFinishedListener mQueryFinishedListener = new IabHelper.QueryInventoryFinishedListener() {
public void onQueryInventoryFinished(IabResult result, Inventory inventory) {
if (result.isFailure()) {
// no error message is shown to the user
Toast.makeText(context, "Query not successful", Toast.LENGTH_LONG).show();
} else {
String message = result.getMessage();
boolean isSuccess = result.isSuccess();
// no success message is shown to the user
List<String> skus = inventory.getAllOwnedSkus();
Map<String,SkuDetails> map = inventory.getSKUMap();
int size = map.size();
Toast.makeText(
context,
"Message: " + message + "Query successful. Mapsize:" + size, Toast.LENGTH_LONG).show();
WMGooglePlayConnection.this.inventory = inventory;
}
}
};
ArrayList<String> list = new ArrayList<String>();
list.add("test");
list.add("test2");
mHelper.queryInventoryAsync(true, list, mQueryFinishedListener);
}
Unfortunately the returned inventory does not contain any SKU Details (even the query is successful). I checked the following:
productIds
status of the product ids (active)
base64EncodedPublicKey
For testing I used a real device (Samsung ACE 2). I copied the apk file directly to the device (not downloaded from google play). Can this be a problem?
Is it somehow possible to get the SKU Details also with the emulator?
Do you have any idea what I can check?
It would be really nice if someone could help me...
I just ran into this as well. Our in app billing stuff broke right around when Google Play Service 4.4 went out. A week or two back I think.
To get your in app billing products to show up now you'll have to publish your Alpha builds but have them only visible to people on your tester list/group.
After one publishes the app then testers can download it from the Google Play Store with a link similar to this.
https://play.google.com/apps/testing/
I hope this helps.