Hello! I have a game with IAP and server side account functional (user data like token saved with PlayerPrefs). So, when i buy product “A” for account “1”, close and reinstall application (ProcessPurchase return Pending for this product) and login in account “B”, product “1” for account “A” buying for account “B”. How i can associate product with server side account?
Sorry I don’t quite follow. Account A is purchasing a product for Account B? That’s not possible, purchases are associated with the user account on the phone. How are you switching accounts on the phone? It’s the user logged into the Google Play App on the phone.
I switch account inside unity application. I have mysql DB and php server side scripts were I generate token for each user account. I not change google or apple account
Yes that won’t work. For security, you won’t be able to do that with Unity IAP (which uses the Google Billing Library on Android and Apple Storekit on iOS). It’s enforced by Google and Apple, not us.
And what should I do?
You will need to make a decision based on these facts. You can’t switch users in the app and expect IAP to function. It will appear to always be charged to User A. To be clear, we are discussing virtual products offered for sale created on your Google developer dashboard and Apple Connect where game users pay for product (like buying “50 Gold Coins” with an actual credit card). https://docs.unity3d.com/Manual/UnityIAPGoogleConfiguration.html and https://docs.unity3d.com/Manual/UnityIAPAppleConfiguration.html . Some Android devices allow you to configure multiple accounts on the device, but the user needs to manually switch accounts for security under Settings, outside of your app. More common and on iOS, you generally need to reset your phone to switch users.
Do you typically hand your phone to someone else to play a game on to make purchases on with their credit card, or vice versa? It’s not common, perhaps in a family situation. But to your initial question, if you have a SINGLE user, and you want to securely store their purchase history in the cloud, you can check out PlayFab or ChilliConnect.