Search code examples
unity-game-enginein-app-purchasegoogle-play-servicesgoogle-play-games

How do I get in-app purchases to show up to the player on Google Play


Sorry if this has been asked but I did my searching and couldn't find anything. It might be the way that I phrased it.

So I am making a mobile game with in-app purchases in Unity. I have successfully done this where it will take my money and tell me what I bought. But where I lack the knowledge is now how to I get that amount back to the player. So for example you pay .99 for 10 coins, now I want to display those 10 coins to the player. Is there an API call I can do that the server handles to show their 10 coins? If not would I just handle that in code with PlayerPrefs or Binary saving? Thank you for reading this and any help is greatly appreciated.


Solution

  • In case anyone else has the same issue here is a more concrete answer to the question.

    Google in-app purchases do not store what your in-app purchases do. They merely store various data such as Product Name, Product description, Product ID, Product Price, Last Updated, and Status. All of this data is editable in the Google Play Console under the In-app products tab.

    Using the Unity IAP you can easily integrate many store purchasing abilities such as Google. After properly setting up your App so it is at least in the Alpha Stage of release, it has been verified by Google, you have set up a Monetization account and you have uploaded an APK with the billing permissions, you will be able to add in-app purchase products.

    Once you have setup the products in the console, you can start implementing the IAP following Unity's tutorial. When a user does purchase a product, there will be a callback with the Product ID of what they purchased.

    When purchasing a product, there are various types of products, but for this post, I will only talk about Consumable and Non-Consumable purchases (the others are subscription-based). Consumable products are products that can be consumed after purchase and can be repurchased. Think of them as gems, energy, or some other resource in your game that can be depleted. Non-Consumable products are those which can not be used up and are always there for the player. Examples of this product can be removal of ads, a new game level, etc.

    Specifically for Google, receipts are kept on Google's end. When a user signs back in, the Unity IAP automatically will restore all purchases that fall under the Non-Consumable category if a user has a receipt for them. As for the Consumable products, you will need to keep track of them. I personally keep track of both just in case, I would rather not have a user lose any sort of purchased good. Google does however keep track of all receipts, so if you want, you can go through them yourself and verify purchases.

    To keep your data persistent, you will need to implement a Save/Load system. The easiest implementation would be to use PlayerPrefs, but they are very insecure. Any data on a local device is vulnerable to an attacker altering it as they have complete control over their data. There is a lot you can do to protect local data by using encryption, code obstruction and memory tracking, but a good enough hacker can simply decompile your APK and figure out what's going on. If you truly want to keep your data safe, use a server.