예제 #1
0
        private static void ProvideProductsToAds(HashSet <Product> productsForAds)
        {
            var promos = new List <Dictionary <string, object> >();

            if (productsForAds != null)
            {
                foreach (var product in productsForAds)
                {
                    var promoDic = new Dictionary <string, object>();
                    promoDic.Add("productId", product.definition.id);
                    promoDic.Add("iapProductId", product.definition.id);
                    promoDic.Add("productType", product.definition.type.ToString());
                    promoDic.Add("localizedPriceString", product.metadata.localizedPriceString);
                    promoDic.Add("localizedTitle", product.metadata.localizedTitle);
                    promoDic.Add("imageUrl", null);
                    promoDic.Add("isoCurrencyCode", product.metadata.isoCurrencyCode);
                    promoDic.Add("localizedPrice", product.metadata.localizedPrice);
                    promos.Add(promoDic);
                }
            }

            // Now storing the last-delivered JSON for future queries
            s_ProductJSON = MiniJSON.Json.Serialize(promos);
            if (promos.Count > 0)
            {
                s_IsReady = true;

#if HIGH_PERMISSION_DATA
                // Send an async notification to Ads SDK to simplify refresh on their end
                var eventSys = EventQueue.Instance(s_Util, s_WebUtil);
                eventSys.SendEvent(EventDestType.AdsIPC, "{\"type\":\"CatalogUpdated\"}");
#endif
            }
        }
예제 #2
0
        public override void Initialize(IStoreCallback callback)
        {
            this.unity    = callback;
            m_EventQueue  = EventQueue.Instance(m_Module.util, m_Module.webUtil);
            m_profileData = ProfileData.Instance(m_Module.util);

            if (m_Module != null)
            {
                var storeName = m_Module.storeInstance.storeName;
                m_profileData.SetStoreName(storeName);
                if (String.IsNullOrEmpty(iapBaseUrl))
                {
                    iapBaseUrl = kIecCatalogBase;
                }
                m_managedStore = StoreCatalogImpl.CreateInstance(storeName, iapBaseUrl, m_Module.webUtil, m_Module.logger, m_Module.util, this);
            }
            else
            {
                if (m_Logger != null)
                {
                    m_Logger.LogWarning("UnityIAP", "JSONStore init has no reference to SPM, can't start managed store");
                }
            }
        }
예제 #3
0
        public static bool InitiatePurchasingCommand(string command)
        {
            if (String.IsNullOrEmpty(command))
            {
                if (s_Logger != null)
                {
                    s_Logger.LogFormat(LogType.Warning, "Promo received null or empty command");
                }
                return(false);
            }

            // Keep for debug for now...
            // if(s_Logger != null)
            // {
            //     s_Logger.LogFormat(LogType.Log, "Promo.IPC({0})", command);
            // }

            Dictionary <string, object> dict = null;
            string request;

            // MiniJSON has been known to throw unexpected exceptions, let's try
            // to deal with them here...
            try
            {
                object req;
                dict = (Dictionary <string, object>)MiniJSON.Json.Deserialize(command);
                if (dict == null)
                {
                    return(false);
                }

                // extract & deal with purchaseTrackingUrls first...
                object sentUrls;
                if (dict.TryGetValue("purchaseTrackingUrls", out sentUrls))
                {
                    if (sentUrls != null)
                    {
                        List <object> trackingUrls = sentUrls as List <object>;

                        var eventSys = EventQueue.Instance(s_Util, s_WebUtil);

                        // This is not a great solution, but nobody seems to want
                        // to guarantee what trackingUrls will include...
                        if (trackingUrls.Count > 0)
                        {
                            eventSys.SetIapUrl(trackingUrls[0] as string);
                        }
                        if (trackingUrls.Count > 1)
                        {
                            eventSys.SetAdsUrl(trackingUrls[1] as string);
                        }
                    }
                    dict.Remove("purchaseTrackingUrls");
                }

                // Back to JSON for if/when sent to old purchasing method
                command = MiniJSON.Json.Serialize(dict);

                if (!dict.TryGetValue("request", out req))
                {
                    // pass this to the old IPP
                    return(ExecPromoPurchase(command));
                }
                else
                {
                    request = ((String)req).ToLower();
                }
                switch (request)
                {
                case "purchase":
                    return(ExecPromoPurchase(command));

                case "setids":
                    var    profile = ProfileData.Instance(s_Util);
                    object param;

                    if (dict.TryGetValue("gamerToken", out param))
                    {
                        profile.SetGamerToken(param as string);
                    }
                    if (dict.TryGetValue("trackingOptOut", out param))
                    {
                        profile.SetTrackingOptOut(param as bool?);
                    }
                    if (dict.TryGetValue("gameId", out param))
                    {
                        profile.SetGameId(param as string);
                    }
                    if (dict.TryGetValue("abGroup", out param))
                    {
                        profile.SetABGroup(param as int?);
                    }

                    return(true);

                case "close":
                    // I don't think we're currently receiving these
                    if (s_Logger != null)
                    {
                        s_Logger.Log("UnityIAP Promo: AdUnit closed without purchase");
                    }
                    // we may want to send an event here
                    return(true);

                default:
                    if (s_Logger != null)
                    {
                        s_Logger.LogWarning("UnityIAP Promo", "Unknown request received: " + request);
                    }
                    return(false);
                }
            }
            catch (Exception e)
            {
                if (s_Logger != null)
                {
                    s_Logger.LogError("UnityIAP Promo", "Exception while processing incoming request: " + e
                                      + "\n" + command);
                }
                return(false);
            }
        }