Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Solved] In-App Purchase Restoring/Saving understanding

Discussion in 'Unity IAP' started by boowman, Mar 5, 2017.

Thread Status:
Not open for further replies.
  1. boowman

    boowman

    Joined:
    Jan 3, 2014
    Posts:
    57
    Hello Everyone, as the title says I am trying to understand those things so I can implement them in my game.
    I followed this tutorial to add all the products: https://unity3d.com/learn/tutorials/topics/ads-analytics/integrating-unity-iap-your-game

    Everything went smoothly and was implemented and when I click the buy button in-game I get the google window to pay for it (it is in testing for now)
    In my game I have a few types of skins like "Common"(£0.5), "Rare"(£0.75) and "Epic"(£1.0) and I have around 30 skins. When I buy one skins I call BuyCommonItems() and so on.

    When I do that I receive the item so it works and my questions start now.
    1. Do I have to save the items myself?
    2. How does it know what items to give the player when the app is re-installed?
    3. Was I supposed to make a product for each skin rather than use "Common" for 10 skins etc?


    Code (CSharp):
    1.    
    2.     public static string Common_Items = "common_items";
    3.     public static string Flag_Items = "flag_items";
    4.     public static string Rare_Items = "rare_items";
    5.     public static string Epic_Items = "epic_items";
    6.  
    7.     public void InitializePurchasing()
    8.     {
    9.         if (IsInitialized())
    10.         {
    11.             return;
    12.         }
    13.  
    14.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    15.      
    16.         builder.AddProduct(Common_Items, ProductType.Consumable);
    17.         builder.AddProduct(Flag_Items, ProductType.Consumable);
    18.         builder.AddProduct(Rare_Items, ProductType.Consumable);
    19.         builder.AddProduct(Epic_Items, ProductType.Consumable);
    20.  
    21.         UnityPurchasing.Initialize(this, builder);
    22.     }
    23.  
    24.     public void BuyCommonItems()
    25.     {
    26.         BuyProductID(Common_Items);
    27.     }
    28.  
    29.     public void BuyFlagItems()
    30.     {
    31.         BuyProductID(Flag_Items);
    32.     }
    33.  
    34.     public void BuyRareItems()
    35.     {
    36.         BuyProductID(Rare_Items);
    37.     }
    38.  
    39.     public void BuyEpicItems()
    40.     {
    41.         BuyProductID(Epic_Items);
    42.     }
    43.  
     
  2. cdarklock

    cdarklock

    Joined:
    Jan 3, 2016
    Posts:
    455
    I am not 100% sure about this, but I am also wondering the same thing so I have been doing some research. And on line 177 of the Purchaser.cs script on the link you shared here, there is a meaningful comment:

    Code (csharp):
    1.  
    2. // We are not running on an Apple device. No work is necessary to restore purchases.
    3.  
    So I am guessing that whenever the IAP component initialises, it uses the player and app IDs to obtain a list of valid purchases from the service, provided this isn't an Apple device. Which would suggest that the saving and loading of purchases is automagically handled for you behind the scenes, too.

    Again, I don't really know what I'm talking about, so it would be nice if someone who does would chime in. ;)
     
  3. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @boowman, @cdarklock

    Yes, Unity IAP does not have any inventory management features. It is simply a wrapper for multiple store APIs. We leave it up to the developer to decide the best way to manage inventory in their game.

    Typically, app stores will grant non-consumable and subscription purchases to users that re-install your app. So after the purchasing system is initialized, Product Restoration can happen. (For Google Play, this happens automatically and ProcessPurchase is called for every non-consumable and subscription. For iOS, this requires a Restore Purchases button, which will also call ProcessPurchase.)

    This is 100% up to your preference and how you want to manage your products.
     
  4. boowman

    boowman

    Joined:
    Jan 3, 2014
    Posts:
    57
    In my app I am using consumable items, does that mean it won't be able to restore the purchases?

    The reason why I asked is because all my items are consumable and I am using the same plan for a lot of items. I was thinking that when it would come to restore them it would get confused because loads of items used the same plan.
     
  5. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @boowman

    It wouldn't be supported by the app store's receipt, but you could configure a system yourself, though this would likely require a user ID system and a server log of what items were purchased.
     
Thread Status:
Not open for further replies.