I am testing the refund workflow for my in-app purchases. I am verifying the purchase receipt using the Google Play Developer API https://developers.google.com/android-publisher/api-ref/purchases/products/get. If a user has asked for a refund of the purchase, this API returns the purchaseState as 1 which is correct. At that point, I remove the purchase from my app and the user can no longer avail the benefits of the in-app purchase. But now if a user wants to buy the in-app purchase again, I get the Item already owned error while buying it.
I am not sure how to allow the user to buy the in-app purchase again. I can consume the item once the purchase is reported as canceled in which case I don't get the Item already owned error but I don't think that would be the correct thing to do though.
Please let me know how to handle this use-case.
I am facing a critical edge case on my app. I will try to explain the situation.
I have an app which offers some premium content via in-app purchase. The user has one email id associated with Play Store on his device.
Here is the scenario:
1) The user logins in to the app using abc#gmail.com and purchases the premium content. This person has never purchased the premium content so his "isPremiumPurchased flag is false.
The purchase is successful and I grant him the premium content and change the flag to true. Works as expected.
2) The user logs out of his account in my app and logs in to my app again using a different account, say xyz#gmail.com. He goes on to purchase the premium content again. This account is a different account so his "isPremiumPurchased" flag is false.
This user has a separate account from the previous one, right? But if he tries to purchase, I always get "Item Already Owned", which is expected as well. The item was purchased already by another account associated with the same Play Store address, and now this account cannot purchase it.
What should the be ideal way to handle this scenario? I should not allow the second account to have access to the premium content. This is a completely separate account, isn't it? I cannot even consume the item. How can I solve this problem
If you want to differentiate the purchase based on the email used in your app, the purchase must be asociated to the email used to login to your app. I am not sure, but you can use developerPayload parameter for this.
Purchase:
iabHelper.launchPurchaseFlow(activity, SKU1, RC_REQUEST, purchaseListener, current_email);
Validation:
private boolean validateDeveloperPayload(Purchase purchaseDetails) {
String payload = purchaseDetails.getDeveloperPayload();
if(payload.equals(current_email)){
return true;
}
return false;
}
Very Simple. In app Purchases are associated with the primary account in Google Play store.
Say, you have an account myaccount#gmail.com associated to Google Play Store.
Here is the scenario:
1) The user logins in to the app using abc#gmail.com and purchases the
premium content. This person has never purchased the premium content
so his "isPremiumPurchased flag is false.
The purchase is successful and I grant him the premium content and
change the flag to true. Works as expected.
The premium content purchase is associated with myaccount#gmail.com not with abc#gmail.com which is local to your app.
2) The user logs out of his account in my app and logs in to my app
again using a different account, say xyz#gmail.com. He goes on to
purchase the premium content again. This account is a different
account so his "isPremiumPurchased" flag is false.
This user has a separate account from the previous one, right? But if
he tries to purchase, I always get "Item Already Owned", which is
expected as well.
The user logs out from yor app not from the Google Play. Thus when you check the purchse state of premium item, Google play responds you as it is purchased.
The item was purchased already by another account
associated with the same Play Store address, and now this account
cannot purchase it.
Please make sure where the account are being switched, is it inside your app or Google accounts?
Here is a small brief;
Download & Install app from playstore with account 'xxx#gmail.com', Purchase an item.
Add google accounts in device 'yyy#gmail.com' in which the item purchase not yet done.
Switch playstore to the account yyy#gmail.com and test item.
Item is in PURCHASE state only.
The account with which the app is downloaded is treated as PRIMARY ACCOUNT to check with purchase details from playstore
Download & Install app from playstore with account 'xxx#gmail.com', Purchase an item.
Add google accounts in device 'yyy#gmail.com' in which the item purchase not yet done.
Switch playstore to the account yyy#gmail.com and test item.
Item is in PURCHASE state only.
Remove account, xxx#gmail.com from the device, and check the item.
Item is in UNPURCHASED state.
Since 'xxx#gmail.com' is removed, primary account is 'yyy#gmail.com'.
Now the IN APP ITEMS for 'yyy#gmail.com' are not purchased.
I got my current app in test with some items to testpurchase. And I´ve done that now but I need to do further testing on those items. Is there a way to simply "restore" those purchases so that I dont get that error "You already own this item" ?
There is a way:
Once an in-app product is purchased, it is considered to be "owned".
In-app products in the "owned" state cannot be purchased from Google
Play. You must send a consumption request for the "owned" in-app
product before Google Play makes it available for purchase again.
Consuming the in-app product reverts it to the "unowned" state, and
discards the previous purchase data.
I have an application and I am trying to understand in-app billing. I want to do this : If a user buys an item with in-app billing. user can use this item with same account in different device without paying again. So my scenerio is this:
Assume that I have a application and it has in-app billing V3 service. And then a user purchases an "Managed Product" item and the user has an another device then the user wants to install this purcashed item in other device without paying again. But I read here, people talk about this problem:
BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED
At this point I am thinking to consume this product as soon as it is purchased. with this code:
mHelper.consumeAsync(inventory.getPurchase(SKU_MY_ITEM), mConsumeFinishedListener);
if it right way. what will the user see after clicking buy button in another device.(is it possible free purchase)
Also I am not sure what will happen, if the user uninstall and install again my app. what will user see if click a buy button. (purchase again or free purchase or a ERROR)
Can you give advice about in app-billing service for 1 account and many device and also about what will see a user if try to purchase in another device even everything goes right.
From here http://developer.android.com/google/play/billing/api.html :
Managed In-app Products
Managed in-app products are items that have their ownership
information tracked and managed by Google Play. When a user purchases
a managed in-app item, Google Play stores the purchase information for
each item on a per-user basis. This enables you to later query Google
Play at any time to restore the state of the items a specific user has
purchased. This information is persistent on the Google Play servers
even if the user uninstalls the application or if they change devices.
What you want to do is ( like in the example app ) query the inventory on successful setup of your in app service and consume any managed item thus granting access to it.
I have a product which a user can buy multiple times. Therefore I consume the purchase just after the purchase.
But then the purchase isn't listed in the GetPurchase method from the IInAppBillingService.aidl. Is it a problem on my end?
If a user uninstalls and reinstalls the app I would like to know wether the user bought the in-app product before. Do I need to use a different method of checking instead of using 'consume'? If I don't consume the purchase, it is listed in the GetPurchase method.