Search Unity

iOS Subscription Upgrade / Downgrade

Discussion in 'Unity IAP' started by mradel, Jan 6, 2020.

  1. mradel

    mradel

    Joined:
    Jan 16, 2018
    Posts:
    10
    We have been trying to implement subscription upgrade/downgrade on iOS for using Unity IAP [1.23.0] without success.

    When subscribed on one of our subscription products (a monthly subscription) and trying to make a purchase on a second product (an annual subscription) from the same iOS group in iOS sandbox with IStoreController.InitiatePurchase, neither ProcessPurchase nor OnPurchaseFailed get called. We get stuck without being able to determine that the switch happened, although the subscription did change (as the ios auto_renew_product_id property of our receipt gets properly updated).

    This post suggests that there is another way to do subscription upgrade/downgrade with SubscriptionManager.UpdateSubscription but I have been unable to use it on iOS as it does not trigger the purchase process.

    How to properly implement subscription upgrade/downgrade on iOS with Unity IAP?
     
  2. SamOYUnity3D

    SamOYUnity3D

    Unity Technologies

    Joined:
    May 12, 2019
    Posts:
    626
    Have you tried using appleStoreCallback to process the purchase?
    Code (CSharp):
    1. IGooglePlayStoreExtensions m_GooglePlayStoreExtensions;
    2. m_GooglePlayStoreExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
    3. Product oldProduct = m_Controller.products.WithID("oldProductID");
    4. Product newProduct = m_Controller.products.WithID("newProductID");
    5. Action<string, string> googlePlayCallback = new Action<string, string>(m_GooglePlayStoreExtensions.UpgradeDowngradeSubscription);
    6. SubscriptionManager.UpdateSubscription(newProduct, oldProduct, "sampleDeveloperPayload", appleStoreCallback, googlePlayCallback);
     
  3. mradel

    mradel

    Joined:
    Jan 16, 2018
    Posts:
    10
    The above code does not show how to use it on iOS. There is no equivalent extension in IAppleExtensions. Am I supposed to initiate a purchase after the callback is called?
     
  4. unity_lhs6_n2ptSWzhw

    unity_lhs6_n2ptSWzhw

    Joined:
    Mar 18, 2020
    Posts:
    1
    I am confused about the same thing
    @JeffDUnity3D any update on this?
    @mradel did you make it work? or any work around? please help.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
  6. s-tang

    s-tang

    Joined:
    Jan 8, 2020
    Posts:
    10
    Hi, I would like to know this as well.

    I'm using version 2.2.1 for the core (the one from Package Manager), and version 2.2.5 for the package (the one from Services). Using them on Unity 2019.2.21f1.

    First purchase of a subscription has no issue, which I use
    _storeController.InitiatePurchase(product)

    to purchase.

    When I detected that I have an existing subscription from the same group, I would then handle it with
    HandleSubscriptionUpgrade
    .

    I tried 3 various methods, but none of them worked.

    1) calling
    SubscriptionManager.UpdateSubscriptionInAppleStore
    and do nothing with the appStoreUpdateCallback
    Code (CSharp):
    1. protected override void HandleSubscriptionUpgrade(Product oldProduct, Product newProduct)
    2.         {
    3.             SubscriptionManager.UpdateSubscriptionInAppleStore(newProduct, null,
    4.                 (newProductArg, unknownArg) => Debug.Logger.Write($"ZR SUB: {newProductArg.definition.id}, {unknownArg}"));
    5.         }
    It returned the appleStoreUpdateCallback, with only newProductArg.
    A native black transparent screen just stuck there, and I could no longer interact with my app.
    I could see that my app was not frozen though.
    Other than the native black screen, there was no native UI that show up like how it would be when you called
    _storeController.InitiatePurchase

    getProductId: (omitted).ads.plan1,

    getCancelDate: 0001/01/01 0:00:00

    getExpireDate: 2020/12/17 9:04:00

    getPurchaseDate: 2020/12/17 8:59:00

    getRemainingTime: 00:04:43.9027980

    isAutoRenewing: True

    isCancelled: False

    isExpired: False

    isFreeTrial: False

    isSubscribed: True

    UnityIAPWrapper:HandleSubscriptions Old Subscription ((omitted).ads.plan1, True)

    UnityIAPWrapper:HandleSubscriptions New Subscription ((omitted).ads.plan3, False)

    ZR SUB: (omitted).ads.plan3,



    2) calling
    SubscriptionManager.UpdateSubscriptionInAppleStore
    and then call
    _storeController.InitiatePurchase(product)
    during the appleStoreUpdateCallback
    Code (CSharp):
    1.  
    2.         protected override void HandleSubscriptionUpgrade(Product oldProduct, Product newProduct)
    3.         {
    4.             SubscriptionManager.UpdateSubscriptionInAppleStore(newProduct, null, (newProductArg, unknownArg) =>
    5.                 _storeController.InitiatePurchase(newProductArg));
    6.         }
    This would return me error saying its a duplicate transaction.
    The transaction ID is indeed the same as the old subscription purchased.
    The new subscription was never succeeded.
    And I'm not sure why is there a google message at the bottom.
    getProductId: (omitted).ads.plan1,

    getCancelDate: 0001/01/01 0:00:00

    getExpireDate: 2020/12/17 8:37:23

    getPurchaseDate: 2020/12/17 8:32:23

    getRemainingTime: 00:04:31.3692750

    isAutoRenewing: True

    isCancelled: False

    isExpired: False

    isFreeTrial: False

    isSubscribed: True

    UnityIAPWrapper:HandleSubscriptions Old Subscription ((omitted).ads.plan1, True)

    UnityIAPWrapper:HandleSubscriptions New Subscription ((omitted).ads.plan3, False)

    2020-12-17 17:32:51.631714+0900 sikaq[5706:4385522] UnityIAP: PurchaseProduct: (omitted).ads.plan3

    purchase({0}): (omitted).ads.plan3

    2020-12-17 17:32:51.647538+0900 sikaq[5706:4385522] UnityIAP: UpdatedTransactions

    ...
    (omitted)
    ...


    2020-12-17 17:33:33.943237+0900 sikaq[5706:4385522] UnityIAP: UpdatedTransactions

    2020-12-17 17:33:33.943452+0900 sikaq[5706:4385522] UnityIAP: DuplicateTransaction error with product (omitted).ads.plan3 and transactionId 1000000(omitted)

    2020-12-17 17:33:33.944888+0900 sikaq[5706:4388132] - <Google>[I-ACS023141] Purchase is a duplicate and will not be reported. Product ID: (omitted).ads.plan3

    onPurchaseFailedEvent({0}): productId:(omitted).ads.plan3 message:Duplicate transaction occurred

    Failed to purchase (omitted).ads.plan3

    Error: DuplicateTransaction



    3) call
    _storeController.InitiatePurchase(product)
    without going through
    SubscriptionManager.UpdateSubscriptionInAppleStore

    Code (CSharp):
    1.  
    2.         protected override void HandleSubscriptionUpgrade(Product oldProduct, Product newProduct)
    3.         {
    4.             _storeController.InitiatePurchase(newProduct);
    5.         }
    This resulted the same as method 2.
    getProductId: (omitted).ads.plan1,

    getCancelDate: 0001/01/01 0:00:00

    getExpireDate: 2020/12/17 8:10:13

    getPurchaseDate: 2020/12/17 8:05:13

    getRemainingTime: 00:04:29.6287660

    isAutoRenewing: True

    isCancelled: False

    isExpired: False

    isFreeTrial: False

    isSubscribed: True

    UnityIAPWrapper:HandleSubscriptions Old Subscription ((omitted).ads.plan1, True)

    UnityIAPWrapper:HandleSubscriptions New Subscription ((omitted).ads.plan3, False)

    2020-12-17 17:05:43.372177+0900 sikaq[5660:4376061] UnityIAP: PurchaseProduct: (omitted).ads.plan3

    purchase({0}): (omitted).ads.plan3

    2020-12-17 17:05:43.388351+0900 sikaq[5660:4376061] UnityIAP: UpdatedTransactions

    ...
    (omitted)
    ...


    2020-12-17 17:06:22.099442+0900 sikaq[5660:4376061] UnityIAP: UpdatedTransactions

    2020-12-17 17:06:22.099597+0900 sikaq[5660:4376061] UnityIAP: DuplicateTransaction error with product (omitted).ads.plan3 and transactionId 1000000(omitted)

    2020-12-17 17:06:22.100925+0900 sikaq[5660:4377823] - <Google>[I-ACS023141] Purchase is a duplicate and will not be reported. Product ID: (omitted).ads.plan3

    onPurchaseFailedEvent({0}): productId:(omitted).ads.plan3 message:Duplicate transaction occurred

    Failed to purchase (omitted).ads.plan3

    Error: DuplicateTransaction
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @s-tang You shared this code, can you share where this flow is documented? I'm not familar "calling SubscriptionManager.UpdateSubscriptionInAppleStore and then call _storeController.InitiatePurchase(product) during the appleStoreUpdateCallback." The UpdateSubscription call should handle the new purchase
     
  8. s-tang

    s-tang

    Joined:
    Jan 8, 2020
    Posts:
    10
    @JeffDUnity3D It wasn't from any documentation. I was just trying it out, since Method 1 (just by calling
    UpdateSubscriptionInAppleStore
    ) doesn't worked.

    I just tried calling
    UpdateSubscription 
    . It failed with the same result of my Method 1.

    Code (CSharp):
    1.  
    2.         protected override void HandleSubscriptionUpgrade(Product oldProduct, Product newProduct)
    3.         {
    4.             SubscriptionManager.UpdateSubscription(newProduct, oldProduct, null,
    5.                                    (newProductArg, unknownArg) => Debug.Logger.Write($"ZR SUB: {newProductArg.definition.id}, {unknownArg}"),
    6.                                    null);
    7.         }
    Only a native black semi-transparent screen overlay on top of my app.
    Nothing else related to the subscription happens.
    The app still runs, but I can't do anything with it, since the native overlay screen is blocking my input to the app.

    Am I missing something? Like do I need to enter anything for the developerPayload parameter? I'm not entirely sure what should go in there, hence the null.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @s-tang We are looking into this and will hopefully have an answer early next year. I need to test this.
     
  10. John_Corbett

    John_Corbett

    Joined:
    May 17, 2019
    Posts:
    151
    Hello everyone,

    We don't have a proper Upgrade/Downgrade feature for iOS, as @mradel mentioned, we don't have it in IAppleExtensions.

    It looks like we could make something based off a quick pass or research, it is supported on the native side: https://developer.apple.com/app-store/subscriptions/#ranking
    https://developer.apple.com/documen.../handling_subscriptions_billing?language=objc
    https://forum.unity.com/threads/ios-subscription-upgrade-downgrade.804687/#post-6635218

    We could also make it including code to handle cancellation, such as: https://stackoverflow.com/a/58595211

    We're going to add a feature to do this on our backlog.

    Sorry for the inconvenience that we don't support this at this time, thanks for pointing it out, as we want to keep making our API better in the future.
     
  11. s-tang

    s-tang

    Joined:
    Jan 8, 2020
    Posts:
    10
    This is disappointing. I wasted 2 weeks trying to figure out how to use UnityIAP, without a proper updated documentation. I had to read through a whole bunch of threads, tons of trials and errors.

    I understand this may not be your fault, but it would be appreciate that if there's a proper centralized updated documentation. And mention what features are not yet supported, so we can choose to adapt the plugin or not.

    Its really a pain to use UnityIAP with a lot of information unknown. Its already version 2, yet it feel like a version 0...

    I'm sorry if this feel like a rant, but its frustrating.
     
    nicholasr likes this.
  12. John_Corbett

    John_Corbett

    Joined:
    May 17, 2019
    Posts:
    151
    hi @s-tang,

    Sorry for the inconvenience our documentation being out of date. We're aware of the situation and we'll be working on updating the documentation soon.
     
  13. unitylicense19

    unitylicense19

    Joined:
    Aug 29, 2018
    Posts:
    32
    Any update on this, when unity might support this feature, Any work around found for this by anyone?
     
  14. primebit

    primebit

    Joined:
    Jun 24, 2015
    Posts:
    14
    Hi everyone,
    I'm trying to implement those upgrades but it's not going well. Has anyone found a working solution to this problem?
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you share the code you are using and any errors you might be receiving? What version of IAP?
     
  16. GastonC

    GastonC

    Joined:
    Aug 26, 2012
    Posts:
    38
    I'm having the same issue doing this
    Code (CSharp):
    1. SubscriptionManager.UpdateSubscriptionInAppleStore(newProduct, null, (newProductArg, unknownArg) =>
    2.                 _storeController.InitiatePurchase(newProductArg));
    Is there anything to perform upgrade/downgrade?
     
  17. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We are still working on this to comply with Google Billing Library v4 and StoreKit2. Hopefully we will have more information later in Q1
     
  18. bkachmar

    bkachmar

    Joined:
    Mar 15, 2013
    Posts:
    43
    Any updates on this?
     
  19. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Unfortunately this work has been delayed. Current ETA is Q3
     
  20. kickassqc

    kickassqc

    Joined:
    Jul 7, 2015
    Posts:
    4
    Still planned for Q3?
     
  21. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, that is still the plan.
     
  22. conondev

    conondev

    Joined:
    Jun 9, 2016
    Posts:
    24
    Any workaround for this please?
     
  23. idoben

    idoben

    Joined:
    Sep 6, 2020
    Posts:
    3
    any updates on this matter?
     
  24. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Likely Q4
     
  25. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    So, does upgrade/downgrade works as expected for both iOS and Android platforms?
     
  26. Arnaud_Gorain

    Arnaud_Gorain

    Unity Technologies

    Joined:
    Jun 28, 2022
    Posts:
    183
    Hi @novaVision,
    Yes it is supported on both platform.

    Note for iOS: Sandbox is known to not support the Upgrade/Downgrade properly (especially the UI)
     
  27. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    Hi @Arnaud_Gorain

    But how can I be sure it works as it should? I followed the subscription change samples for IAP 4.8.0, and from what I see there is no `special` requirement for iOS subscription change how Android has. Does it mean that subscription upgrade/downgrade works as simple IAP purchase and everything is handled by Apple in the background?

    And yes, testing upgrade on iOS I just get the 2 subscriptions according to SubscriptionInfo and on app restart 1 of 2 left. I never had 2 of them same time after app restart.
    Furthermore, downgrade doesn't trigger any Apple Store callback - not a success, not a failure. Just nothing
     
  28. Arnaud_Gorain

    Arnaud_Gorain

    Unity Technologies

    Joined:
    Jun 28, 2022
    Posts:
    183
    There will be a sample update in the upcoming 4.9.0 for iOS for upgrade/downgrade, it should be out within the next 2-3 weeks.
    Stay tuned for the release!
     
  29. unitylicense19

    unitylicense19

    Joined:
    Aug 29, 2018
    Posts:
    32
    Any update on this? is there any sample given for upgrade/downgrade
     
  30. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    Mate, I wouldn't expect anything for next months at least. That's a "usual" Unity approach.
    The worst what can developer do in such cases is to wait for their releases. This doesn't work this way with them.
     
  31. unity_B84A6AC018AFD27DB337

    unity_B84A6AC018AFD27DB337

    Joined:
    Aug 11, 2023
    Posts:
    1
  32. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    it's 4.9.3 already, but I don't see any changes related to upgrade/downgrade support
     
  33. FunCrew_Seo

    FunCrew_Seo

    Joined:
    Jun 16, 2017
    Posts:
    9
    same here... still waiting and no response from Unity side.. we are paying Unity Pro for what?
     
  34. VietmillionAviron

    VietmillionAviron

    Joined:
    Mar 15, 2023
    Posts:
    1
    hello, any update please ? i used Unity IAP v4.9.3, published app to Apple appstore, downgrade subscription show system popup: "You are all set" and there isn't any callback was called.