Search Unity

Question How long to wait for IAP Apple Restore Purchases

Discussion in 'Unity IAP' started by Hotshot10101, Aug 5, 2022.

  1. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    I am using IAP on an iOS app. I have a button that the user hits to restore purchases if I don't detect that they have purchased the items.

    When they hit the button I kick off the RestorePurchases process and get the callback as follows:

    Code (CSharp):
    1.             // Fetch the Apple store-specific subsystem.
    2.             var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    3.             // Begin the asynchronous process of restoring purchases. Expect a confirmation response in
    4.             // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
    5.             apple.RestoreTransactions((result) =>
    6.             {
    7.                 // The first phase of restoration. If no more responses are received on ProcessPurchase then
    8.                 // no purchases are available to be restored.
    9.                 Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    10.             });
    This comes from the examples.

    Notice the debug log output that says if no further messages, no purchases available to restore.

    Current I am showing a please wait when the user hits the "Restore Purchases" button I have, but I need to know when to dismiss it.

    If there are purchases then the callback that processes them is supposed to get called. If there are no purchases to be restored, how long do I want before closing the please wait?

    Or should I not have a please wait at all? Should I just tell the user nothing or ??? I could probably show a message on the restore purchases screen that says something like if there is nothing to restore nothing will happen, but that doesn't seem great either.

    Any suggestions?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Your Debug.Log message should say "Restore complete.". All ProcessPurchase calls will be completed by the time RestoreTransactions result occurs.
     
  3. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    When there are no purchases to restore I never get the ProcessPurchase call at all.

    So are you saying that if I get the callback to RestoreTransactions and never got the call to ProcessPurchase that means there are none? Are you also saying that if there are purchases I will get the ProcessPurchase and that will complete and then the RestoreTransactions will fire?

    I just want to make sure I understand and am confused by that comment that came from the example source code. To clarify, that debug log message came directly from the example code I found from one of the Unity examples.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Correct on all questions.
     
  5. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    Awesome. Thanks for the quick reply.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    For clarity, RestoreTransactions will complete (not fire), perhaps that is what you meant. So the order is:

    RestoreTransactions is fired
    None, 1 or more ProcessPurchase calls will be made
    RestoreTransactions will complete (result is returned).
     
  7. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    That is great.

    I wonder if maybe something changed along the way and that example just wasn't updated to reflect that....
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Which example?
     
  9. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
    The example I got that code from that has this line in it:

    Code (CSharp):
    1. Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    That comment seems to indicate that this callback is not the end and something else might happen. Maybe it is just worded in a way that I am taking it wrong.

    I got that example somewhere from a Unity post of blog. Can't remember anymore where it came from.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The message in that code is incorrect. The documentation is here https://docs.unity3d.com/Manual/UnityIAPRestoringTransactions.html
     
  11. Hotshot10101

    Hotshot10101

    Joined:
    Jun 23, 2012
    Posts:
    223
  12. DarkDeivel

    DarkDeivel

    Joined:
    Aug 31, 2016
    Posts:
    127
    Please tell me, for the "Restore Purchase" button to work in the game itself, is it enough to create a button and add a method call to it? Does he recognize everything and restore it himself, or is it necessary, as with a purchase, to call methods to restore each product? By the way, does it only work with NON-CONSUMABLE PURCHASES or ALL?

    Code (CSharp):
    1.     public void RestorePurchases()
    2.     {
    3.         // If Purchasing has not yet been set up ...
    4.         if (!IsInitialized())
    5.         {
    6.             // ... report the situation and stop restoring. Consider either waiting longer, or retrying initialization.
    7.             Debug.Log("RestorePurchases FAIL. Not initialized.");
    8.             return;
    9.         }
    10.  
    11.         // If we are running on an Apple device ...
    12.         if (Application.platform == RuntimePlatform.IPhonePlayer ||
    13.             Application.platform == RuntimePlatform.OSXPlayer)
    14.         {
    15.             // ... begin restoring purchases
    16.             Debug.Log("RestorePurchases started ...");
    17.  
    18.             // Fetch the Apple store-specific subsystem.
    19.             var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    20.             // Begin the asynchronous process of restoring purchases. Expect a confirmation response in
    21.             // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
    22.             apple.RestoreTransactions((result) =>
    23.             {
    24.                 // The first phase of restoration. If no more responses are received on ProcessPurchase then
    25.                 // no purchases are available to be restored.
    26.                 Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    27.             });
    28.         }
    29.         // Otherwise ...
    30.         else
    31.         {
    32.             // We are not running on an Apple device. No work is necessary to restore purchases.
    33.             Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
    34.         }
    35.     }
     
  13. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,264
    apple.RestoreTransactions fires your ProcessPurchase method again for each product the user owns as reported by the Apple App Store. If you already use the ProcessPurchase method to grant a purchased product to the user, then that's enough.

    Only non consumables and subscriptions can be restored since consumables are not persisted on the App Store.
     
    nobluff67 and DarkDeivel like this.
  14. jason_yak

    jason_yak

    Joined:
    Aug 25, 2016
    Posts:
    531
    Hi there, we're not getting any callback from RestoreTransactions in a live production build. We know that an account should have a single purchase to restore, but we get no call to PorcessPurchase, and also no restore completion event.

    No logs of any sort to indicate what's gone wrong, we simply call RestoreTransactions and then nothing happens.

    What can we do to debug this? I'm using Unity 2021.3.30, with latest Unity IAP 4.9.4, testing on an iPad, I have tried iOS16, and now after updating to iOS17 it's doing the same thing. If we call restore in a test build using a testing sandbox user the restore does return a event and it proves our implementation is setup correctly. But I'm 100% sure that there's no callback coming from RestoreTransactions in our live production build.
     
  15. chltmd04

    chltmd04

    Joined:
    Jan 19, 2022
    Posts:
    1

    I'm stuck in the same problem.
    Is there any updates on this?