Пример #1
0
    // Restore purchases previously made by this customer. Some platforms automatically restore purchases, like Google. 
    // Apple currently requires explicit purchase restoration for IAP, conditionally displaying a password prompt.
    public void RestorePurchases()
    {
        processPurchaseCalled = false;

        // If Purchasing has not yet been set up ...
        if (!IsInitialized())
        {
            // ... report the situation and stop restoring. Consider either waiting longer, or retrying initialization.
            //Debug.Log("RestorePurchases FAIL. Not initialized.");
            return;
        }

        // If we are running on an Apple device ... 
        if (Application.platform == RuntimePlatform.IPhonePlayer ||
            Application.platform == RuntimePlatform.OSXPlayer    ||
            Application.platform == RuntimePlatform.OSXEditor)
        {
            // ... begin restoring purchases
            //Debug.Log("RestorePurchases started ...");
            onShopCanvas.ShowThatItsRestoring();

            // Fetch the Apple store-specific subsystem.
            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.");

                if (result)
                {
                    restoreRemoveAdsButton.gameObject.SetActive(false); // disable Restore button
                    removeAdsButton.gameObject.SetActive(false);
                    GameControl.control.purchasesRestoredChecked = true;
                    GameControl.control.Save();

                    if (!processPurchaseCalled)
                    {
                        // No previous purchases to restore, so re-enable Purchase button. Victor NBNBNB
                        removeAdsButton.gameObject.SetActive(true);
                        onShopCanvas.PriceToNormal();
                        //Debug.Log("ProcessPurchases not called");
                    }
                }
                else
                {
                    // Don't know what to do here. Something went wrong with RestoreTransactions?
                    //Debug.Log("RestorePurchases FAIL. Not supported on this platform.");
                }
            });
        }
        // Otherwise ...
        else
        {
            // We are not running on an Apple device. No work is necessary to restore purchases.
            //Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
        }
    }