예제 #1
0
        /// <summary>
        /// Handles the <c>onMarketItemsRefreshFinished</c> event, which is fired when items associated with market are
        /// refreshed (prices, titles ...).
        /// </summary>
        /// <param name="message">Message that contains information about the process that is occurring.</param>
        public void onMarketItemsRefreshFinished(string message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onMarketItemsRefreshFinished: " + message);

            var eventJSON = new JSONObject(message);

            List <MarketItem> marketItems = new List <MarketItem>();

            foreach (var micJSON in eventJSON.list)
            {
                string productId          = micJSON[StoreJSONConsts.MARKETITEM_PRODUCT_ID].str;
                string marketPrice        = micJSON[StoreJSONConsts.MARKETITEM_MARKETPRICE].str;
                string marketTitle        = micJSON[StoreJSONConsts.MARKETITEM_MARKETTITLE].str;
                string marketDescription  = micJSON[StoreJSONConsts.MARKETITEM_MARKETDESC].str;
                string marketCurrencyCode = micJSON[StoreJSONConsts.MARKETITEM_MARKETCURRENCYCODE].str;
                long   marketPriceMicros  = System.Convert.ToInt64(micJSON[StoreJSONConsts.MARKETITEM_MARKETPRICEMICROS].n);
                try {
                    PurchasableVirtualItem pvi = StoreInfo.GetPurchasableItemWithProductId(productId);
                    MarketItem             mi  = ((PurchaseWithMarket)pvi.PurchaseType).MarketItem;
                    mi.MarketPriceAndCurrency = marketPrice;
                    mi.MarketTitle            = marketTitle;
                    mi.MarketDescription      = marketDescription;
                    mi.MarketCurrencyCode     = marketCurrencyCode;
                    mi.MarketPriceMicros      = marketPriceMicros;
                    pvi.Save();

                    marketItems.Add(mi);
                } catch (VirtualItemNotFoundException ex) {
                    SoomlaUtils.LogDebug(TAG, ex.Message);
                }
            }

            StoreEvents.OnMarketItemsRefreshFinished(marketItems);
        }
예제 #2
0
        /// <summary>
        /// Handles the <c>onMarketItemsRefreshFinished</c> event, which is fired when items associated with market are
        /// refreshed (prices, titles ...).
        /// </summary>
        /// <param name="message">Message that contains information about the process that is occurring.</param>
        public void onMarketItemsRefreshFinished(string message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onMarketItemsRefreshFinished: " + message);

            string[]          marketItemsChanges = Regex.Split(message, "#SOOM#");
            List <MarketItem> marketItems        = new List <MarketItem>();

            foreach (string mic in marketItemsChanges)
            {
                if (string.IsNullOrEmpty(mic.Trim()))
                {
                    continue;
                }

                JSONObject micJSON           = new JSONObject(mic);
                string     productId         = micJSON["productId"].str;
                string     marketPrice       = micJSON["market_price"].str;
                string     marketTitle       = micJSON["market_title"].str;
                string     marketDescription = micJSON["market_desc"].str;
                try {
                    PurchasableVirtualItem pvi = StoreInfo.GetPurchasableItemWithProductId(productId);
                    MarketItem             mi  = ((PurchaseWithMarket)pvi.PurchaseType).MarketItem;
                    mi.MarketPrice       = marketPrice;
                    mi.MarketTitle       = marketTitle;
                    mi.MarketDescription = marketDescription;
                    pvi.save();

                    marketItems.Add(mi);
                } catch (VirtualItemNotFoundException ex) {
                    SoomlaUtils.LogDebug(TAG, ex.Message);
                }
            }

            StoreEvents.OnMarketItemsRefreshFinished(marketItems);
        }
예제 #3
0
        public static void onMarketItemsRefreshFinished(MarketItemsRefreshFinishedEvent _Event)
        {
            List <SoomlaWpStore.domain.MarketItem> pluginMarketItems = _Event.GetMarketItems();

            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onMarketItemsRefreshFinished: " + pluginMarketItems.Count);

            List <MarketItem> marketItems = new List <MarketItem>();

            foreach (SoomlaWpStore.domain.MarketItem mic in pluginMarketItems)
            {
                try
                {
                    PurchasableVirtualItem pvi = StoreInfo.GetPurchasableItemWithProductId(mic.getProductId());
                    MarketItem             mi  = ((PurchaseWithMarket)pvi.PurchaseType).MarketItem;
                    mi.MarketPriceAndCurrency = mic.getMarketPrice();
                    mi.MarketTitle            = mic.getMarketTitle();
                    mi.MarketDescription      = mic.getMarketDescription();
                    if (mic.isPriceSuccessfullyParsed())
                    {
                        mi.MarketPriceMicros  = mic.getMarketPriceMicros();
                        mi.MarketCurrencyCode = mic.getMarketCurrencyCode();
                    }
                    pvi.Save();

                    marketItems.Add(mi);
                }
                catch (VirtualItemNotFoundException ex)
                {
                    SoomlaUtils.LogDebug(TAG, ex.Message);
                }
            }

            StoreEvents.OnMarketItemsRefreshFinished(marketItems);
        }
