Exemple #1
0
 public void RestoreButtonClick()
 {
     if (m_IsCloudMoolahStoreSelected)
     {
         // Restore abnornal transaction identifer, if Client don't receive transaction identifer.
         m_MoolahExtensions.RestoreTransactionID((RestoreTransactionIDState restoreTransactionIDState) =>
         {
             Debug.Log("restoreTransactionIDState = " + restoreTransactionIDState.ToString());
             bool success =
                 restoreTransactionIDState != RestoreTransactionIDState.RestoreFailed &&
                 restoreTransactionIDState != RestoreTransactionIDState.NotKnown;
             OnTransactionsRestored(success);
         });
     }
     else if (m_IsSamsungAppsStoreSelected)
     {
         m_SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
     }
     else if (Application.platform == RuntimePlatform.WSAPlayerX86 ||
              Application.platform == RuntimePlatform.WSAPlayerX64 ||
              Application.platform == RuntimePlatform.WSAPlayerARM)
     {
         m_MicrosoftExtensions.RestoreTransactions();
     }
     else if (m_IsGooglePlayStoreSelected)
     {
         m_GooglePlayStoreExtensions.RestoreTransactions(OnTransactionsRestored);
     }
     else
     {
         m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
     }
 }
Exemple #2
0
    private void InitUI(IEnumerable <Product> items)
    {
        // Disable the UI while IAP is initializing
        // See also UpdateInteractable()
        m_InteractableSelectable = GetDropdown();         // References any one of the disabled components

        // Show Restore button on Apple platforms
        if (!(Application.platform == RuntimePlatform.IPhonePlayer ||
              Application.platform == RuntimePlatform.OSXPlayer ||
              m_IsSamsungAppsStoreSelected))
        {
            GetRestoreButton().gameObject.SetActive(false);
        }

        foreach (var item in items)
        {
            // Add initial pre-IAP-initialization content. Update later in OnInitialized.
            var description = string.Format("{0} - {1}", item.definition.id, item.definition.type);

            GetDropdown().options.Add(new Dropdown.OptionData(description));
        }

        // Ensure I render the selected list element
        GetDropdown().RefreshShownValue();

        GetDropdown().onValueChanged.AddListener((int selectedItem) => {
            Debug.Log("OnClickDropdown item " + selectedItem);
            m_SelectedItemIndex = selectedItem;
        });

        // Initialize my button event handling
        GetBuyButton().onClick.AddListener(() => {
            if (m_PurchaseInProgress == true)
            {
                return;
            }

            m_Controller.InitiatePurchase(m_Controller.products.all[m_SelectedItemIndex]);

            // Don't need to draw our UI whilst a purchase is in progress.
            // This is not a requirement for IAP Applications but makes the demo
            // scene tidier whilst the fake purchase dialog is showing.
            m_PurchaseInProgress = true;
        });

        if (GetRestoreButton() != null)
        {
            GetRestoreButton().onClick.AddListener(() =>
            {
                if (m_IsSamsungAppsStoreSelected)
                {
                    m_SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
                }
                else
                {
                    m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
                }
            });
        }
    }
        public static void RestorePurchases()
        {
            // 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 ...

            // ... begin restoring purchases
            Debug.Log("RestorePurchases started ...");

            if (_isCloudMoolahStore)
            {
                if (_isLogined == false)
                {
                    Debug.LogError("CloudMoolah purchase restoration aborted. Login incomplete.");
                }
                else
                {
                    // Restore abnornal transaction identifer, if Client don't receive transaction identifer.
                    _MoolahExtensions.RestoreTransactionID((RestoreTransactionIDState restoreTransactionIDState) =>
                    {
                        Debug.Log("restoreTransactionIDState = " + restoreTransactionIDState.ToString());
                        bool success =
                            restoreTransactionIDState != RestoreTransactionIDState.RestoreFailed &&
                            restoreTransactionIDState != RestoreTransactionIDState.NotKnown;
                        OnTransactionsRestored(success);
                    });
                }
            }
            else if (_isSamsungAppsStore)
            {
                _SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
            }
            else if (_isGooglePlayStore)
            {
            }
            else
            {
                _AppleExtensions.RestoreTransactions(OnTransactionsRestored);
            }
        }
