Search Unity

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:
    17
    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

    Joined:
    May 2, 2017
    Posts:
    14,446
  3. yoppon

    yoppon

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

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    17
    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:
    17
    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

    Joined:
    May 2, 2017
    Posts:
    14,446
    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:
    17
    I got it! Thank you for your advice.
     
  8. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    17
    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..
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No
     
  10. yoppon

    yoppon

    Joined:
    Nov 19, 2016
    Posts:
    17
    Thank you!