private EventQueue(IUtil util, IAsyncWebUtil webUtil)
 {
     m_AsyncUtil = webUtil;
     Profile     = ProfileData.Instance(util);
     ProfileDict = Profile.GetProfileDict();
     AdsIPC.InitAdsIPC(util);
 }
示例#2
0
        protected void SendPurchaseFailedEvent(PurchaseFailureDescription failure, string json)
        {
#if HIGH_PERMISSION_DATA
            if (promoPayload != null)
            {
                promoPayload["type"] = "iap.purchasefailed";
                promoPayload.Add("purchase", "FAILED");
                if (json != null)
                {
                    promoPayload.Add("failureJSON", json);
                }

                var purchaseEvent = new PurchasingEvent(promoPayload);
                var profileDict   = m_profileData.GetProfileDict();
                var eventjson     = purchaseEvent.FlatJSON(profileDict);

                m_EventQueue.SendEvent(EventDestType.IAP, eventjson); // don't use Ads tracking event here

                promoPayload.Clear();
                promoPayload = null;
            }
            else
            {
                // enriched "organic" purchases here

                Product thisProduct = unity.products.WithStoreSpecificID(failure.productId);

                if (thisProduct != null)
                {
                    var purchaseDict = new Dictionary <string, object>();
                    purchaseDict.Add("type", "iap.purchasefailed");
                    purchaseDict.Add("iap_service", true);
                    purchaseDict.Add("iapPromo", false);
                    purchaseDict.Add("purchase", "FAILED");
                    purchaseDict.Add("productId", thisProduct.definition.id);
                    purchaseDict.Add("storeSpecificId", thisProduct.definition.storeSpecificId);
                    purchaseDict.Add("amount", thisProduct.metadata.localizedPrice);
                    purchaseDict.Add("currency", thisProduct.metadata.isoCurrencyCode);
                    if (json != null)
                    {
                        purchaseDict.Add("failureJSON", json);
                    }

                    var purchaseEvent = new PurchasingEvent(purchaseDict);
                    var profileDict   = ProfileData.Instance(m_Module.util).GetProfileDict();
                    var eventjson     = purchaseEvent.FlatJSON(profileDict);

                    m_EventQueue.SendEvent(EventDestType.IAP, eventjson, eventBaseUrl + "/v1/organic_purchase");
                }
            }
#endif
        }
        //stg private const string kCatalogURL = "https://ecommerce-iap-stg.ie.unityads.unity3d.com";
        //qa  private const string kCatalogURL = "http://ec2-35-172-194-34.compute-1.amazonaws.com:8000";

        /// <summary>
        /// Fetches a Product catalog for the given parameters from the given catalog service. Returns null if
        /// either current ProfileData or key input parameters are incomplete.
        /// </summary>
        /// <param name="storeName">if null or empty, returns a null catalog provider</param>
        /// <param name="baseUrl">if null or empty, returns a null catalog provider</param>
        /// <param name="webUtil"></param>
        /// <param name="logger"></param>
        /// <param name="util"></param>
        /// <returns></returns>
        public static StoreCatalogImpl CreateInstance(string storeName, string baseUrl, IAsyncWebUtil webUtil, ILogger logger, IUtil util, JSONStore baseStore = null)
        {
            if ((String.IsNullOrEmpty(storeName)) || (String.IsNullOrEmpty(baseUrl)))
            {
                return(null);
            }


            if (logger == null)
            {
                logger = UnityEngine.Debug.unityLogger;
            }
            profile = ProfileData.Instance(util);
            Dictionary <string, object> queryParams = profile.GetProfileIds();

            if ((baseStore != null) && baseStore.disableStoreCatalog)
            {
                queryParams.Add("storeDisabled", "true");
            }
            var storeCatalogURL = baseUrl + "/catalog" + queryParams.ToQueryString();
            var fileReference   = FileReference.CreateInstance(kFileName, logger, util);

            return(new StoreCatalogImpl(webUtil, logger, storeCatalogURL, storeName, fileReference));
        }
示例#4
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");
                }
            }
        }
示例#5
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);
            }
        }