예제 #1
0
        //returning products retrieved by the billing system back to Unity IAP
        private void OnProductsRetrieved(BillingProduct[] list, string error)
        {
            if (!string.IsNullOrEmpty(error))
            {
                OnSetupFailed(error);
                return;
            }

            string itemId = null;

            for (int i = 0; i < list.Length; i++)
            {
                itemId = list[i].ProductIdentifier;

                if (!products.ContainsKey(itemId))
                {
                    products.Add(itemId, new ProductDescription(itemId, new ProductMetadata(list[i].LocalizedPrice,
                                                                                            list[i].Name, list[i].Description,
                                                                                            list[i].CurrencyCode, (decimal)list[i].Price)));
                }

                if (PlayerPrefs.HasKey(itemId))
                {
                    products[itemId] = new ProductDescription(itemId, products[itemId].metadata, DBManager.GetReceipt(itemId), "");
                }

                //auto restore products in case database does not match
                #if UNITY_ANDROID
                string globalId = IAPManager.GetIAPIdentifier(itemId);
                if (NPBinding.Billing.IsProductPurchased(list[i]) && DBManager.GetPurchase(globalId) == 0)
                {
                    DBManager.SetPurchase(globalId);
                }
                #endif
            }

            callback.OnProductsRetrieved(products.Values.ToList());
        }
예제 #2
0
        private void OnProductsRetrieved(Result result)
        {
            this.products = new Dictionary <string, ProductDescription>();

            if (!result.IsSucceeded)
            {
                OnSetupFailed(result.Error.Code + ", " + result.Error.Message);
                return;
            }

            List <IOSProductTemplate> list = IOSInAppPurchaseManager.Instance.Products;

            string globalId = null;
            string storeId  = null;

            for (int i = 0; i < list.Count; i++)
            {
                storeId  = list[i].Id;
                globalId = IAPManager.GetIAPIdentifier(storeId);
                if (!products.ContainsKey(globalId))
                {
                    products.Add(globalId, new ProductDescription(storeId, new ProductMetadata(list[i].LocalizedPrice,
                                                                                               list[i].DisplayName, list[i].Description,
                                                                                               list[i].CurrencyCode, (decimal)list[i].Price)));
                }

                if (PlayerPrefs.HasKey(globalId))
                {
                    products[globalId] = new ProductDescription(storeId, products[globalId].metadata, DBManager.GetReceipt(globalId), "");
                }
            }

            callback.OnProductsRetrieved(products.Values.ToList());
        }