Exemple #4
0
 public void RestoreButtonClick()
 {
     if (m_IsSamsungAppsStoreSelected)
     {
         m_SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
     }
     else if (Application.platform == RuntimePlatform.WSAPlayerX86 ||
              Application.platform == RuntimePlatform.WSAPlayerX64 ||
              Application.platform == RuntimePlatform.WSAPlayerARM)
     {
         m_MicrosoftExtensions.RestoreTransactions();
     }
     else if (m_IsGooglePlayStoreSelected)
     {
         m_GooglePlayStoreExtensions.RestoreTransactions(OnTransactionsRestored);
     }
     else
     {
         m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
     }
 }
Exemple #5
0
 public void RestoreButtonClick()
 {
     if (m_IsCloudMoolahStoreSelected)
     {
         if (m_IsLoggedIn == false)
         {
             Debug.LogError("CloudMoolah purchase restoration aborted. Login incomplete.");
         }
         else
         {
             // Restore abnornal transaction identifer, if Client don't receive transaction identifer.
             //如果客户端不接收事务标识,则恢复//恢复事务标识。
             m_MoolahExtensions.RestoreTransactionID((RestoreTransactionIDState restoreTransactionIDState) =>
             {
                 Debug.Log("restoreTransactionIDState = " + restoreTransactionIDState.ToString());
                 bool success =
                     restoreTransactionIDState != RestoreTransactionIDState.RestoreFailed &&
                     restoreTransactionIDState != RestoreTransactionIDState.NotKnown;
                 OnTransactionsRestored(success);
             });
         }
     }
     else if (m_IsSamsungAppsStoreSelected)
     {
         m_SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
     }
     else if (Application.platform == RuntimePlatform.WSAPlayerX86 ||
              Application.platform == RuntimePlatform.WSAPlayerX64 ||
              Application.platform == RuntimePlatform.WSAPlayerARM)
     {
         m_MicrosoftExtensions.RestoreTransactions();
     }
     else
     {
         m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
     }
 }
