Purchasing Single In-App Item from Multiple Account Ambiguity - android

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.

Related

Android In-app subscription purchase with multiple user on a single device

I am developing an app with android in-app subscription purchase with a self login procedure, basically which means multiple user can use single device to access app. Everything works fine as long as i use a single user in my app, but as i logout and login another user and try to do a subscription purchase it either tells me you already have this subscription or changes my subscription to new requested subscription.
This happens because previous user had a subscription which is reflecting in this user, as subscriptions/purchases are associated with the primary play store account.
So How can i manage this situation with multiple user each with a same or different subscription on a single device? Is it possible ?
Thanks in advance for help.

Android In App Billing: Purchase Validation When Multiple Accounts Present In Google Play

I validate In-App Purchase upon app startup. The problem I am facing is when some users have multiple accounts in Google Play:
User makes a purchase with Account A
Time passes, and user logs in with Account B in GooglePlay
User re-opens the app after some time, purchase is no longer recognized as logged in with Account B
Logging back into Account A in Google Play solves the problem
I would like to successfully validate the purchase as long as 1 of the accounts on the device was used to made the purchase regardless of the account currently logged in in GooglePlay.
Is there a way to achieve this, to validate across all accounts on the device?
Change the criteria of validation. use the email-id and phones imei to validate, this is one of the way. or you can access accounts and check if the email-id is there or not to validate. hope you understood. its upto ur requirement. if the app is mobile based used imei. if it is plateform based i mean if it runs also in browser use email id

What should do for this Scenerio in-app billing

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.

Restoring consumable purchases

I use consumable purchases (user may buy one item many times, in my app it convert to digital good) and need ability to restore purchases in future.
I think, there is only way to do this is save user email on server side and when I need to restore purchases, I request user autorization thru Google Play Services, send email to server and restore all data.
It is possible to get user email by which the user makes a purchase after purchase flow?
Or, it may be, there is another method for restoring consumable purchases?
Authorization in the application is not desirable, even though it would solve all problems!
It is possible to get user email by which the user makes a purchase after purchase flow?
When a user purchases an in-app item, Google Wallet assigns the transaction a unique and permanent order number. Google Play provides that order number to you at the conclusion of the purchase flow, as the value of the orderId field of the PURCHASE_STATE_CHANGED intent.
In your app, you can use the order number as a general-purpose identifier for the in-app purchase transaction. After the purchase, you can use the order number as a means of tracking the transaction in reconciliation reports and for customer support.
see Working With Order Numbers for more information
My suggestion would be to link the user to the orderId.
I'm going to guess a few follow up questions you may have:
How to link the user to the orderId?
Probably a simple login / authentication. You could use their Google Account (every Android user has one) - see Android Account Manager. This is a nice approach since your application does not have to handle any passwords - yay!
I want the same user on another phone to get those purchases/user data...
Not really possible without a login - see above (or something to uniquely identify that user) that syncs user data from the cloud to the new/other device.
Or, it may be, there is another method for restoring consumable purchases?
You cannot restore a consumed purchase with Google IAP. Double check whether you want to be using non-consumable purchases instead :)
additional source: IAP v3 API documentation.

Does In App Billing support multiple accounts?

Does InApp billing (V2 or V3) works for a user who uses several accounts and makes the purchase with an account that isn't the primary one?
PD: Some explanation required, no simple Yes/No
In App Billing support multiple accounts reported as a bug in code.google, have a look at it
According to Mr.Sergej (posted in G+ android dev community) in-app products purchased with the first account won't be active anymore while using multiple user accounts!.
InApp billing just charges the user and tells your app whether it was successful or not. It is up to you to figure out how to give the user what they purchased.
You can...
toggle the SharedPreferences of the app to save their purchase. Obviously multiple people can use the same app on the same device with the purchase.
provide login functionality to save a purchase to a server, in case the user deletes the app or gets a new device.
Use one-time purchases to check whether the user has purchased previously. This won't carry over to several accounts on different devices/multiple-accounts-per-device.

Categories

Resources