Restore Purchases

Hello!

I just started using Unity IAP and have a question regarding “Restore Purchases”.

To restore purchases I have this method:

public void RestorePurchases() {
        if(!IsInitialized()) {
            return;
        }

        IAppleExtensions iosExtensions = storeExtensionProvider.GetExtension<IAppleExtensions>();
        iosExtensions.RestoreTransactions((result) => {
            if(result) {
                // What do here??
            }
            else {
                // And here??
            }
        });
    }
  1. My first question is: What am I supposed to do in the lambda of RestoreTransactions? Is this code called for every restored items or only ONCE after all items have been restored?

  2. My biggest problem: I have a ProcessPurchase(PurchaseEventArgs args) and if I understand correctly, this method is called in 2 cases: A) When I explicitly request a buy via storeController.InitiatePurchase(product) and B) When I request a restore purchases via RestoreTransactions().
    I want to display a success dialog when the user bought an item. Thus actually I want to show a dialog inside ProcessPurchase(). My problem: Since ProcessPurchase() is also called when I do a “Restore purchases”, I can’t just open a dialog inside ProcessPurchase().
    Imagine if the user clicks on “Restore Purchases” and the system restores 3 items, then I would get 3 dialogs.
    How can I show a dialog ONLY when the user made a buy and NOT on Restore Purchases?

You really don’t need to do anything for in your if/else statement. Each restored product will trigger ProcessPurchase just as if the user purchased it. You would probably want to set a boolean at the beginning of your restore button click. Then in ProcessPurchase, check this boolean before displaying a message. When you get to the the if/else condition, you know that restore has completed.