Unity Services In-App Purchases: How to check if a user has bought a non-consumable product
I've recently activated in-app purchases (for Android and iOS) through Unity Services and walked through their tutorial (http://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game-beta?playlist=17123). Though it describes how consumable objects might be purchased, I'm not sure what to do with a non-consumable purchase.
I want to be able to communicate with the store when the user opens the game and find out which non-consumables they've purchased. Does Unity Services have a function for that? I could save the non-consumable purchase in PlayerPrefs right after user purchases clear, but PlayerPrefs doesn't seem secure.
Answer by Banderous · Feb 08, 2016 at 01:02 PM
To counter local IAP fraud you should use local receipt validation; you can validate the receipts Google Play gives you for each product (as in @Jabbah76's code above) or on Apple platforms you can validate and parse the App receipt to determine all the non-Consumables the user is entitled to.
We are working on a receipt validation library to assist with this, initially for Google Play and Apple stores. This will be shipped in a forthcoming update to our IAP store implementations, installable from the Editor IAP cloud service window.
Answer by Jabbah76 · Jan 15, 2016 at 11:27 AM
I just came across the same issue. I haven't tested it yet, but I think it can be done using the following code:
Product product = storeController.products.WithID(productId);
if (product != null && product.hasReceipt)
{
// Owned Non Consumables and Subscriptions should always have receipts.
// So here the Non Consumable product has already been bought.
itemBought = true;
}
In my experience—at least in the editor—the user retains a receipt after processing a restore or refund for an item. Is this true or is this only an editor thing?
This code appears to work when I run it in the Unity editor, but when I have one of my testers download the alpha, it doesn't always work. When they close and reopen the app, the above code is run to see if they still have the receipt, but for some reason it isn't working. The app works correctly when they first run it after an install, but stops working after closing it and re-opening. Is the storeController never initialized when they open it the second time, leading to a null pointer? Am I using this code for the right purpose? Has anyone else got it to work?
Answer by hawkzey · May 15, 2017 at 01:13 AM
You feel like you need to do something extra to perform the enabling of already purchased items but you don't.
When the app is deleted and downloaded or downloaded on a new phone, the IAP's back end process will call the ProcessPurchase Function you have specified from the IStoreListener class on each item being restored(this is saved internally on each players google account). So what ever code was executed for when the player originally bought the item is executed again, there for re-enabling it.
I would also like to inform that Consumable products have to be managed them selves as the app store does not keep track of if the player has purchased such things.
$$anonymous$$y app recovers the correct state when it's re-installed, as you say, but when it's simply closed and re-opened, the game state resets, and the new "pro" features are gone. The pro features are enabled whenever the purchase is made, or the app is re-installed, but I need to make the game state persist after the game is closed. Is there a function I can call when the game starts that performs the same actions as when it's reinstalled? $$anonymous$$aybe I'll try what Jabbah76 suggests above.
Answer by jacshon121 · Mar 01, 2018 at 09:47 AM
Here is how to View the Windows Store Purchase History
1- Launch Windows Store application directly by clicking on the Store icon or you can alternatively search for Store in the search box and launch it. 2- Wait while the store picks itself up and launches. 3- Now from the top portion of the Windows Store window, find your profile picture and click on it. If you haven’t set any profile picture, it will be the classic profile icon instead of your picture. A menu gets expanded out. Find Purchased option from the menu and click on. 4- Now you will be redirected to the Microsoft sign in page. You have to enter your Microsoft account credentials and click on the Sign in button when you are ready, to view your store purchase history. 5- Under the Payment & Billing tab, you can view your Windows Store purchase history. Look for a drop down menu that says View from. You can select the time period of the purchase history that you want to see, from this drop down menu. Once you are all set, click on search button. You can now view the purchased items along with their dates of purchases, the modes of payment and the amount that you have paid for every single item from the search results.
Source:- https://merabheja.com/view-windows-store-purchase-history/
Your answer
Follow this Question
Related Questions
IStoreListener Purchase vs Restore on Android and iOS 0 Answers
ios memory is much higher than android memory. 0 Answers
Namespace Gamecenter not found on Unity 2017.2 1 Answer
Read and save current git commit hash into script 1 Answer
[IAP] IOs Consumable pending when closing app during purchase 0 Answers