[Solved] IAP purchase "lost" when multiple accounts used

Hi, I am getting reports, that people are loosing their purchased items in my apps. After a lot of investigstion, the issue was narrowed down to the following: when IAP purchase is triggered via Unity Purchasing, it is processed correctly and everything is fine, however when the app data is cleared (app reinstall), the purchases are not always restored on app start! It looks like with single account they are restored correctly every time, but with multiple accounts the behavior is somehow random - sometimes Unity Purchasing is picking the right account, sometimes not.

Can I somehow specify from which google account the purchases are restored with Unity Purchasing? It would be even better to be able to do so from all added accounts, is this possible somehow?

This is affecting live players.

@kraskon ,

Unity Purchasing will only restore items for the account that originally purchased them.

We have had reports of users purchasing a product with one account and then uninstalling and re-installing with a different account. The products will not be carried over in that case. That is expected behavior for Unity IAP.

There also may be issues with the Google Play store with multiple accounts. There is a discussion thread on the Google Play Help Forum about issues with multiple account and IAP. It’s possible that user’s are expecting to use one account for IAP, but Google will default to another.

https://productforums.google.com/forum/#!topic/play/jmyM0Sgl_jM

There are some workarounds in that thread to resolve that issue, if your user’s are experiencing that issue.

1 Like

@ap-unity Thank you for the prompt reply.

Yes, I came across this thread while searching for solutions, it seems the issue is rather old.

How does Unity Purchasing pick which Google account to use?

Installing the app with the currently selected does not seem to work. I understand there is a severe issue on Google side, but it would be great if there was a way to switch accounts on Unity side - so that the players can select at least account per game.

You should get a dropdown menu that will allow you to select from the accounts that are on the device.
2936648--217215--googleplay-multiple.png

I think the Google Play Help Forum post was concerning which account is the default one shown. Unity IAP has no control over that.

Just to confirm:

  1. Unity Purchasing can pick in which account to put the purchased item during order fulfillment?
  2. Once the order is completed, on game start Unity Purchasing has no control which account is used - so if the purchase is done with the non-default google account, the purchase will never be picked on game start?

Are those correct?
If 2 is correct, any way to overcome this - on game start, not during purchase?

Thanks!

No. Google Play handles which account is used for the purchase. Users with multiple accounts installed are given a dropdown menu so they can choose which account to use. The screenshot is what Google Play pops up when you try to purchase an item. Sorry for any confusion.

Once the order is complete, on game start Unity Purchasing will use the same account that the purchase was made with and only that account.

I will check with our QA team and see if their testing setup has any scenarios for devices with multiple accounts. The expected behavior is that a purchase will only restore for an account that made the original purchase.

If you have any evidence that this is not the case, we would be very appreciative of getting any details (receipts, etc.)

  1. Thank you, this is clear now.

  2. In my experience this is not the behavior of Unity Purchasing. It seems, that on start always the default Google account is used. If the purchase is done with a non-default Google account, there seems to be no (easy) way to restore the purchase.

I wanted to open new topic, but it seems like my issue fits here. So here it is (I am implementing non-consumable (no ads) purchasing on Android):

  1. Log in to google account (if you weren’t) and open the game
  2. Purchase item
  3. Collapse game (don’t exit, but collapse - it is important) and in the background run into another google account that doesn’t have had purchased this item
  4. Return to game
  5. And then if you’ll get product.hasReceipt it will still return TRUE instead of ‘false’ for another user. It turns out that locally changing user is kind of way to hack purchasing. But! if you’ll exit game and open it again - everything will be okay - hasReceipt will return false.

Here is some logs:

(Open game)

I/UnityIAP: Billing service connected.
I/Unity: OnInitialized: PASS
I/Unity: checking receipts: True //It is because I’m already own this item
I/Unity: Validation succeed! //Validating product receipt in the ProcessPurchase
I/Unity: ProcessPurchase: PASS. Product: NO_ADS
I/UnityIAP: Finish transaction:akenmi…

(Login to other google account in the background)

I/UnityIAP: Billing service disconnected.
I/UnityIAP: Releasing billing service.

My code here is
void OnApplicationFocus( bool hasFocus )
{
if (hasFocus)
{
if (m_StoreController == null)
{
InitializePurchasing ();
}
}
else
{
m_StoreController = null;
}
}

(Return to game)

I/UnityIAP: Billing service connected.
I/Unity: OnInitialized: PASS
I/Unity: Already recorded transaction akenmi… //here where is I’m confused
I/UnityIAP: Finish transaction:akenmi…

Please reply something) I’m just newbie, and it is high possibility that my understandig of IAP processing is wrong.

@vas1990

This is an interesting edge case, but I don’t think it will be a serious vulnerability. It sounds like the user will still have to purchase the item and the item will only be shown incorrectly while the app is running.

Also, we don’t recommend using the hasReceipt field to check if a user owns an item, as that is not the intended functionality and it may change or be removed at some point. Unity IAP does not handle inventory management. We encourage you to determine the inventory management solution that is best suited for your app.

1 Like

Thanks for reply!

Yeah, I did some management by using PlayerPrefs, but the thing is that I store item depending on current user and when I change user in the background it returns Already recorded transaction (or smthg like that) anyway, until I exit the game. Actually

I’m agree with you and I think this is very rare case so I’m decided to leave it like this to be sure that I don’t make it worser))