Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Can I restore former Items without adding former products when do UnityPurchasing.Initialize()?

Discussion in 'Unity IAP' started by yoppon, Dec 27, 2018.

  1. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    13
    I changed shop item lineups, but I want to enable to restore former Subscription/NonConsumable items.

    Can I restore former Subscription/NonConsumable Items even if I do
    UnityPurchasing.Initialize() 
    only with new products?

    Or I must add former products with new items when
    UnityPurchasing.Initialize() 
    ?

    (in iOS/Android)
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,130
  3. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    13
    Sorry for multiposting. Thank you for the information of FetchAdditionalProducts! I'll try this.
     
  4. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    13
    I want to ask one more question.

    If I add new Items in store dev console after UnityIAP is already once initialized,
    can't I get new products by
    instance_of_IStoreController.products.WithID(productId)

    until I call
    FetchAdditionalProducts()
    ?

    I would appreciate your reply.
     
  5. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    13
    To spell out my situation,
    I'm wondering which code below is the right way to do
    FetchAdditionalProducts()
    to reflect newly added shop items.

    1) If
    instance_of_IStoreController.products.WithID(productId)
    doesn't reflect newly added shop items until
    FetchAdditionalProducts()
    , i think this code results lacking of newly added items.
    Code (CSharp):
    1. ProductDefinition currentProducts = new HashSet<ProductDefinition>();
    2. foreach (ShopItem item in currentShopItemInfos_in_my_server) {
    3.     Product currentProduct =  StoreController.products.WithID(item.itemProductId)
    4.     if (currentProduct != null) {
    5.         currentProducts.Add(currentProduct.definition);
    6.     }
    7. }
    8.  
    9. if (currentProducts.Count > 0) {
    10.     storeController.FetchAdditionalProducts(currentProducts, success_callback, failure_callback);
    11. }
    OR

    2)
    Code (CSharp):
    1. ProductDefinition currentProducts = new HashSet<ProductDefinition>();
    2. foreach (ShopItem item in currentShopItemInfos_in_my_server) {
    3.     currentProducts.Add(new ProductDefinition(item.itemProductId, item.itemProductType));
    4. }
    5.  
    6. if (currentProducts.Count > 0) {
    7.     storeController.FetchAdditionalProducts(currentProducts, success_callback, failure_callback);
    8. }
     
    Last edited: Jan 9, 2019
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    3,130
    Make sure you fully test your code. Products would not be in your controller until you fetch them.
     
  7. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    13
    I got it! Thank you for your advice.
     
  8. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    13
    Please tell me one more.

    On
    FetchAdditionalProducts()
    is called in iOS,
    will an appleID password input dialog appear?

    Sorry I can't test on device now..