Beispiel #1
0
        // 根据ID给购买商品;
        public void BuyProductByID(long charge_id_)
        {
            if (IsInitialized())
            {
                if (m_PurchaseInProgress == true)
                {
                    return;
                }

                Product product = m_StoreController.products.WithID(charge_id_.ToString());
                if (product != null && product.availableToPurchase)
                {
                    Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
                    m_StoreController.InitiatePurchase(product);
                    m_PurchaseInProgress = true;
                }
                else
                {
                    Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
                }
            }
            else
            {
                Debug.Log("BuyProductID FAIL. Not initialized.");
            }
        }
Beispiel #2
0
 public void OnPurchaseClicked(int productId)
 {
     if (controller != null)
     {
         if (productId == 1)
         {
             controller.InitiatePurchase(SKU_1000_COINS);
         }
         else if (productId == 2)
         {
             controller.InitiatePurchase(SKU_5000_COINS);
         }
         else if (productId == 3)
         {
             controller.InitiatePurchase(SKU_10000_COINS);
         }
         else if (productId == 4)
         {
             controller.InitiatePurchase(SKU_50000_COINS);
         }
         else if (productId == 5)
         {
             controller.InitiatePurchase(SKU_100000_COINS);
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// 购买去除广告
 /// </summary>
 public void OnPurchaseClicked()
 {
     currentBuy            = buy_adRemove;
     buyItemCompleteEvent += buyItemDic[currentBuy].OnBuy;
     controller.InitiatePurchase(currentBuy);
     AllSDKManager.GetSDK <AllAnalyticsSdk>().Event_IAP_Start("RemoveAd");
 }
    public void BuyProduct(string productID)
    {
        if (IsInitialized())
        {
            // ... look up the Product reference with the general product identifier and the Purchasing
            // system's products collection.
            Product product = m_StoreController.products.WithID(productID);

            // If the look up found a product for this device's store and that product is ready to be sold ...
            if (product != null && product.availableToPurchase)
            {
                Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
                // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
                // asynchronously.
                m_StoreController.InitiatePurchase(product);
            }
            else
            {
                Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
            }
        }
        // Otherwise ...
        else
        {
            Debug.Log("BuyProductID FAIL. Not initialized.");
        }
    }
    //Example code
    void BuyProductID(string productId)
    {
        // If Purchasing has been initialized ...
        if (IsInitialized())
        {
            // ... look up the Product reference with the general product identifier and the Purchasing
            // system's products collection.
            Product product = m_StoreController.products.WithID(productId);

            // If the look up found a product for this device's store and that product is ready to be sold ...
            if (product != null && product.availableToPurchase)
            {
                Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
                // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
                // asynchronously.
                m_StoreController.InitiatePurchase(product);
            }
            // Otherwise ...
            else
            {
                // ... report the product look-up failure situation
                Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
            }
        }
        // Otherwise ...
        else
        {
            // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
            // retrying initiailization.
            Debug.Log("BuyProductID FAIL. Not initialized.");
        }
    }
Beispiel #6
0
    public void OnBtnPurchaseClicked(int index)
    {
        if (!UIManager.Instance.Check_Network())
        {
            return;
        }

#if UNITY_ANDROID
        if (controller != null)
        {
            // Fetch the currency Product reference from Unity Purchasing


            Product product = controller.products.WithID(android_ProductIds[index]);
            if (product != null && product.availableToPurchase)
            {
                controller.InitiatePurchase(product);
            }
        }
#elif UNITY_IOS
        Product product = controller.products.WithID(ios_ProductIds[index]);
        if (product != null && product.availableToPurchase)
        {
            controller.InitiatePurchase(product);
        }
#endif

#if UNITY_EDITOR
        ShopManager.Instance.Buy(index);
#endif
    }
Beispiel #7
0
    void BuyProductID(string productId, string developerPayload = null)
    {
        if (IsInitialized() == false)
        {
            PrintConsole("BuyProductID FAIL. Not initialized.");
            return;
        }

        Product product = m_StoreController.products.WithID(productId);

        if (product != null && product.availableToPurchase)
        {
            PrintConsole(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));

            if (developerPayload != null)
            {
                m_StoreController.InitiatePurchase(product, developerPayload);
            }
            else
            {
                m_StoreController.InitiatePurchase(product);
            }
        }
        else
        {
            PrintConsole("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
        }
    }
Beispiel #8
0
        /// <summary>
        /// アイテムの購入.
        /// </summary>
        private BuyFailureReason PurchaseInternal(string productId, string developerPayload)
        {
            // コールバックが通知できない場合は何もしない.
            if (onStorePurchaseComplete == null || !onStorePurchaseComplete.HasObservers)
            {
                return(BuyFailureReason.NotReceiveMessage);
            }

            // 購入処理中.
            if (IsPurchaseing)
            {
                return(BuyFailureReason.InPurchaseing);
            }

            try
            {
                // 課金システムが未初期化の場合はなにもしない.
                if (!IsPurchaseReady)
                {
                    return(BuyFailureReason.NotInitialization);
                }

                var product = storeController.products.WithID(productId);

                // 購入できないアイテムの場合.
                if (product == null || !product.availableToPurchase)
                {
                    return(BuyFailureReason.UnknownItem);
                }

                // 通信不可の場合は何もしない(初期化は終了済み).
                if (!NetworkConnection())
                {
                    return(BuyFailureReason.NetworkUnavailable);
                }

                // Androidの場合はDeveloperPayloadを送る.
                if (Application.platform == RuntimePlatform.Android)
                {
                    storeController.InitiatePurchase(product, developerPayload);
                }
                else
                {
                    storeController.InitiatePurchase(product);
                }

                IsPurchaseing = true;

                return(BuyFailureReason.None);
            }
            catch (Exception)
            {
                // 何らかのエラーが発生(課金は未発生).
                return(BuyFailureReason.Unknown);
            }
        }
 public void OnClickNoAdsProductBuy()
 {
     if (storeController != null)
     {
         Debug.Log("구매 실패 : 결제 기능 초기화 실패");
     }
     else
     {
         storeController.InitiatePurchase(productID);
     }
 }
Beispiel #10
0
 public void Buy(Product product)
 {
     if (_store == null)
     {
         throw new UnityException("Not properly inited");
     }
     Check();
     LogUtils.Log("Buy " + product.definition.id);
     if (!product.availableToPurchase)
     {
         LogUtils.Log("Product " + product.definition.id + " is not available to purchase");
         return;
     }
     _store.InitiatePurchase(product, null);
 }
Beispiel #11
0
        /// <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 (productId == "restore")
            {
                RestoreTransactions();
            }
            else
            {
                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.isVirtual)
                {
                    PurchaseProduct(obj);
                }
                else
                {
                    controller.InitiatePurchase(controller.products.WithID(productId));
                }
            }
        }
Beispiel #12
0
    private void InitUI(HashSet <ProductDefinition> items)
    {
        foreach (var item in items)
        {
            // Add initial pre-IAP-initialization content. Update later in OnInitialized.
            var description = string.Format("{0} - {1}", item.id, item.type);
            Debug.LogError(description);
            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(() => {
            m_Controller.InitiatePurchase(m_Controller.products.all[m_SelectedItemIndex]);
        });

        GetRestoreButton().onClick.AddListener(() => {
            m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
        });
    }
Beispiel #13
0
        //*******************************************************************
        // PURCHASE
        //*******************************************************************
        /// <summary>
        /// Try to Purchase a product
        /// <param name="productID">Product ID</param>
        /// </summary>
        public PurchaseRequest PurchaseProduct(string productID)
        {
            if (!IsInit)
            {
                Debug.LogWarning("Cannot purchase product. IAPManager not successfully initialized!");
                return(PurchaseRequest.NoInit);
            }

            var product = GetProduct(productID);

            if (product == null)
            {
                return(PurchaseRequest.ProductUnavailable);
            }

            if (!product.availableToPurchase)
            {
                Debug.LogWarning($"Cannot purchase product {productID}. Not available for purchase.");
                return(PurchaseRequest.PurchasingUnavailable);
            }

            // try to purchase product.
            storeController.InitiatePurchase(product);

            return(PurchaseRequest.Ok);
        }
Beispiel #14
0
 public void InitiatePurchase(Product product, string payload)
 {
     if (IsInitialized())
     {
         m_Controller.InitiatePurchase(product, payload);
     }
 }
Beispiel #15
0
    public void BuyProductByID(int purchaseType, string orderId, string productId)
    {
        Debug.Log(string.Format("BuyProductByID: {0}", productId));
        if (!IsInitialized())
        {
            Debug.Log("BuyProductByID Failed! Not Initialized!");

            PURCHASE_INFO info = new PURCHASE_INFO();
            info.iBillingType = purchaseType;
            info.strOrderId   = orderId;
            info.strProductId = productId;
            _fnPurchaseCallback(false, info);

            return;
        }

        Debug.Log("SDK::通用接口,直接开启订单");
        Product product = _storeController.products.WithID(productId);

        if (product == null)
        {
            Debug.Log("product is null");
        }
        if (product != null && product.availableToPurchase == false)
        {
            Debug.Log("product is not availableToPurchase");
        }

        if (product != null && product.availableToPurchase)
        {
            Debug.Log(string.Format("直接开启订单: {0}", product.definition.id));
            //开启支付
            _storeController.InitiatePurchase(product, orderId);
        }
    }
Beispiel #16
0
 //This function checking everything when trying to buy something and return errors
 private void BuyProductID(string productId)
 {
     //Checking that is initializated
     if (IsInitialized())
     {
         //Making a new product of an given productID
         Product product = m_StoreController.products.WithID(productId);
         //There you are able to purchase
         if (product != null && product.availableToPurchase)
         {
             Debug.Log(string.Format("Buying product: '{0}'", product.definition.id));
             m_StoreController.InitiatePurchase(product);
         }
         else
         {
             //You are initializated but product can be null or you cant purchase it
             this.GetComponent <MenuManagerScript>().IAPCallbackError();
         }
     }
     else
     {
         //Retrying initialization
         InitializePurchasing();
         //You are not initializated
         this.GetComponent <MenuManagerScript>().IAPInitializeError();
     }
 }
    public void PurchaseProduct(string productId)
    {
        if (IsInitialized())
        {
            Product product = productController.products.WithID(productId);

            if (product != null && product.availableToPurchase)
            {
                Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));

                // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
                // asynchronously.

                productController.InitiatePurchase(product);
            }
            else
            {
                Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
            }
        }
        else
        {
            Debug.Log("BuyProductID FAIL. Not initialized.");
        }
    }
    public void BuyProductID(string id)
    {
        if (!IsInitialized( ))
        {
            MessageDialogs.ShowMessageDialog(
                "Store Error",
                "Store is not yet initialized.",
                "OK", null);
            return;
        }

        Product product = _storeController.products.WithID(productID);

        if (product == null)
        {
            MessageDialogs.ShowMessageDialog(
                "Store Error",
                "Problem retrieving product.",
                "OK", null);
            return;
        }

        // starting purchase, is async so will need some sort of loading pop-up
        _storeController.InitiatePurchase(product);
    }
