예제 #1
0
        /// <summary>
        /// Overload for purchasing virtual product based on its product identifier.
        /// </summary>
        public static void PurchaseProduct(IAPObject obj)
        {
            string productId = obj.id;

            //product is set to already owned, do nothing
            if (DBManager.isPurchased(productId))
            {
                OnPurchaseFailed("Product already purchased.");
                return;
            }

            //check whether the player has enough funds
            bool didSucceed = DBManager.VerifyVirtualPurchase(obj);

            if (isDebug)
            {
                Debug.Log("Purchasing virtual product " + productId + ", result: " + didSucceed);
            }
            //on success, non-consumables are saved to the database. This automatically
            //saves the new substracted fund value, then and fire the succeeded event
            if (didSucceed)
            {
                if (obj.type != ProductType.Consumable)
                {
                    DBManager.SetToPurchased(productId);
                }
                purchaseSucceededEvent(productId);
            }
            else
            {
                OnPurchaseFailed("Insufficient funds.");
            }
        }
예제 #2
0
        /// <summary>
        /// purchase non-consumable virtual product based on its product id
        /// </summary>
        public static void PurchaseNonconsumableVirtualProduct(string productId)
        {
            //if already owned, do nothing
            if (DBManager.isPurchased(productId))
            {
                PurchaseFailed("Product already purchased.");
                return;
            }

            //check whether the player has enough funds
            bool didSucceed = DBManager.VerifyVirtualPurchase(GetIAPObject(productId));

            if (instance.debug)
            {
                Debug.Log("purchasing non-consumable virtual product " + productId + " result: " + didSucceed);
            }
            //on success, non-consumables are being saved to the database
            //this automatically saves the new substracted fund value to the database
            //and fire the succeeded event
            if (didSucceed)
            {
                DBManager.SetToPurchased(productId);
                purchaseSucceededEvent(productId);
            }
            //otherwise show fail message
            else
            {
                PurchaseFailed("Insufficient funds.");
            }
        }
예제 #3
0
        /// <summary>
        /// Overload for purchasing virtual product based on its product identifier.
        /// </summary>
        public static void PurchaseProduct(IAPObject obj)
        {
            string productId = obj.id;

            //product is set to already owned, this should not happen
            if (obj.type != ProductType.Consumable && DBManager.GetPurchase(productId) > 0)
            {
                OnPurchaseFailed("Product already owned.");
                return;
            }

            #if PLAYFAB && !PLAYFAB_VALIDATION
            new PlayfabStore().Purchase(obj);
            return;
            #endif

            //check whether the player has enough funds
            bool didSucceed = DBManager.VerifyVirtualPurchase(obj);
            if (isDebug)
            {
                Debug.Log("Purchasing virtual product " + productId + ", result: " + didSucceed);
            }
            //on success, non-consumables are saved to the database. This automatically
            //saves the new substracted fund value, then and fire the succeeded event
            if (didSucceed)
            {
                if (obj.type == ProductType.Consumable)
                {
                    DBManager.IncreasePlayerData(productId, obj.usageCount);
                    purchaseSucceededEvent(productId);
                }
                else
                {
                    DBManager.SetPurchase(obj.id);
                }
                purchaseSucceededEvent(productId);
            }
            else
            {
                OnPurchaseFailed("Insufficient funds.");
            }
        }
예제 #4
0
        /// <summary>
        /// purchase consumable virtual product based on its product id
        /// </summary>
        public static void PurchaseConsumableVirtualProduct(string productId)
        {
            //check whether the player has enough funds
            bool didSucceed = DBManager.VerifyVirtualPurchase(GetIAPObject(productId));

            if (instance.debug)
            {
                Debug.Log("purchasing consumable virtual product " + productId + " result: " + didSucceed);
            }
            //on success, save new substracted fund value to the database
            //and fire the succeeded event
            if (didSucceed)
            {
                DBManager.Save();
                purchaseSucceededEvent(productId);
            }
            //otherwise show fail message
            else
            {
                PurchaseFailed("Insufficient funds.");
            }
        }