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.
4 Answers
4
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.
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;
}
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.
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/
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?
– AndrewRyanThis 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?
– PuzzleBuilder