/// <summary>
        /// Overriding the base method for calling a web request and passing in the product purchased. Since PlayFab needs a user
        /// for validating receipts, it is also checked if the user is logged in already. If not, device login is called as well.
        /// </summary>
        public override void Validate(Product p = null)
        {
            if (p == null || !p.hasReceipt)
            {
                return;
            }

            if (string.IsNullOrEmpty(PlayfabManager.userId))
            {
                //log in before validating
                PlayfabManager.GetInstance().LoginWithDevice((result) =>
                {
                    //login failed, treat like without validation
                    if (result == false)
                    {
                        OnValidationResult(new PlayFabResultCommon()
                        {
                            CustomData = p.definition.storeSpecificId
                        });
                        return;
                    }

                    //we're logged in with PlayFab now
                    WaitForRequest(p);
                });
            }
            else
            {
                //we've been logged in all the time
                WaitForRequest(p);
            }
        }
Exemple #2
0
        //initialize IAPs, billing systems and database,
        //as well as shop components in this order
        void Awake()
        {
            //make sure we keep one instance of this script in the game
            if (instance)
            {
                Destroy(gameObject);
                return;
            }
            DontDestroyOnLoad(this);
            isDebug = Debug.isDebugBuild;

            //set static reference
            instance = this;
            DBManager dbManager = GetComponent <DBManager>();

            validator = GetComponent <ReceiptValidator>();

            #if PLAYFAB
            playfabManager = null;
            GameObject playfabGO = GameObject.Find("PlayfabManager");
            if (!playfabGO)
            {
                Debug.LogWarning("IAPManager: Playfab is enabled, but could not find PlayfabManager prefab. Have you placed it in the first scene "
                                 + "of your app and started from there? Instantiating temporary copy...");
                playfabGO = Instantiate(Resources.Load("PlayfabManager", typeof(GameObject))) as GameObject;
                //remove clone tag from its name. not necessary, but nice to have
                playfabGO.name = playfabGO.name.Replace("(Clone)", "");
            }

            playfabManager = playfabGO.GetComponent <PlayfabManager>();
            if (validator == null)
            {
                validator = gameObject.AddComponent <ReceiptValidatorService>();
            }

                #if !PLAYFAB_VALIDATION
            dbManager.memoryOnly = true;
            if (isDebug)
            {
                Debug.Log("PlayFab (online mode) is enabled: IAP data will not be saved on devices.");
            }
                #endif
            #endif

            //populate IAP dictionary and arrays with product ids
            SceneManager.sceneLoaded += OnSceneWasLoaded;
            dbManager.Init();
            InitIds();

            //do not self-initialize when using PlayFab services (full):
            //wait for its login callback for querying store later
            #if PLAYFAB && !PLAYFAB_VALIDATION
            return;
            #endif

            Initialize();
        }
Exemple #3
0
        /// <summary>
        /// Requests a new password, mapped to a UI button.
        /// </summary>
        public void ForgotPassword()
        {
            errorText.text = "";

            if (emailField.text.Length == 0)
            {
                errorText.text = "Please enter your email and retry.";
                return;
            }

            PlayfabManager.ForgotPassword(emailField.text);
        }
Exemple #4
0
        /// <summary>
        /// Sets a product to purchased after successful verification (or without).
        /// This alters the database entry for non-consumable or products with usage as well.
        /// </summary>
        public void PurchaseVerified(string id)
        {
            if (!IAPObjects.ContainsKey(id))
            {
                id = GetIAPIdentifier(id);
            }
            if (!IAPObjects.ContainsKey(id))
            {
                return;
            }
            IAPObject obj = IAPObjects[id];

            switch (obj.editorType)
            {
            case IAPType.Currency:
                foreach (IAPCurrency cur in obj.virtualPrice)
                {
                    DBManager.IncreaseFunds(cur.name, cur.amount);
                }
                break;

            default:
                //for consumables, add the defined usage count to tracking in player data
                //on non-consumables, don't continue if the product is already purchased,
                //for example if we just want to verify an existing product again
                switch (obj.type)
                {
                case ProductType.Consumable:
                    if (obj.usageCount > 0)
                    {
                        DBManager.IncreasePlayerData(id, obj.usageCount);

                        //update server player data
                                #if PLAYFAB && !PLAYFAB_VALIDATION
                        PlayfabManager.SetPlayerData();
                                #endif
                    }
                    break;

                default:
                    if (DBManager.GetPurchase(id) > 0)
                    {
                        return;
                    }

                    DBManager.IncreasePurchase(id, 1);
                    break;
                }
                break;
            }

            purchaseSucceededEvent(id);
        }