예제 #4
0
        protected virtual void _buyMarketItem(string productId, string payload)
        {
#if UNITY_EDITOR
            PurchasableVirtualItem item = StoreInfo.GetPurchasableItemWithProductId(productId);
            if (item == null)
            {
                throw new VirtualItemNotFoundException("ProductId", productId);
            }

            // in the editor we just give the item... no real market.
            item.Give(1);
#endif
        }
예제 #5
0
        protected virtual void _buyMarketItem(string productId, string payload)
        {
#if UNITY_EDITOR
            PurchasableVirtualItem item = StoreInfo.GetPurchasableItemWithProductId(productId);
            if (item == null)
            {
                throw new VirtualItemNotFoundException("ProductId", productId);
            }

            // simulate onMarketPurchaseStarted event
            var eventJSON = new JSONObject();
            eventJSON.AddField("itemId", item.ItemId);
            eventJSON.AddField("payload", payload);
            StoreEvents.Instance.onMarketPurchaseStarted(eventJSON.print());

            // simulate events as they happen on the device
            // the order is :
            //    onMarketPurchase
            //    give item
            //    onItemPurchase
            StoreEvents.Instance.RunLater(() => {
                eventJSON = new JSONObject();
                eventJSON.AddField("itemId", item.ItemId);
                eventJSON.AddField("payload", payload);
                var extraJSON = new JSONObject();
                        #if UNITY_IOS
                extraJSON.AddField("receipt", "fake_receipt_abcd1234");
                extraJSON.AddField("token", "fake_token_zyxw9876");
                        #elif UNITY_ANDROID
                extraJSON.AddField("orderId", "fake_orderId_abcd1234");
                extraJSON.AddField("purchaseToken", "fake_purchaseToken_zyxw9876");
                        #endif
                eventJSON.AddField("extra", extraJSON);
                StoreEvents.Instance.onMarketPurchase(eventJSON.print());

                // in the editor we just give the item... no real market.
                item.Give(1);

                // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events.
                StoreEvents.Instance.RunLater(() => {
                    eventJSON = new JSONObject();
                    eventJSON.AddField("itemId", item.ItemId);
                    eventJSON.AddField("payload", payload);
                    StoreEvents.Instance.onItemPurchased(eventJSON.print());
                });
            });
#endif
        }
예제 #6
0
        /// <summary>
        /// Handles the <c>onMarketItemsRefreshFinished</c> event, which is fired when items associated with market are
        /// refreshed (prices, titles ...).
        /// </summary>
        /// <param name="message">Message that contains information about the process that is occurring.</param>
        public void onMarketItemsRefreshFinished(string message)
        {
            SoomlaUtils.LogDebug(TAG, "SOOMLA/UNITY onMarketItemsRefreshFinished: " + message);

            string[]          marketItemsChanges = Regex.Split(message, "#SOOM#");
            List <MarketItem> marketItems        = new List <MarketItem>();

            foreach (string mic in marketItemsChanges)
            {
                if (string.IsNullOrEmpty(mic.Trim()))
                {
                    continue;
                }

                JSONObject micJSON            = new JSONObject(mic);
                string     productId          = micJSON[JSONConsts.MARKETITEM_PRODUCT_ID].str;
                string     marketPrice        = micJSON[JSONConsts.MARKETITEM_MARKETPRICE].str;
                string     marketTitle        = micJSON[JSONConsts.MARKETITEM_MARKETTITLE].str;
                string     marketDescription  = micJSON[JSONConsts.MARKETITEM_MARKETDESC].str;
                string     marketCurrencyCode = micJSON[JSONConsts.MARKETITEM_MARKETCURRENCYCODE].str;
                long       marketPriceMicros  = System.Convert.ToInt64(micJSON[JSONConsts.MARKETITEM_MARKETPRICEMICROS].n);
                try {
                    PurchasableVirtualItem pvi = StoreInfo.GetPurchasableItemWithProductId(productId);
                    MarketItem             mi  = ((PurchaseWithMarket)pvi.PurchaseType).MarketItem;
                    mi.MarketPriceAndCurrency = marketPrice;
                    mi.MarketTitle            = marketTitle;
                    mi.MarketDescription      = marketDescription;
                    mi.MarketCurrencyCode     = marketCurrencyCode;
                    mi.MarketPriceMicros      = marketPriceMicros;
                    pvi.save();

                    marketItems.Add(mi);
                } catch (VirtualItemNotFoundException ex) {
                    SoomlaUtils.LogDebug(TAG, ex.Message);
                }
            }

            StoreEvents.OnMarketItemsRefreshFinished(marketItems);
        }