Beispiel #19
0
 public void OnBtnPurchaseClicked(int itemId)
 {
     if (storeController == null)
     {
         Debug.Log("구매 실패 : 결제 기능 초기화 실패");
     }
     else
     {
         buyItemId = itemId;
         int index = -1;
         for (var i = 0; i < sProductIds.Length; i++)
         {
             if (sProductIds[i].Equals(buyItemId) || sProductIds[i] == buyItemId.ToString())
             {
                 index = i;
                 break;
             }
         }
         if (index != -1)
         {
             storeController.InitiatePurchase(sProductIds[index]);
         }
         else
         {
             Debug.Log("구매 실패 : 결제 상품 존재하지 않음");
         }
     }
 }
Beispiel #20
0
 public void BuyProductId(string productId, string payload, Action <bool, string> callback)
 {
     try
     {
         if (IsInitialized())
         {
             var p = _storeController.products.WithID(productId);
             if (p != null && p.availableToPurchase)
             {
                 _onBuyProductCallback = callback;
                 Log.Verbose(nameof(UnityInAppPurchaser), string.Format("Purchasing product asychronously: '{0}'", p.definition.id));
                 _storeController.InitiatePurchase(p, payload);
             }
             else
             {
                 callback.CallSafe(false, null);
                 Log.Verbose(nameof(UnityInAppPurchaser),
                             "BuyProductId: FAIL. Not purchasing product, either is not found or is not available for purchase");
             }
         }
         else
         {
             callback.CallSafe(false, null);
             Log.Verbose(nameof(UnityInAppPurchaser), "BuyProductId FAIL. Not initialized.");
         }
     }
     catch (Exception e)
     {
         callback.CallSafe(false, null);
         Log.Verbose(nameof(UnityInAppPurchaser), "BuyProductId: FAIL. Exception during purchase. " + e);
     }
 }
