Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

UnityPurchasing.Initialize cannot pass initialization after completing purchase of subscription

Discussion in 'Unity IAP' started by seimitu, May 16, 2021.

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

    seimitu

    Joined:
    Nov 2, 2020
    Posts:
    6
    Sorry for the basic rudimentary question.

    The code below will pass the initialization.

    Code (CSharp):
    1.  public void InitializePurchasing() {
    2.         if (IsInitialized()) {
    3.             return;
    4.         }
    5.  
    6.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    7.  
    8.         builder.AddProduct(WEEKLYSUB, ProductType.Subscription);
    9.  
    10.         MyDebug("Initialization start...");
    11.  
    12.         UnityPurchasing.Initialize(this, builder);
    13.     }
    14.  
    15.  
    16.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
    17.         MyDebug("PASS");
    18.  
    19.         this.controller = controller;
    20.         this.extensions = extensions;
    21.  
    22.         m_AppleExtensions = extensions.GetExtension<IAppleExtensions>();
    23.         m_GoogleExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
    24.         m_GoogleExtensions?.SetDeferredPurchaseListener(OnPurchaseDeferred);
    25.  
    26.         //SUBSCRIPTION_MANAGER
    27.         Dictionary<string, string> dict = m_AppleExtensions.GetIntroductoryPriceDictionary();
    28.  
    29.         foreach (UnityEngine.Purchasing.Product item in controller.products.all) {
    30.             //SUBSCRIPTION_MANAGER
    31.             if (item.receipt != null) {
    32.                 string intro_json = (dict == null || !dict.ContainsKey(item.definition.storeSpecificId)) ? null : dict[item.definition.storeSpecificId];
    33.  
    34.                 if (item.definition.type == ProductType.Subscription) {
    35.                     SubscriptionManager p = new SubscriptionManager(item, intro_json);
    36.                     SubscriptionInfo info = p.getSubscriptionInfo();
    37.                 }
    38.             }
    39.         }
    40.     }

    Then buy subscription.
    Immediately after the purchase was completed, I was able to confirm the receipt with the code below.

    Code (CSharp):
    1.       foreach (UnityEngine.Purchasing.Product item in controller.products.all) {
    2.             if (item.receipt != null) {
    3.                 MyDebug("Product receipt found = " + item.definition.id.ToString());
    4.             } else {
    5.                 MyDebug("item.receipt == null");
    6.             }
    7.         }
    I was able to confirm the receipt in.

    However, when I restarted the app while continuing the purchased subscription, the initialization could not pass.

    Where is the problem?

    If you cancel your subscription, it will pass the initialization.

    I want to check the receipt after restarting the app.
    However, if you do not pass the initialization, you will not be able to confirm the receipt.
    Can the receipt be confirmed without passing the initialization?

    If you have purchased a subscription, you cannot purchase the subscription, so initialization will not pass. I think that's what it means.
     
  2. seimitu

    seimitu

    Joined:
    Nov 2, 2020
    Posts:
    6
    I want to get a receipt for a purchased subscription.
    If I know the product ID, can I get the purchased receipt without initializing it?
    I can't find the code in this case anywhere.
     
  3. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
Thread Status:
Not open for further replies.