Exemple #5
0
        /// <summary>
        /// Tries to login via email, mapped to a UI button.
        /// </summary>
        public void LoginWithEmail()
        {
            errorText.text = "";

            if (emailField.text.Length == 0 || passwordField.text.Length == 0 || passwordField.text.Length <= 5)
            {
                errorText.text = "Email or Password is invalid. Check credentials and try again.";
                return;
            }

            loadingScreen.SetActive(true);
            PlayerPrefs.SetString(emailPref, emailField.text);
            PlayfabManager.LoginWithEmail(emailField.text, passwordField.text);
        }
Exemple #6
0
        /// <summary>
        /// Registers a new account with PlayFab, mapped to a UI button.
        /// </summary>
        public void RegisterAccount()
        {
            errorText.text = "";

            if (emailField.text.Length == 0 || passwordField.text.Length == 0)
            {
                errorText.text = "All fields are required.";
                return;
            }

            if (passwordField.text.Length <= 5)
            {
                errorText.text = "Password must be longer than 5 characters.";
                return;
            }

            loadingScreen.SetActive(true);
            PlayerPrefs.SetString(emailPref, emailField.text);
            PlayfabManager.RegisterAccount(emailField.text, passwordField.text);
        }
Exemple #7
0
        public void LoginAccountOther()
        {
            string user = userField.text;
            string key  = "";

            for (int i = 0; i < keyFields.Length; i++)
            {
                if (string.IsNullOrEmpty(keyFields[i].text) || keyFields[i].text.Length < 4)
                {
                    Debug.Log("Key does not meet requirements.");
                    break;
                }

                key += keyFields[i].text;
            }

            key  = key.Replace(" ", "").ToUpper();
            user = userField.text.Replace(" ", "").ToUpper();
            PlayfabManager.LoginAccountOther(user, key);
        }
Exemple #8
0
        /// <summary>
        /// Callback invoked after initiating a restore attempt.
        /// </summary>
        public static void OnTransactionsRestored(bool success)
        {
            instance.isRestoringTransactions = false;

            if (!success)
            {
                string error = "Restore failed.";
                if (isDebug)
                {
                    Debug.Log("IAPManager reports: " + error);
                }
                purchaseFailedEvent(error);
                return;
            }

            #if PLAYFAB && !PLAYFAB_VALIDATION
            List <string> restoreProducts = DBManager.GetAllPurchased(true);
            restoreProducts.RemoveAll(p => controller.products.WithID(p) == null);
            GetInstance().StartCoroutine(PlayfabManager.SetPurchase(restoreProducts));
            #endif

            purchaseSucceededEvent("restore");
        }
Exemple #9
0
        //setting up parameters and callbacks
        void Awake()
        {
            //make sure we keep one instance of this script in the game
            if (instance)
            {
                Destroy(gameObject);
                return;
            }
            DontDestroyOnLoad(this);

            //set static reference
            instance = this;
            bool validationOnly = false;

            #if PLAYFAB_VALIDATION
            validationOnly = true;
            #endif

            accountParams = new GetPlayerCombinedInfoRequestParams()
            {
                GetUserInventory       = !validationOnly,
                GetUserVirtualCurrency = !validationOnly,
                GetUserData            = !validationOnly,
                UserDataKeys           = new List <string>()
                {
                    DBManager.playerKey, DBManager.selectedKey
                }
            };

            if (validationOnly)
            {
                return;
            }
            //subscribe to selected events for handling them automatically
            ShopManager.itemSelectedEvent   += x => SetSelected();
            ShopManager.itemDeselectedEvent += x => SetSelected();
        }
Exemple #10
0
 public void UnlinkOther()
 {
     PlayfabManager.UnlinkCustomId();
 }
Exemple #11
0
 public void LinkAccountOther()
 {
     PlayfabManager.LinkAccountOther();
 }