Exemple #6
0
    private void InitUI(IEnumerable <Product> items)
    {
        // Disable the UI while IAP is initializing
        // See also UpdateInteractable()
        m_InteractableSelectable = GetDropdown();         // References any one of the disabled components

        // Show Restore button on supported platforms
        if (!(Application.platform == RuntimePlatform.IPhonePlayer ||
              Application.platform == RuntimePlatform.OSXPlayer ||
              Application.platform == RuntimePlatform.tvOS ||
              Application.platform == RuntimePlatform.WSAPlayerX86 ||
              Application.platform == RuntimePlatform.WSAPlayerX64 ||
              Application.platform == RuntimePlatform.WSAPlayerARM ||
              m_IsSamsungAppsStoreSelected || m_IsCloudMoolahStoreSelected))
        {
            GetRestoreButton().gameObject.SetActive(false);
        }

        // Show Register, Login, and Validate buttons on CloudMoolah platform
        GetRegisterButton().gameObject.SetActive(m_IsCloudMoolahStoreSelected);
        GetLoginButton().gameObject.SetActive(m_IsCloudMoolahStoreSelected);
        GetValidateButton().gameObject.SetActive(m_IsCloudMoolahStoreSelected);

        foreach (var item in items)
        {
            // Add initial pre-IAP-initialization content. Update later in OnInitialized.
            var description = string.Format("{0} - {1}", item.definition.id, item.definition.type);

            GetDropdown().options.Add(new Dropdown.OptionData(description));
        }

        // Ensure I render the selected list element
        GetDropdown().RefreshShownValue();

        GetDropdown().onValueChanged.AddListener((int selectedItem) => {
            Debug.Log("OnClickDropdown item " + selectedItem);
            m_SelectedItemIndex = selectedItem;
        });

        // Initialize my button event handling
        GetBuyButton().onClick.AddListener(() => {
            if (m_PurchaseInProgress == true)
            {
                Debug.Log("Please wait, purchasing ...");
                return;
            }

            // For CloudMoolah, games utilizing a connected backend game server may wish to login.
            // Standalone games may not need to login.
            if (m_IsCloudMoolahStoreSelected && m_IsLoggedIn == false)
            {
                Debug.LogWarning("CloudMoolah purchase notifications will not be forwarded server-to-server. Login incomplete.");
            }

            // Don't need to draw our UI whilst a purchase is in progress.
            // This is not a requirement for IAP Applications but makes the demo
            // scene tidier whilst the fake purchase dialog is showing.
            m_PurchaseInProgress = true;
            m_Controller.InitiatePurchase(m_Controller.products.all[m_SelectedItemIndex], "aDemoDeveloperPayload");
        });

        if (GetRestoreButton() != null)
        {
            GetRestoreButton().onClick.AddListener(() => {
                if (m_IsCloudMoolahStoreSelected)
                {
                    if (m_IsLoggedIn == false)
                    {
                        Debug.LogError("CloudMoolah purchase restoration aborted. Login incomplete.");
                    }
                    else
                    {
                        // Restore abnornal transaction identifer, if Client don't receive transaction identifer.
                        m_MoolahExtensions.RestoreTransactionID((RestoreTransactionIDState restoreTransactionIDState) => {
                            Debug.Log("restoreTransactionIDState = " + restoreTransactionIDState.ToString());
                            bool success =
                                restoreTransactionIDState != RestoreTransactionIDState.RestoreFailed &&
                                restoreTransactionIDState != RestoreTransactionIDState.NotKnown;
                            OnTransactionsRestored(success);
                        });
                    }
                }
                else if (m_IsSamsungAppsStoreSelected)
                {
                    m_SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
                }
                else if (Application.platform == RuntimePlatform.WSAPlayerX86 ||
                         Application.platform == RuntimePlatform.WSAPlayerX64 ||
                         Application.platform == RuntimePlatform.WSAPlayerARM)
                {
                    m_MicrosoftExtensions.RestoreTransactions();
                }
                else
                {
                    m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
                }
            });
        }

        // CloudMoolah requires user registration and supports login to manage the user's
        // digital wallet. The CM store also supports remote receipt validation.

        // CloudMoolah user registration extension, to establish digital wallet
        // This is a "fast" registration, requiring only a password. Users may provide
        // more detail including an email address during the purchase flow, a "slow" registration, if desired.
        if (GetRegisterButton() != null)
        {
            GetRegisterButton().onClick.AddListener(() => {
                // Provide a unique password to establish the user's account.
                // Typically, connected games (with backend game servers), may already
                // have available a user-token, which could be supplied here.
                m_MoolahExtensions.FastRegister("CMPassword", RegisterSucceeded, RegisterFailed);
            });
        }

        // CloudMoolah user login extension, to access existing digital wallet
        if (GetLoginButton() != null)
        {
            GetLoginButton().onClick.AddListener(() => {
                m_MoolahExtensions.Login(m_CloudMoolahUserName, "CMPassword", LoginResult);
            });
        }

        // CloudMoolah remote purchase receipt validation, to determine if the purchase is fraudulent
        // NOTE: Remote validation only available for CloudMoolah currently. For local validation,
        // see ProcessPurchase.
        if (GetValidateButton() != null)
        {
            GetValidateButton().onClick.AddListener(() => {
                // Remotely validate the last transaction and receipt.
                m_MoolahExtensions.ValidateReceipt(m_LastTransationID, m_LastReceipt,
                                                   (string transactionID, ValidateReceiptState state, string message) => {
                    Debug.Log("ValidtateReceipt transactionID:" + transactionID
                              + ", state:" + state.ToString() + ", message:" + message);
                });
            });
        }
    }
