Upgrade subscriptions

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.

//Define subscription tiers
public static string subscriptionBasic = "subscription_basic";
public static string subscriptionAdvanced = "subscription_advanced";

//These are added to builder during initialization
builder.AddProduct(subscriptionBasic, ProductType.Subscription, new IDs(){
    { subscriptionBasic, AppleAppStore.Name },
    { subscriptionBasic, GooglePlay.Name },
});
builder.AddProduct(subscriptionAdvanced, ProductType.Subscription, new IDs(){
    { subscriptionAdvanced, AppleAppStore.Name },
    { subscriptionAdvanced, GooglePlay.Name },
});

//Method to upgrade from basic to advanced subscription tier
IGooglePlayStoreExtensions m_GooglePlayStoreExtensions;
m_GooglePlayStoreExtensions.GetExtension<IGooglePlayStoreExtensions>();
Product oldProduct = m_StoreController.products.WithID(subscriptionBasic);
Product newProduct = m_StoreController.products.WithID(subscriptionAdvanced);
Action<string, string> googlePlayCallback = new Action<string, string>(m_GooglePlayStoreExtensions.UpgradeDowngradeSubscription);
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?

1 Like

I switched out:

SubscriptionManager.UpdateSubscription(newProduct, oldProduct, "sampleDeveloperPayload", OnSubUpgradedApple, googlePlayCallback);

To:

SubscriptionManager.UpdateSubscriptionInGooglePlayStore(newProduct, oldProduct, googlePlayCallback);

Which resulted in the invalid receipt error below:
Logcat

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.Action2[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+EventFunction1[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.EventFunction1:Invoke(T1, BaseEventData) 05-17 09:01:41.703 20176 20201 I Unity : UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction1)
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…

1 Like

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?

1 Like

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.

Product newProduct = m_StoreController.products.WithID(subscriptionAdvanced);
Product oldProduct = m_StoreController.products.WithID(subscriptionBasic);

Action<string, string> googlePlayCallback = new Action<string, string>(m_GooglePlayStoreExtensions.UpgradeDowngradeSubscription);

SubscriptionManager.UpdateSubscription(newProduct, oldProduct, "sampleDeveloperPayload", OnSubUpgradedApple, googlePlayCallback);
3 Likes

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”.

  • i got that this is a variable of type IGooglePlayStoreExtentions but when I type this
  • " m_GooglePlayStoreExtensions.GetExtension();"
  • it says m_GooglePlayStoreExtensions do not have definition for GetExtention…
    can u help me out why am I getting this???

Please don’t mulitpost, I already answered in your other thread.