Exemplo n.º 1
0
        public void Purchase(CocoStoreID id, Action <BuyItemResult> doneAction = null)
        {
            var itemData = StoreConfigData.GetItemData(id);

            if (itemData == null)
            {
                if (doneAction != null)
                {
                    doneAction(new BuyItemResult(BuyItemResultCode.Error));
                }
                return;
            }

            if (!IsBillingAvailable)
            {
                if (doneAction != null)
                {
                    doneAction(new BuyItemResult(BuyItemResultCode.Error));
                }
//				CocoMainController.ShowNoInternetPopup ();
                return;
            }

            StoreManager.BuyItem(itemData.Key).Done(result => OnPurchaseDone(itemData, result, doneAction));
        }
Exemplo n.º 2
0
        private void RefreshAllItemState()
        {
            var psdkBilling = PSDKBilling;

            if (psdkBilling == null)
            {
                return;
            }

            var products = PSDKBilling.storeController.products;

            foreach (var product in products.all)
            {
                var itemKey  = psdkBilling.GetMainId(product.definition.storeSpecificId);
                var itemData = StoreConfigData.GetItemData(itemKey);
                if (itemData == null)
                {
                    continue;
                }

                itemData.ProductType = product.definition.type;
                UpdateItemPurchaseState(itemData, psdkBilling.IsPurchased(itemData.Key));
            }

            RefreshNoAdsState();
        }
Exemplo n.º 3
0
        private bool IsPurchased(CocoStoreID id, HashSet <CocoStoreID> excludedParentIds, bool checkSlots)
        {
            var itemData = StoreConfigData.GetItemData(id);

            if (itemData == null)
            {
                return(false);
            }

            // check if self is purchased
            if (itemData.IsPurchased)
            {
                return(true);
            }

            excludedParentIds.Add(itemData.Id);

            // check if any parent is purchased
            foreach (var parentId in itemData.ParentIds)
            {
                if (excludedParentIds.Contains(parentId))
                {
                    continue;
                }

                if (IsPurchased(parentId, excludedParentIds, false))
                {
                    return(true);
                }
            }

            // check slots
            if (!checkSlots || itemData.SlotIds.Count <= 0)
            {
                return(false);
            }

            // check if all slots are purchased
            foreach (var slotId in itemData.SlotIds)
            {
                if (!IsPurchased(slotId, excludedParentIds, true))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public string GetPriceString(CocoStoreID id, bool useISOCurrencySymbol = false)
        {
            var itemData = StoreConfigData.GetItemData(id);

            if (itemData == null)
            {
                return(string.Empty);
            }

            if (!useISOCurrencySymbol)
            {
                return(BillingService.GetLocalizedPriceString(itemData.Key));
            }

            var symbol = BillingService.GetISOCurrencySymbol(itemData.Key);

            return(string.Format("{0} {1}", symbol, BillingService.GetPriceInLocalCurrency(itemData.Key)));
        }
Exemplo n.º 5
0
        private void OnIAPPurchaseDone(PurchaseIAPResult iapResult)
        {
            if (!IsAutoRestoreInProgress)
            {
                return;
            }

            var itemKey  = PSDKBilling.GetMainId(iapResult.purchasedItem.id);
            var itemData = StoreConfigData.GetItemData(itemKey);

            if (itemData == null)
            {
                return;
            }

            var resultCode    = (iapResult.result == PurchaseIAPResultCode.Success) ? BuyItemResultCode.Success : BuyItemResultCode.InAppPurchaseFailed;
            var buyItemResult = new BuyItemResult(resultCode, iapResult);

            OnPurchaseDone(itemData, buyItemResult, null);
        }