Exemple #7
0
    private void InitUI(IEnumerable <Product> items)
    {
        // Disable the UI while IAP is initializing
        // See also UpdateInteractable()
        m_InteractableSelectable = GetDropdown(); // References any one of the disabled components

        // Show Restore button on supported platforms
        if (!(NeedRestoreButton()))
        {
            GetRestoreButton().gameObject.SetActive(false);
        }

        // Show Register, Login, and Validate buttons on supported platform
        GetRegisterButton().gameObject.SetActive(NeedRegisterButton());
        GetLoginButton().gameObject.SetActive(NeedLoginButton());
        GetValidateButton().gameObject.SetActive(NeedValidateButton());

        foreach (var item in items)
        {
            // Add initial pre-IAP-initialization content. Update later in OnInitialized.
            var description = string.Format("{0} - {1}", item.definition.id, item.definition.type);

            GetDropdown().options.Add(new Dropdown.OptionData(description));
        }

        // Ensure I render the selected list element
        GetDropdown().RefreshShownValue();

        GetDropdown().onValueChanged.AddListener((int selectedItem) => {
            Debug.Log("OnClickDropdown item " + selectedItem);
            m_SelectedItemIndex = selectedItem;
        });

        // Initialize my button event handling
        GetBuyButton().onClick.AddListener(() => {
            if (m_PurchaseInProgress == true)
            {
                Debug.Log("Please wait, purchasing ...");
                return;
            }

            // For platforms needing Login, games utilizing a connected backend
            // game server may wish to login.
            // Standalone games may not need to login.
            if (NeedLoginButton() && m_IsLoggedIn == false)
            {
                Debug.LogWarning("Purchase notifications will not be forwarded server-to-server. Login incomplete.");
            }

            // Don't need to draw our UI whilst a purchase is in progress.
            // This is not a requirement for IAP Applications but makes the demo
            // scene tidier whilst the fake purchase dialog is showing.
            m_PurchaseInProgress = true;
            m_Controller.InitiatePurchase(m_Controller.products.all[m_SelectedItemIndex], "aDemoDeveloperPayload");
        });

        if (GetRestoreButton() != null)
        {
            GetRestoreButton().onClick.AddListener(() => {
                if (m_IsCloudMoolahStoreSelected)
                {
                    if (m_IsLoggedIn == false)
                    {
                        Debug.LogError("CloudMoolah purchase restoration aborted. Login incomplete.");
                    }
                    else
                    {
                        // Restore abnornal transaction identifer, if Client don't receive transaction identifer.
                        m_MoolahExtensions.RestoreTransactionID((RestoreTransactionIDState restoreTransactionIDState) => {
                            Debug.Log("restoreTransactionIDState = " + restoreTransactionIDState.ToString());
                            bool success =
                                restoreTransactionIDState != RestoreTransactionIDState.RestoreFailed &&
                                restoreTransactionIDState != RestoreTransactionIDState.NotKnown;
                            OnTransactionsRestored(success);
                        });
                    }
                }
                else if (m_IsSamsungAppsStoreSelected)
                {
                    m_SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
                }
                else if (Application.platform == RuntimePlatform.WSAPlayerX86 ||
                         Application.platform == RuntimePlatform.WSAPlayerX64 ||
                         Application.platform == RuntimePlatform.WSAPlayerARM)
                {
                    m_MicrosoftExtensions.RestoreTransactions();
                }
                else
                {
                    m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
                }
            });
        }

        if (GetLoginButton() != null)
        {
            if (m_IsUnityChannelSelected)
            {
                GetLoginButton().onClick.AddListener(() =>
                {
                    unityChannelLoginHandler.loginSucceededAction = (UserInfo userInfo) =>
                    {
                        m_IsLoggedIn = true;
                        Debug.LogFormat("Succeeded logging into UnityChannel. channel {0}, userId {1}, userLoginToken {2} ",
                                        userInfo.channel, userInfo.userId, userInfo.userLoginToken);
                    };
                    unityChannelLoginHandler.loginFailedAction = (string message) =>
                    {
                        m_IsLoggedIn = false;
                        Debug.LogError("Failed logging into UnityChannel. " + message);
                    };

                    StoreService.Login(unityChannelLoginHandler);
                });
            }
        }

        // For local validation, see ProcessPurchase.
        if (GetValidateButton() != null)
        {
            if (m_IsUnityChannelSelected)
            {
                GetValidateButton()
                .onClick.AddListener(() =>
                {
                    string txId = m_LastTransationID;
                    m_UnityChannelExtensions.ValidateReceipt(txId, (bool success, string signData, string signature) =>
                    {
                        Debug.LogFormat("ValidateReceipt transactionId {0}, success {1}, signData {2}, signature {3}",
                                        txId, success, signData, signature);

                        // May use signData and signature results to validate server-to-server
                    });
                });
            }
        }
    }