Beispiel #21
0
 public void BuyProductID(string productId)
 {
     try
     {
         if (IsInitialized())
         {
             Product p = storeController.products.WithID(productId);
             if (p != null && p.availableToPurchase)
             {
                 storeController.InitiatePurchase(p);
             }
             else
             {
                 Debug.Log("구매 실패 #1");
             }
         }
         else
         {
             Debug.Log("구매 실패 #2");
         }
     }
     catch (Exception e)
     {
         Debug.Log("구매 실패 #" + e);
     }
 }
Beispiel #22
0
    public void BuyProductID(string productID)
    {
#if UNITY_EDITOR
        BuyJewel(productId);
#elif UNITY_ANDROID
        productId = productID;
        try
        {
            if (storeController != null)
            {
                Product p = storeController.products.WithID(productID);
                if (p != null && p.availableToPurchase)
                {
                    storeController.InitiatePurchase(p);
                }
                else if (p != null && p.hasReceipt)
                {
                    Debug.Log("BuyProductID : Fail. The Non Consumable product has already been bought.");
                }
                else
                {
                    Debug.Log("BuyProductID : Fail. Not purchasing product, either is not found or is not available for purchase");
                }
            }
            else
            {
                Debug.Log("BuyProductID : Fail. Not initialized.");
            }
        }
        catch (System.Exception e)
        {
            Debug.Log(string.Format("BuyProductID : Fail. Exception during purchase. - error : {0}", e));
        }
#endif
    }
