Search Unity

[Closed] IAP iOS restore transaction events

Discussion in 'Unity IAP' started by ADNCG, Dec 30, 2015.

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

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    Trying to implement unity's IAPs solely for iOS at the moment and I ran into the following issue.
    Code (CSharp):
    1.  
    2. // This is a chunk of code I got from a unity's tutorial about IAP integration
    3. //FetchtheApplestore-specificsubsystem.
    4.  var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    5. // Begin the asynchronous process of restoring purchases. Expect a confirmation response in the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
    6.         apple.RestoreTransactions((result) => {
    7.             // The first phase of restoration. If no more responses are received on ProcessPurchase then no purchases are available to be restored.
    8.             Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    9.         }
    From my understanding the following line says that there are no events fired when no purchases are available to be restored?
    Code (CSharp):
    1. // The first phase of restoration. If no more responses are received on ProcessPurchase then no purchases are available to be restored.
    Right now, I'm disabling interactions with my UI to prevent the user from sending multiple requests once he clicks on restore purchase. The workaround that I found was to start a coroutine and have it wait X seconds, if no events had been fired in regard of purchase restoration by that time, then the coroutine would re-enable the UI. This feels sloppy, is there some sort of callback that ensures that the user has no purchases available to be restored? Or another way of knowing 100% that no purchases can be restored at a point in time?
     
    Last edited: Dec 30, 2015
  2. mpinol

    mpinol

    Joined:
    Jul 29, 2015
    Posts:
    317
    Hi @Fujik,

    Thank you for bringing this up, the comment on line 7 of the code above is incorrect as it is actually the second phase of restoration. I have made a note to make the necessary updates! As of right now, I believe it might be a better idea to re-enable the UI on line 8 in RestoreTransactions.
     
    Caselli likes this.
  3. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    Is there a list of the potential results of RestoreTransactions?
     
  4. nicholasr

    nicholasr

    Joined:
    Aug 15, 2015
    Posts:
    183
    Hi @Fujik RestoreTransactions passes a boolean result. Thank you for your patience as we complete our Store-specific documentation. For the happy-path case, expect to see a true passed to your RestoreTransactions callback.
     
    Caselli and mpinol like this.
  5. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    The action you pass to RestoreTransactions will always be invoked; if there is nothing to restore the value will still be 'true'. It would be false if there was a problem with the restoration, ue the network was down or the user entered the wrong password.
     
    OnePoint618 and nicholasr like this.
  6. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    Thanks for the clarifications. Sorry if it's obvious and I didn't catch it, but does it mean that in the current state of unity IAPs, there are no ways of knowing if there was nothing to restore?

    Please don't take this as a complaint, it has nothing to do with one. I just want to make sure I understand properly before I engage in creating a workaround.
     
  7. nicholasr

    nicholasr

    Joined:
    Aug 15, 2015
    Posts:
    183
    Sure, it's a constructive question @Fujik and really we're here to clarify and refine these tools. So for that case, 'true' will still be passed. A restoration query returning "zero new products available" is considered a 'true' success.

    Only when errors are detected will 'false' be passed. Like bad password, bad network, etc.
     
  8. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    Thanks, I got that! Although, the bool will also return true if there was something to restore, as far as I understand this.

    I'm asking if there's a way to differentiate the scenarios where there was indeed something restored or if there wasn't anything to restore, to give the user proper feedback.

    Sorry for the confusion, I should of phrased this in a better way.
     
    nicholasr likes this.
  9. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    You can tell if anything was restored by monitoring whether the ProcessPurchase method was called during the restoration process.
     
  10. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    994
    Ah I feel silly. Thank you so much.
     
  11. daklab

    daklab

    Joined:
    Nov 24, 2013
    Posts:
    27
    This probably needs to be updated then - https://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game
     
    OnePoint618, InsaneGoblin and mpinol like this.
  12. DW79

    DW79

    Joined:
    Apr 10, 2017
    Posts:
    2
    @nicholasr @AntoineDesbiens @Banderous Maybe i'm missing something, but how do you know when all of the purchases have been restored? It's my understanding that ProcessPurchase is called when there are items to restore. Ok. Good. But how do you know when the restoring is complete? Setting a timer seems sloppy and guesswork.
     
  13. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @DW79

    Would you be able to share your use case for wanting to know when purchase restoration is done?

    If you are trying to do something like block UI after you press the Restore button on iOS, you can use the RestoreTransactions extension which accepts a callback, which will be called after the restoration is complete
    https://docs.unity3d.com/Manual/UnityIAPiOSMAS.html
     
    krisventure likes this.
Thread Status:
Not open for further replies.