Ejemplo n.º 1
0
        void Start()
        {
            receiptViewer.SetActive(false);
            curtain.SetActive(!EM_Settings.IsIAPModuleEnable);

            if (logProductLocalizedData)
            {
                #if EM_UIAP
                foreach (IAPProduct p in EM_Settings.InAppPurchasing.Products)
                {
                    UnityEngine.Purchasing.ProductMetadata data = InAppPurchasing.GetProductLocalizedData(p.Name);

                    if (data != null)
                    {
                        Debug.Log("Product Localized Title: " + data.localizedTitle);
                        Debug.Log("Localized Price: " + data.localizedPriceString);
                        Debug.Log("Product Localized Description: " + data.localizedDescription);
                    }
                    else
                    {
                        Debug.Log("Localized data is null");
                    }
                }
                #endif
            }

            StartCoroutine(CheckOwnedProducts());
        }
Ejemplo n.º 2
0
 public static GoogleProductMetadata GetGoogleProductMetadata(this ProductMetadata productMetadata)
 {
     try
     {
         return((GoogleProductMetadata)productMetadata);
     }
     catch (Exception)
     {
         return(null);
     }
 }
        private static Dictionary <string, object> EncodeProductMeta(ProductMetadata product)
        {
            var prod = new Dictionary <string, object>
            {
                { "localizedPriceString", product.localizedPriceString },
                { "localizedTitle", product.localizedTitle },
                { "localizedDescription", product.localizedDescription },
                { "isoCurrencyCode", product.isoCurrencyCode },
                { "localizedPrice", Convert.ToDouble(product.localizedPrice) }
            };


            return(prod);
        }
Ejemplo n.º 4
0
        // This is now being used by the INativeStore implementation
        public void StoreRetrieveProducts(ReadOnlyCollection <ProductDefinition> productDefinitions)
        {
            var products = new List <ProductDescription>();

            foreach (var product in productDefinitions)
            {
                if (unavailableProductId != product.id)
                {
                    var            metadata = new ProductMetadata("$0.01", "Fake title for " + product.id, "Fake description", "USD", 0.01m);
                    ProductCatalog catalog  = ProductCatalog.LoadDefaultCatalog();
                    if (catalog != null)
                    {
                        foreach (var item in catalog.allProducts)
                        {
                            if (item.id == product.id)
                            {
                                metadata = new ProductMetadata(item.googlePrice.value.ToString(), item.defaultDescription.Title, item.defaultDescription.Description, "USD", item.googlePrice.value);
                            }
                        }
                    }
                    products.Add(new ProductDescription(product.storeSpecificId, metadata));
                }
            }

            Action <bool, InitializationFailureReason> handleAllowInitializeOrRetrieveProducts =
                (bool allow, InitializationFailureReason failureReason) =>
            {
                if (allow)
                {
                    m_Biller.OnProductsRetrieved(products);

                    // Since iOS is already rigged to work this way might as well just use it...
                    // *** if we want to use this change without Promo then we'll need to use reflection here
                    Promo.ProvideProductsToAds(this, m_Biller);
                }
                else
                {
                    m_Biller.OnSetupFailed(failureReason);
                }
            };

            // To mimic typical store behavior, only display RetrieveProducts dialog for developers
            if (!(UIMode == FakeStoreUIMode.DeveloperUser &&
                  StartUI <InitializationFailureReason> (productDefinitions, DialogType.RetrieveProducts, handleAllowInitializeOrRetrieveProducts)))
            {
                // Default non-UI FakeStore RetrieveProducts behavior is to succeed
                handleAllowInitializeOrRetrieveProducts(true, InitializationFailureReason.AppNotKnown);
            }
        }
Ejemplo n.º 5
0
        private void OnInventoryQueried(bool success, object payload)
        {
            bool   actualSuccess = success;
            string parsedPayload;
            Type   inventoryType = InventoryInterface.GetClassType();

            if (success)
            {
                if (inventoryType != null)
                {
                    object inventory = payload;
                    if (inventory != null && inventory.GetType() == inventoryType)
                    {
                        HashSet <ProductDescription> fetchedProducts = new HashSet <ProductDescription>();

                        var getProductList = InventoryInterface.GetProductListMethod();
                        var products       = (IEnumerable)getProductList.Invoke(inventory, null);
                        var productList    = products.Cast <object>().ToList();

                        foreach (var productInfo in productList)
                        {
                            var priceProp    = ProductInfoInterface.GetPriceProp();
                            var titleProp    = ProductInfoInterface.GetTitleProp();
                            var descProp     = ProductInfoInterface.GetDescriptionProp();
                            var currencyProp = ProductInfoInterface.GetCurrencyProp();
                            var microsProp   = ProductInfoInterface.GetPriceAmountMicrosProp();

                            ProductMetadata metadata = new ProductMetadata(
                                (string)priceProp.GetValue(productInfo, null),
                                (string)titleProp.GetValue(productInfo, null),
                                (string)descProp.GetValue(productInfo, null),
                                (string)currencyProp.GetValue(productInfo, null),
                                Convert.ToDecimal((long)microsProp.GetValue(productInfo, null)) / 1000000);


                            var idProp    = ProductInfoInterface.GetProductIdProp();
                            var productId = (string)idProp.GetValue(productInfo, null);

                            ProductDescription desc = new ProductDescription(productId, metadata);

                            var hasPurchase = InventoryInterface.HasPurchaseMethod();
                            if ((bool)hasPurchase.Invoke(inventory, new object[] { productId }))
                            {
                                var    getPurchaseInfo = InventoryInterface.GetPurchaseInfoMethod();
                                object purchase        = getPurchaseInfo.Invoke(inventory, new object[] { productId });

                                var    dic             = StringPropertyToDictionary(purchase);
                                string transactionId   = dic["GameOrderId"];
                                var    storeSpecificId = dic["ProductId"];

                                if (!string.IsNullOrEmpty(transactionId))
                                {
                                    dic["transactionId"] = transactionId;
                                }

                                if (!string.IsNullOrEmpty(storeSpecificId))
                                {
                                    dic["storeSpecificId"] = storeSpecificId;
                                }

                                desc = new ProductDescription(productId, metadata, dic.toJson(), transactionId);
                            }

                            fetchedProducts.Add(desc);
                        }

                        parsedPayload = JSONSerializer.SerializeProductDescs(fetchedProducts);
                    }
                    else
                    {
                        actualSuccess = false;
                        parsedPayload = "{ \"error\" : \"Cannot load inventory from UDP. Please make sure your UDP package is installed and up-to-date\" }";
                    }
                }
                else
                {
                    actualSuccess = false;
                    parsedPayload = "{ \"error\" : \"Cannot parse inventory type for UDP. Please make sure your UDP package is installed and up-to-date\" }";
                }
            }
            else
            {
                parsedPayload = (string)payload;
            }

            m_RetrieveProductsCallbackCache(actualSuccess, parsedPayload);
            m_RetrieveProductsCallbackCache = null;
        }