Beispiel #23
0
 public void BuyProductID(UIPurchaseSlot slot)
 {
     Debug.Log("!!!!!!!! BuyProductID Enter");
     try
     {
         if (IsInitialized())
         {
             mPurchaseSlot = slot;
             Debug.Log("mPurchaseSlot.PurchaseID " + mPurchaseSlot.PurchaseID);
             //Product p = storeController.products.WithID(productId);
             Product p = storeController.products.WithID(mPurchaseSlot.PurchaseID);
             Debug.Log("mPurchaseSlot.PurchaseID " + mPurchaseSlot.PurchaseID);
             if (p != null && p.availableToPurchase)
             {
                 Debug.Log("Purchasing product asychronously: '{0}'" + p.definition.id);
                 storeController.InitiatePurchase(p);
             }
             else
             {
                 Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
             }
         }
         else
         {
             Debug.Log("BuyProductID FAIL. Not initialized.");
         }
     }
     catch (Exception e)
     {
         Debug.Log("BuyProductID: FAIL. Exception during purchase. " + e);
     }
 }
Beispiel #24
0
        /// <summary>
        /// Purchases the product with specified ID.
        /// </summary>
        /// <param name="productId">Product identifier.</param>
        public static void PurchaseWithId(string productId)
        {
#if EM_UIAP
            if (IsInitialized())
            {
                Product product = sStoreController.products.WithID(productId);

                if (product != null && product.availableToPurchase)
                {
                    Debug.Log("Purchasing product asychronously: " + product.definition.id);

                    // Buy the product, expect a response either through ProcessPurchase or OnPurchaseFailed asynchronously.
                    sStoreController.InitiatePurchase(product);
                }
                else
                {
                    Debug.Log("IAP purchasing failed: product not found or not available for purchase.");
                }
            }
            else
            {
                // Purchasing has not succeeded initializing yet.
                Debug.Log("IAP purchasing failed: In-App Purchasing is not initialized.");
            }
#else
            Debug.Log("IAP purchasing failed: In-App Purchasing module is not enabled.");
#endif
        }
