Beispiel #1
0
 //called when an purchaseFailedEvent happens,
 //we do the same here
 void HandleFailedPurchase(string error)
 {
     if (ShopManager.GetInstance())
     {
         ShopManager.ShowMessage(error);
     }
 }
Beispiel #2
0
 //just shows a message via our ShopManager component,
 //but checks for an instance of it first
 public void ShowMessage(string text)
 {
     if (ShopManager.GetInstance())
     {
         ShopManager.ShowMessage(text);
     }
 }
Beispiel #3
0
 //called when an purchaseFailedEvent happens, here we forward
 //the error message to ShopManager's error window (if present)
 void HandleFailedInventory(string error)
 {
     if (ShopManager.GetInstance())
     {
         ShopManager.ShowMessage(error);
     }
 }
Beispiel #4
0
        //when the buy button has been clicked, here we try to purchase this item
        //maps to the corresponding purchase methods of IAPManager
        //only works on an actual mobile device
        public void Purchase()
        {
            #if UNITY_EDITOR
            if (type == IAPType.consumable || type == IAPType.nonConsumable ||
                type == IAPType.subscription)
            {
                string editorText = "Calling purchase ID: " + this.productId + ".\nYou are not on a mobile device, nothing will happen.";
                if (ShopManager.GetInstance())
                {
                    ShopManager.ShowMessage(editorText);
                }
                Debug.Log(editorText);
                return;
            }
            #endif

            //differ between IAP type
            switch (type)
            {
            case IAPType.consumable:
                IAPManager.PurchaseConsumableProduct(this.productId);
                break;

            case IAPType.nonConsumable:
                IAPManager.PurchaseNonconsumableProduct(this.productId);
                break;

            case IAPType.subscription:
                IAPManager.PurchaseSubscription(this.productId);
                break;

            case IAPType.consumableVirtual:
                IAPManager.PurchaseConsumableVirtualProduct(this.productId);
                break;

            case IAPType.nonConsumableVirtual:
                IAPManager.PurchaseNonconsumableVirtualProduct(this.productId);
                break;
            }

            //hide buy button once a purchase was made
            //only when an additional buy trigger was set
            if (buyTrigger)
            {
                ConfirmPurchase(false);
            }
        }
Beispiel #5
0
        /*
         * public void CloudMoolahButton()
         * {
         *  extensions.GetExtension<IMoolahExtension>().FastRegister(DBManager.GetDeviceId(), (string moolahName) =>
         *  {
         *      //register succeeded
         *      extensions.GetExtension<IMoolahExtension>().Login(moolahName, DBManager.GetDeviceId(), (LoginResultState loginResult, string error) =>
         *      {
         *          //login succeeded?
         *          Debug.Log("Moolah Login State: " + loginResult + ", " + error);
         *      });
         *  }, (FastRegisterError registerResult, string error) =>
         *  {
         *      //register failed
         *      Debug.Log("Moolah Register Error: " + registerResult + ", " + error);
         *  });
         * }
         */


        /// <summary>
        /// Purchase product based on its product id. If the productId matches "restore", we restore transactions instead.
        /// Our delegates then fire the appropriate succeeded/fail/restore event.
        /// </summary>
        public static void PurchaseProduct(string productId)
        {
            #if UNITY_PURCHASING
            if (productId == "restore")
            {
                RestoreTransactions();
                return;
            }
            #endif

            IAPObject obj = GetIAPObject(productId);
            if (obj == null)
            {
                if (isDebug)
                {
                    Debug.LogError("Product " + productId + " not found in IAP Settings.");
                }
                return;
            }

            //distinguish between virtual and real products
            if (obj.editorType == IAPType.Virtual)
            {
                PurchaseProduct(obj);
                return;
            }

            #if UNITY_PURCHASING
            if (controller == null)
            {
                if (ShopManager.GetInstance())
                {
                    ShopManager.ShowMessage("Billing is not available.");
                }
                Debug.LogError("Unity IAP is not initialized correctly! Please check your billing settings.");
                return;
            }

            controller.InitiatePurchase(controller.products.WithID(productId));
            #endif
        }