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