Search Unity

Upgrade subscriptions

Discussion in 'Unity IAP' started by TheLastVertex, May 17, 2020.

  1. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    I'm having troubles finding any documentation regarding how to go about upgrading a subscription and any requirements needed. I have pieced together what I can from various threads but am still unable to get the basic upgrade functionality working on Android let alone attempt iOS yet.

    Code (CSharp):
    1.  
    2.  
    3. //Define subscription tiers
    4. public static string subscriptionBasic = "subscription_basic";
    5. public static string subscriptionAdvanced = "subscription_advanced";
    6.  
    7. //These are added to builder during initialization
    8. builder.AddProduct(subscriptionBasic, ProductType.Subscription, new IDs(){
    9.     { subscriptionBasic, AppleAppStore.Name },
    10.     { subscriptionBasic, GooglePlay.Name },
    11. });
    12. builder.AddProduct(subscriptionAdvanced, ProductType.Subscription, new IDs(){
    13.     { subscriptionAdvanced, AppleAppStore.Name },
    14.     { subscriptionAdvanced, GooglePlay.Name },
    15. });
    16.  
    17. //Method to upgrade from basic to advanced subscription tier
    18. IGooglePlayStoreExtensions m_GooglePlayStoreExtensions;
    19. m_GooglePlayStoreExtensions.GetExtension<IGooglePlayStoreExtensions>();
    20. Product oldProduct = m_StoreController.products.WithID(subscriptionBasic);
    21. Product newProduct = m_StoreController.products.WithID(subscriptionAdvanced);
    22. Action<string, string> googlePlayCallback = new Action<string, string>(m_GooglePlayStoreExtensions.UpgradeDowngradeSubscription);
    23. SubscriptionManager.UpdateSubscription(newProduct, oldProduct, "sampleDeveloperPayload", OnSubUpgradedApple, googlePlayCallback);
    Is this all that is needed? I'm attempting to upgrade/downgrade between 3 different tiers of subscriptions but I get one of the following issues.

    Testing on Android I start by successfully purchasing a basic subscription which shows up on Google Play under the subscription manager. Then using the above code I attempt to upgrade to the next tier and results in nothing, no errors, no logcat output, no prompt for purchase verification.

    On PC it states the store does not support subscription upgrades, though I'm assuming that is expected.

    What am I missing? Is that "sampleDeveloperPayload" suppose to be something?
     
    ertugoguz likes this.
  2. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    I switched out:
    Code (CSharp):
    1. SubscriptionManager.UpdateSubscription(newProduct, oldProduct, "sampleDeveloperPayload", OnSubUpgradedApple, googlePlayCallback);
    To:
    Code (CSharp):
    1. SubscriptionManager.UpdateSubscriptionInGooglePlayStore(newProduct, oldProduct, googlePlayCallback);  
    Which resulted in the invalid receipt error below:
    05-17 09:01:41.702 20176 20201 I Unity : Error: the product that will be updated does not have a valid receipt: UnityEngine.Purchasing.NullReceiptException: Exception of type 'UnityEngine.Purchasing.NullReceiptException' was thrown.
    05-17 09:01:41.702 20176 20201 I Unity : at UnityEngine.Purchasing.SubscriptionManager.getSubscriptionInfo () [0x00000] in <00000000000000000000000000000000>:0
    05-17 09:01:41.702 20176 20201 I Unity : at UnityEngine.Purchasing.SubscriptionManager.UpdateSubscriptionInGooglePlayStore (UnityEngine.Purchasing.Product oldProduct, UnityEngine.Purchasing.Product newProduct, System.Action`2[T1,T2] googlePlayUpdateCallback) [0x00000] in <00000000000000000000000000000000>:0
    05-17 09:01:41.702 20176 20201 I Unity : at CompleteProject.Qwerty_IAP_Manager.UpgradSubscriptionProductID (System.String productId) [0x00000] in <00000000000000000000000000000000>:0
    05-17 09:01:41.702 20176 20201 I Unity : at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    05-17 09:01:41.702 20176 20201 I Unity : at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    05-17 09:01:41.702 20176 20201 I Unity : at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (T1 handler, UnityEngine.Even
    05-17 09:01:41.703 20176 20201 I Unity : Upgrade - After Updatesubscription
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.Logger:Log(LogType, Object)
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.Events.UnityAction:Invoke()
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.Events.UnityEvent:Invoke()
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.EventSystems.EventFunction`1:Invoke(T1, BaseEventData)
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.EventSystems.StandaloneInputModule:processTouchPress(PointerEventData, Boolean, Boolean)
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.EventSystems.StandaloneInputModule:processTouchEvents()
    05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.EventSystems.StandaloneInputModule:process()
    05-17 09:01:41.703 20176 20201 I Unity :
    05-17 09:01:41.703 20176 20201 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
    05-17 09:01:41.703 20176 20201 I Unity :

    Whoops.... After looking at this closer it it appears UpdateSubscription() wants new product first while UpdateSubscriptionInGooglePlayStore() wants the inverse with the old product first.... Fun...

    Off to retest...
     
    ertugoguz likes this.
  3. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    Welp that solved the error but unfortunately I'm back to the same result as previous. Nothing. No confirmation, no prompt, no logs.

    Is there suppose to be something in that "googlePlayCallback" that I'm responsible for activating the new purchase perhaps?
     
    ertugoguz likes this.
  4. TheLastVertex

    TheLastVertex

    Joined:
    Sep 30, 2015
    Posts:
    126
    Aha! Finally!

    As part of adding in the subscriptions and corresponding upgrades I've been moving away from the CodelessIAP. Unfortunately there was still some codeless iap logic hanging around.

    I removed all IAPButtons from my scenes and set the IAP Catalog option to "Automatically initialize UnityPurchasing" to false. Double checked that the codeless iap was not being initialized when the app launches and tada! Subscription upgrades now work.

    Code (CSharp):
    1. Product newProduct = m_StoreController.products.WithID(subscriptionAdvanced);
    2. Product oldProduct = m_StoreController.products.WithID(subscriptionBasic);
    3.  
    4. Action<string, string> googlePlayCallback = new Action<string, string>(m_GooglePlayStoreExtensions.UpgradeDowngradeSubscription);
    5.  
    6. SubscriptionManager.UpdateSubscription(newProduct, oldProduct, "sampleDeveloperPayload", OnSubUpgradedApple, googlePlayCallback);
    7.  
     
  5. ashishdevden

    ashishdevden

    Joined:
    Oct 5, 2020
    Posts:
    17
    Hi,
    Can u please tell me what is "m_GooglePlayStoreExtensions" and how can I access it??
    to me, it's saying "m_GooglePlayStoreExtensions doesn't exist in the current context".
     
  6. ashishdevden

    ashishdevden

    Joined:
    Oct 5, 2020
    Posts:
    17
    1. i got that this is a variable of type IGooglePlayStoreExtentions but when I type this
    2. " m_GooglePlayStoreExtensions.GetExtension<IGooglePlayStoreExtensions>();"
    3. it says m_GooglePlayStoreExtensions do not have definition for GetExtention...
      can u help me out why am I getting this???
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please don't mulitpost, I already answered in your other thread.