/// <summary>
 /// Gets the <cref="SkuDetails"/> associated with the specified Google Play Store SKU id from inventory.
 /// <returns>true if the inventory contains the requested SKU; otherwise, false.</returns>
 /// </summary>
 public bool GetSkuDetails(string sku, out SkuDetails skuDetails)
 {
     lock (_inventoryLock)
     {
         return(_skuDetailsInventory.TryGetValue(sku, out skuDetails));
     }
 }
Example #2
0
        /// <summary>
        /// Parses the sku details results returned by the Google Play Billing Library.
        /// </summary>
        /// <returns>An IEnumerable of <cref="SkuDetails"/>. The IEnumerable could be empty.</returns>
        public IEnumerable <SkuDetails> ParseSkuDetailsResult(AndroidJavaObject billingResult,
                                                              AndroidJavaObject skuDetailsList)
        {
            var responseCode = GetResponseCodeFromBillingResult(billingResult);

            if (responseCode != BillingResponseCode.Ok)
            {
                // TODO: retry getSkuDetails call.
                _util.LogErrorFormat(
                    "Failed to retrieve products information! Error code {0}, debug message: {1}.",
                    responseCode, GetDebugMessageFromBillingResult(billingResult));
                return(Enumerable.Empty <SkuDetails>());
            }

            var parsedSkuDetailsList = new List <SkuDetails>();
            var size = skuDetailsList.Call <int>("size");

            for (var i = 0; i < size; i++)
            {
                var javaSkuDetails = skuDetailsList.Call <AndroidJavaObject>("get", i);
                // Google Play Store returns non-null, non-empty originalJson.
                var        originalJson = javaSkuDetails.Call <string>(Constants.SkuDetailsGetOriginalJson);
                SkuDetails skuDetails;
                if (SkuDetails.FromJson(originalJson, out skuDetails))
                {
                    parsedSkuDetailsList.Add(skuDetails);
                }
                else
                {
                    _util.LogWarningFormat("Failed to parse skuDetails {0} ", originalJson);
                }
            }

            return(parsedSkuDetailsList);
        }
 /// <summary>
 /// Creates a SkuDetails object from its JSON representation.
 /// </summary>
 public static bool FromJson(string jsonSkuDetails, out SkuDetails skuDetails)
 {
     try
     {
         skuDetails = JsonUtility.FromJson <SkuDetails>(jsonSkuDetails);
         skuDetails.JsonSkuDetails = jsonSkuDetails;
         return(true);
     }
     catch (Exception)
     {
         // Error is logged at the caller side.
         skuDetails = null;
         return(false);
     }
 }