[Closed] IAP iOS restore transaction events

Trying to implement unity’s IAPs solely for iOS at the moment and I ran into the following issue.

// This is a chunk of code I got from a unity's tutorial about IAP integration
//FetchtheApplestore-specificsubsystem.
 var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
// 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.
        apple.RestoreTransactions((result) => {
            // The first phase of restoration. If no more responses are received on ProcessPurchase then no purchases are available to be restored.
            Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
        }

From my understanding the following line says that there are no events fired when no purchases are available to be restored?

// 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?

Hi @ADNCG ,

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.

1 Like

Is there a list of the potential results of RestoreTransactions?

Hi @ADNCG 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.

2 Likes

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.

2 Likes

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.

Sure, it’s a constructive question @ADNCG 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.

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.

1 Like

You can tell if anything was restored by monitoring whether the ProcessPurchase method was called during the restoration process.

Ah I feel silly. Thank you so much.

This probably needs to be updated then - https://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game

3 Likes

@nicholasr @ADNCG @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.

@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

1 Like