Beispiel #25
0
        public void purchaseItem(int item)
        {
            if (storeControler == null)
            {
                initStore();
                Debug.Log("결재실패. 원인:결재기능 초기화 실패 -> 재시도");
            }
            else
            {
                int index;

                if (item == 400)
                {
                    index = 0;              //샤넬No5
                }
                else if (item == 401)
                {
                    index = 1;                   //에어팟
                }
                else if (item == 402)
                {
                    index = 2;                   //스벅텀블러
                }
                else if (item == 403)
                {
                    index = 3;                   //정관장홍삼정
                }
                else
                {
                    return;
                }

                storeControler.InitiatePurchase(sProductIds[index]);
            }
        }
Beispiel #26
0
    public void PurchaseButtonClick(string productID)
    {
        if (m_PurchaseInProgress == true)
        {
            Debug.Log("Please wait, purchase in progress");
            return;
        }

        if (m_Controller == null)
        {
            Debug.LogError("Purchasing is not initialized");
            return;
        }

        if (m_Controller.products.WithID(productID) == null)
        {
            Debug.LogError("No product has id " + productID);
            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.WithID(productID), "aDemoDeveloperPayload");
    }
Beispiel #27
0
    public void Buy(string pid)
    {
        if (m_Controller == null)
        {
            Debug.Log("--->> errror m_Controller == null");
            return;
        }
        if (m_PurchaseInProgress == true)
        {
            return;
        }
        Product selected = CheckProduct(pid);

        if (selected != null)
        {
            m_Controller.InitiatePurchase(CheckProduct(pid));
            // 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;
        }
        else
        {
            Debug.Log("--->> Buy() 没有找到支付产品对象 selected == null");
            m_PurchaseInProgress = false;
        }
    }
Beispiel #28
0
    public void InitiatePurchase(string _productId, System.Action _onInitiatePurchaseSuccess = null)
    {
        purchasingProductId = _productId;
        if (!IsInitialized())
        {
            InitializePurchasing(false);
            return;
        }

        if (m_StoreController.products.WithID(_productId) == null)
        {
            PopupManager.Instance.CreatePopupMessage(MyLocalize.GetString(MyLocalize.kError)
                                                     , MyLocalize.GetString("Error/IAP_CanNotFindPackage")
                                                     , string.Empty
                                                     , MyLocalize.GetString(MyLocalize.kOk));
            return;
        }

        m_StoreController.InitiatePurchase(_productId);

        if (_onInitiatePurchaseSuccess != null)
        {
            _onInitiatePurchaseSuccess();
        }
    }
Beispiel #29
0
    public void PurchaseButtonClick(string productID)
    {
        if (m_PurchaseInProgress)
        {
            Debug.Log("Please wait, purchase in progress");
            return;
        }

        if (m_Controller == null)
        {
            Debug.LogError("Purchasing is not initialized");
            return;
        }

        if (m_Controller.products.WithID(productID) == null)
        {
            Debug.LogError("No product has id " + productID);
            return;
        }

        // 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;

        //Sample code how to add accountId in developerPayload to pass it to getBuyIntentExtraParams
        //Dictionary<string, string> payload_dictionary = new Dictionary<string, string>();
        //payload_dictionary["accountId"] = "Faked account id";
        //payload_dictionary["developerPayload"] = "Faked developer payload";
        //m_Controller.InitiatePurchase(m_Controller.products.WithID(productID), MiniJson.JsonEncode(payload_dictionary));
        m_Controller.InitiatePurchase(m_Controller.products.WithID(productID), "developerPayload");
    }
Beispiel #30
0
    void BuyProductID(string productId)
    {
        if (IsInitialized())
        {
            Product product = storeController.products.WithID(productId);

            if (product != null && product.availableToPurchase)
            {
                Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
                storeController.InitiatePurchase(product);
            }
            // Otherwise ...
            else
            {
                // ... report the product look-up failure situation
                Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
            }
        }
        // Otherwise ...
        else
        {
            // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
            // retrying initiailization.
            Debug.Log("BuyProductID FAIL. Not initialized.");
        }
    }