0

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.

giff1
  • 101
  • 1
  • 12
  • Your question is a bit unclear. The title and description of in-app purchases are stored on their servers. The actual purchasing for 1-time purchases (non-consumables) such as removing ads are saved, but purchases that can be purchased multiple times (consumables) such as gems are not. The best practice is to store all of their data locally in some form yes. Google just knows you have some in-app purchases that costs [$some Amount] with the ID [yourID] that has the title [name] and the description [description]. – TEEBQNE Apr 22 '21 at 20:57
  • @TEEBQNE Okay so my consumable amount, 10 coins, isn't stored on Google but just the transaction. The actual 10 coins are things I would have to code in on my end, not pulling out from the server. If that's the case how to companies with in app purchases handle the actual amount of coins? PlayerPrefs are really changeable, so would it have to be binary saving? – giff1 Apr 22 '21 at 22:15
  • Exactly Google just handles that the transaction occurred, you need to then decide what happens after. If you mean PlayerPrefs are easily changed, then yes they are. Larger companies store all important data on servers and almost never trust local player data. There is no guaranteed way to protect any data locally. If your question is how you would save this data locally, then yes Player Prefs is an option. – TEEBQNE Apr 22 '21 at 22:22
  • Thank you so much for your reply. That answers my questions. – giff1 Apr 22 '21 at 22:46
  • Glad I could help. I might type up a more formal answer in a bit so the question can have an answer. – TEEBQNE Apr 22 '21 at 23:13
  • Added a more full answer in case you have any further questions. I am not sure what stage you are in implementing IAP, but hopefully, it helps a bit if you get stuck again. – TEEBQNE Apr 23 '21 at 00:33

1 Answers1

0

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.

TEEBQNE
  • 6,104
  • 3
  • 20
  • 37