/// <summary> /// Initialises the response with the given json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the JSON data.</param> public ValidateAppleIapResponse(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Valid"), "Json is missing required field 'Valid'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Status"), "Json is missing required field 'Status'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("AppStore"), "Json is missing required field 'AppStore'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Valid if (entry.Key == "Valid") { ReleaseAssert.IsTrue(entry.Value is bool, "Invalid serialised type."); Valid = (bool)entry.Value; } // Status else if (entry.Key == "Status") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Status = (string)entry.Value; } // App Store else if (entry.Key == "AppStore") { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); AppStore = new AppStore((IDictionary <string, object>)entry.Value); } } }
/// <summary> /// Initialises the response with the given json dictionary. /// </summary> /// /// <param name="jsonDictionary">The dictionary containing the JSON data.</param> public RedeemAppleIapResponse(IDictionary <string, object> jsonDictionary) { ReleaseAssert.IsNotNull(jsonDictionary, "JSON dictionary cannot be null."); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Redeemed"), "Json is missing required field 'Redeemed'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("Status"), "Json is missing required field 'Status'"); ReleaseAssert.IsTrue(jsonDictionary.ContainsKey("AppStore"), "Json is missing required field 'AppStore'"); foreach (KeyValuePair <string, object> entry in jsonDictionary) { // Redeemed if (entry.Key == "Redeemed") { ReleaseAssert.IsTrue(entry.Value is bool, "Invalid serialised type."); Redeemed = (bool)entry.Value; } // Status else if (entry.Key == "Status") { ReleaseAssert.IsTrue(entry.Value is string, "Invalid serialised type."); Status = (string)entry.Value; } // App Store else if (entry.Key == "AppStore") { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); AppStore = new AppStore((IDictionary <string, object>)entry.Value); } // Rewards else if (entry.Key == "Rewards") { if (entry.Value != null) { ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type."); Rewards = new PurchaseExchange((IDictionary <string, object>)entry.Value); } } // An error has occurred. else { #if DEBUG throw new ArgumentException("Input Json contains an invalid field."); #endif } } }