/// <summary>
        /// Initialises the response with the given json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the JSON data.</param>
        public ValidateAmazonIapResponse(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("ReceiptVerificationService"), "Json is missing required field 'ReceiptVerificationService'");

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

                // Receipt Verification Service
                else if (entry.Key == "ReceiptVerificationService")
                {
                    ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type.");
                    ReceiptVerificationService = new ReceiptVerificationService((IDictionary <string, object>)entry.Value);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Initialises the response with the given json dictionary.
        /// </summary>
        ///
        /// <param name="jsonDictionary">The dictionary containing the JSON data.</param>
        public RedeemAmazonIapResponse(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("ReceiptVerificationService"), "Json is missing required field 'ReceiptVerificationService'");

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

                // Receipt Verification Service
                else if (entry.Key == "ReceiptVerificationService")
                {
                    ReleaseAssert.IsTrue(entry.Value is IDictionary <string, object>, "Invalid serialised type.");
                    ReceiptVerificationService = new ReceiptVerificationService((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
                }
            }
        }