Beispiel #1
0
        public static string Serialize(StoreConfiguration store)
        {
            var dic = new Dictionary <string, object>()
            {
                { "androidStore", store.androidStore.ToString() }
            };

            return(MiniJson.JsonEncode(dic));
        }
        public static string SerializeProductDescs(IEnumerable <ProductDescription> products)
        {
            List <object> result = new List <object>();

            foreach (var product in products)
            {
                result.Add(EncodeProductDesc(product));
            }
            return(MiniJson.JsonEncode(result));
        }
Beispiel #3
0
        public string getSubscriptionInfoJsonString()
        {
            Dictionary <string, object> dict = new Dictionary <string, object>();

            dict.Add("productId", this.productId);
            dict.Add("is_free_trial", this.is_free_trial);
            dict.Add("is_introductory_price_period", this.is_introductory_price_period == Result.True);
            dict.Add("remaining_time_in_seconds", this.remainedTime.TotalSeconds);
            return(MiniJson.JsonEncode(dict));
        }
        public static Dictionary <string, string> DeserializeProductDetails(string json)
        {
            var objects = (List <object>)MiniJson.JsonDecode(json);
            var result  = new Dictionary <string, string>();

            foreach (Dictionary <string, object> obj in objects)
            {
                var details = new Dictionary <string, string>();
                if (obj.TryGetValue("metadata", out var metadata))
                {
                    var metadataStr = (Dictionary <string, object>)metadata;
                    details["subscriptionNumberOfUnits"]        = metadataStr.TryGetString("subscriptionNumberOfUnits");
                    details["subscriptionPeriodUnit"]           = metadataStr.TryGetString("subscriptionPeriodUnit");
                    details["localizedPrice"]                   = metadataStr.TryGetString("localizedPrice");
                    details["isoCurrencyCode"]                  = metadataStr.TryGetString("isoCurrencyCode");
                    details["localizedPriceString"]             = metadataStr.TryGetString("localizedPriceString");
                    details["localizedTitle"]                   = metadataStr.TryGetString("localizedTitle");
                    details["localizedDescription"]             = metadataStr.TryGetString("localizedDescription");
                    details["introductoryPrice"]                = metadataStr.TryGetString("introductoryPrice");
                    details["introductoryPriceLocale"]          = metadataStr.TryGetString("introductoryPriceLocale");
                    details["introductoryPriceNumberOfPeriods"] = metadataStr.TryGetString("introductoryPriceNumberOfPeriods");
                    details["numberOfUnits"] = metadataStr.TryGetString("numberOfUnits");
                    details["unit"]          = metadataStr.TryGetString("unit");

                    // this is a double check for Apple side's bug
                    if (!string.IsNullOrEmpty(details["subscriptionNumberOfUnits"]) && string.IsNullOrEmpty(details["subscriptionPeriodUnit"]))
                    {
                        details["subscriptionPeriodUnit"] = "0";
                    }

                    // this is a double check for Apple side's bug
                    if (!string.IsNullOrEmpty(details["numberOfUnits"]) && string.IsNullOrEmpty(details["unit"]))
                    {
                        details["unit"] = "0";
                    }
                }
                else
                {
                    Debug.LogWarning("metadata key not found in product details json");
                }

                if (obj.TryGetValue("storeSpecificId", out var id))
                {
                    var idStr = (string)id;
                    result.Add(idStr, MiniJson.JsonEncode(details));
                }
                else
                {
                    Debug.LogWarning("storeSpecificId key not found in product details json");
                }
            }
            return(result);
        }
        public void SetStorePromotionOrder(List <Product> products)
        {
            // Encode product list as a json doc containing an array of store-specific ids:
            // { "products": [ "ssid1", "ssid2" ] }
            var productIds = new List <string>();

            foreach (var p in products)
            {
                if (p != null && !string.IsNullOrEmpty(p.definition.storeSpecificId))
                {
                    productIds.Add(p.definition.storeSpecificId);
                }
            }
            var dict = new Dictionary <string, object> {
                { "products", productIds }
            };

            m_Native.SetStorePromotionOrder(MiniJson.JsonEncode(dict));
        }
        public static Dictionary <string, string> DeserializeSubscriptionDescriptions(string json)
        {
            var objects = (List <object>)MiniJson.JsonDecode(json);
            var result  = new Dictionary <string, string>();

            foreach (Dictionary <string, object> obj in objects)
            {
                var subscription = new Dictionary <string, string>();
                if (obj.TryGetValue("metadata", out var metadata))
                {
                    var metadataDict = (Dictionary <string, object>)metadata;
                    subscription["introductoryPrice"]                = metadataDict.TryGetString("introductoryPrice");
                    subscription["introductoryPriceLocale"]          = metadataDict.TryGetString("introductoryPriceLocale");
                    subscription["introductoryPriceNumberOfPeriods"] = metadataDict.TryGetString("introductoryPriceNumberOfPeriods");
                    subscription["numberOfUnits"] = metadataDict.TryGetString("numberOfUnits");
                    subscription["unit"]          = metadataDict.TryGetString("unit");

                    // this is a double check for Apple side's bug
                    if (!string.IsNullOrEmpty(subscription["numberOfUnits"]) && string.IsNullOrEmpty(subscription["unit"]))
                    {
                        subscription["unit"] = "0";
                    }
                }
                else
                {
                    Debug.LogWarning("metadata key not found in subscription description json");
                }

                if (obj.TryGetValue("storeSpecificId", out var id))
                {
                    var idStr = (string)id;
                    result.Add(idStr, MiniJson.JsonEncode(subscription));
                }
                else
                {
                    Debug.LogWarning("storeSpecificId key not found in subscription description json");
                }
            }

            return(result);
        }
 public static string SerializeProductDescs(ProductDescription product)
 {
     return(MiniJson.JsonEncode(EncodeProductDesc(product)));
 }
 public static string SerializeProductDef(ProductDefinition product)
 {
     return(MiniJson.JsonEncode(EncodeProductDef(product)));
 }