Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

[Solved] How to know that there is nothing to restore / restored ?

Discussion in 'Unity IAP' started by thibouf, Jul 26, 2018.

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

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Hello,
    The documentation about restoring purchases says we can get a callback with true result event if nothing was restored.
    Also to know if anything was restored, we need to listen to ProcessPurchase.
    Fine, but , if the user had not purchased anything before, there will be nothing to restore... so the ProcessPurchase will never be called... and the user will wait forever for nothing ...
    Is there any way to know that the user has nothing to restore, so we can show him a nice message to tell him ?

    I would prefer not using a timer... as the restoration request a password it can be very long ...
     
  2. Benvictus

    Benvictus

    Joined:
    Sep 12, 2013
    Posts:
    87
    @thibouf

    Let me know if I understand correctly...

    You want to know how to determine if RestorePurchase() has completed and if ProcessPurchase() was called during the restore, however, you do not know when to check for this?

    RestorePurchases will return true if the products were restored or not, it also tells us that the restore process has ended. You can listen for the ProcessPurchase() when restoration starts and check if there was any activity after you get the callback.

    You can also set a Boolean in ProcessPurchase if there was a restore, in addition to unlocking the product.
     
  3. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Not exactly ...

    But I want to handle the successfull case where there is nothing to restore (because the user did not purchase anything before).
    In that case, ProcessPurchase will never be call after the RestorePurchase() because there is no product to restore. So if I do what you say (setting a bool and waiting for activity), I would wait forever...
     
  4. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    I'm not sure I understand. Why would the user be waiting? This should happen during initialization, which happens asynchronously.

    A false response would be worth catching, in case there was some problem with the Restoration. In that case, you can throw an exception or something.

    Could you clarify this a bit? I don't quite understand when they would need to see this dialog.
     
  5. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    To add to ap-unity's response, if the developer passes a callback function to the restore function like this: `m_AppleExtensions.RestoreTransactions(OnTransactionsRestored)`, when the restore process complete, the `OnTransactionsRestored` function will be called, the developer can know the restore process is finished. Regarding the Boolean mention, you would set it to False prior to calling restore, and set it to true in ProcessPurchase (for example). You could take appropriate action based on true/false of this value. If False, you could display "No products to restore" in the callback.
     
  6. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Just to clarify the use case (pretty standard I guess):
    - User click on restore button
    - Waiting popup appear
    - Then
    1 If there is something restored
    -> Inform the user the restore has succeed
    2 If there is nothing to restore
    -> Inform the user he has nothing to restore
    3 If there was an error
    -> Inform the user there was an error in the restore process and he should try again (maybe he cancel)

    That the case n°2 I am not sure to be able to handle correctly...

    So @JeffDUnity3D , are you saying that if there is nothing to restore the OnTransactionsRestored callback will called with False value ? For me nothing to restore does not means a failure as stated in the documentation, but it may be the case. That means , that I can not differentiate cases 2 and 3 :/
     
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    As mentioned, you set a global Boolean value (that you create, initially set to False) to True in ProcessPurchase if there is any Restore for any Product, otherwise leave it at the default of False. This will handle scenario 2 when there is nothing to restore.
     
  8. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    I am sorry, but I don't see how your solution handle my scenario 2 :/
    Yes, If there is nothing to restore the global Boolean will stay False. But there is nothing that tells me "Ok, know the wait is over, the process has ended , I can check the boolean". So basically the only way is to add a timer, and check this value at the end of the timer. But ,as I said earlier, I want to avoid that, because, as the restoration process is requesting user password, the duration can be very long ....
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    As mentioned previously, when the restore process is complete, the `OnTransactionsRestored` function will be called (or the name of the function that you pass). You check your Boolean value, and you're done. You can display "No products to restore" at this point.
     
  10. thibouf

    thibouf

    Joined:
    Mar 17, 2017
    Posts:
    105
    Ok thanks, what was not clear to me in the documentation are theses comments :
    Code (CSharp):
    1. // This does not mean anything was restored,
    2. // merely that the restoration process succeeded.
    I don't know why, but I thought that it meant that we could receive a ProcessPurchase call AFTER this callback... but i guess I misinterpreted the comment.

    Anyway thank you for your answers :)
     
Thread Status:
Not open for further replies.