示例#1
0
        public void RestoreTransactions(Action <bool> callback)
        {
            if (!IsGooglePlayInAppBillingServiceAvailable())
            {
                callback.Invoke(false);
                return;
            }

            var inAppPurchasesResult = _billingClient.Call <AndroidJavaObject>(Constants.QueryPurchasesMethod,
                                                                               SkuType.InApp.ToString());
            var subsPurchasesResult = _billingClient.Call <AndroidJavaObject>(Constants.QueryPurchasesMethod,
                                                                              SkuType.Subs.ToString());

            if (_jniUtils.GetResponseCodeFromQueryPurchasesResult(inAppPurchasesResult) !=
                BillingResponseCode.Ok ||
                _jniUtils.GetResponseCodeFromQueryPurchasesResult(subsPurchasesResult) != BillingResponseCode.Ok)
            {
                callback.Invoke(false);
                return;
            }

            var allPurchases = _jniUtils.ParseQueryPurchasesResult(inAppPurchasesResult)
                               .Concat(_jniUtils.ParseQueryPurchasesResult(subsPurchasesResult))
                               .ToList();

            _inventory.UpdatePurchaseInventory(allPurchases);
            _billingUtil.RunOnMainThread(() =>
                                         _callback.OnProductsRetrieved(_inventory.CreateProductDescriptionList()));
            _billingUtil.RunOnMainThread(() => callback.Invoke(true));
        }
示例#2
0
        //getting the items declared in PlayFab's catalog and converting them to Unity IAP format
        private void OnCatalogRetrieved(GetCatalogItemsResult result)
        {
            for (int i = 0; i < result.Catalog.Count; i++)
            {
                CatalogItem catalogItem = result.Catalog[i];
                string      itemId      = IAPManager.GetIAPIdentifier(catalogItem.ItemId);
                if (!IAPManager.GetIAPKeys().Contains(itemId) || products.ContainsKey(itemId))
                {
                    continue;
                }

                ApplyCatalogItem(itemId, catalogItem);

                decimal price       = 0;
                string  priceString = "";
                string  currency    = catalogItem.VirtualCurrencyPrices.Keys.First();
                if (currency == "RM")
                {
                    price       = (decimal)catalogItem.VirtualCurrencyPrices[currency] / 100m;
                    priceString = price.ToString("C");
                }
                else
                {
                    price       = catalogItem.VirtualCurrencyPrices[currency];
                    priceString = price.ToString();
                }

                products.Add(itemId, new ProductDescription(itemId, new ProductMetadata(priceString, catalogItem.DisplayName, catalogItem.Description, "USD", price)));
            }

            if (callback != null)
            {
                callback.OnProductsRetrieved(products.Values.ToList());
            }
        }
示例#3
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());
        }
示例#4
0
        public virtual void OnProductsRetrieved(string json)
        {
            // NB: AppleStoreImpl overrides this completely and does not call the base.
            unity.OnProductsRetrieved(JSONSerializer.DeserializeProductDescriptions(json));

            Promo.ProvideProductsToAds(this, unity);
        }
示例#5
0
        public virtual void OnProductsRetrieved(string json)
        {
            // NB: AppleStoreImpl overrides this completely and does not call the base.
            unity.OnProductsRetrieved(JSONSerializer.DeserializeProductDescriptions(json));

            // The shouldLogPromoInitialization flag determines if we should log a message from ProvideProductsToAds
            // We would like to log this message only once when we successfully retrieved products, so we reset
            // shouldLogPromoInitialization to false once we call ProvideProductsToAds.
            Promo.ProvideProductsToAds(this, unity, shouldLogPromoInitialization);
            shouldLogPromoInitialization = false;
        }
示例#6
0
        public void RetrieveProducts(ReadOnlyCollection <ProductDefinition> productDefinitions)
        {
            var products = new List <ProductDescription>();

            foreach (var product in productDefinitions)
            {
                var metadata = new ProductMetadata("$123.45", "Fake title for " + product.id, "Fake description", "USD", 123.45m);
                products.Add(new ProductDescription(product.storeSpecificId, metadata));
            }
            _biller.OnProductsRetrieved(products);
        }
示例#7
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);
            }
        }
示例#8
0
 public void RetrieveProducts(ReadOnlyCollection <ProductDefinition> products, bool wantPurchases = true)
 {
     if (m_StoreCallback != null)
     {
         m_GooglePlayStoreService.RetrieveProducts(products, retrievedProducts =>
         {
             if (wantPurchases)
             {
                 m_GoogleFetchPurchases.FetchPurchases(purchaseProducts =>
                 {
                     var mergedProducts = MakePurchasesIntoProducts(retrievedProducts, purchaseProducts);
                     m_StoreCallback.OnProductsRetrieved(mergedProducts);
                 });
             }
             else
             {
                 m_StoreCallback.OnProductsRetrieved(retrievedProducts);
             }
         }, () =>
         {
             m_GooglePlayConfigurationInternal.NotifyInitializationConnectionFailed();
         });
     }
 }
示例#9
0
 public void RetrieveProducts(ReadOnlyCollection <ProductDefinition> products)
 {
     if (m_StoreCallback != null)
     {
         m_GooglePlayStoreService.RetrieveProducts(products, retrievedProducts =>
         {
             m_GoogleFetchPurchases.FetchPurchases(purchaseProducts =>
             {
                 var mergedProducts = MakePurchasesIntoProducts(retrievedProducts, purchaseProducts);
                 m_StoreCallback.OnProductsRetrieved(mergedProducts);
             });
         }, () =>
         {
             m_StoreCallback.OnSetupFailed(InitializationFailureReason.NoProductsAvailable);
         });
     }
 }
示例#10
0
 public void OnProductListReceived(WinProductDescription[] winProducts)
 {
     util.RunOnMainThread(() =>
     {
         // Convert windows products to Unity Purchasing products.
         var products = from product in winProducts
                        let metadata = new ProductMetadata(
             product.price, product.title, product.description,
             product.ISOCurrencyCode, product.priceDecimal)
                                       select new ProductDescription(
             product.platformSpecificID,
             metadata,
             product.receipt,
             product.transactionID);
         // need to determine if that list includes any purchases or just products
         // and then use that to set m_CanReceivePurchases
         callback.OnProductsRetrieved(products.ToList());
     });
 }
示例#11
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());
        }
示例#12
0
        private void OnProductsRetrieved(BillingResult result)
        {
            if (!result.IsSuccess)
            {
                OnSetupFailed(result.Response + ", " + result.Message);
                return;
            }

            AndroidInventory              inventory = AndroidInAppPurchaseManager.Client.Inventory;
            List <GoogleProductTemplate>  list      = inventory.Products;
            List <GooglePurchaseTemplate> purchases = inventory.Purchases;

            string globalId = null;
            string storeId  = null;

            for (int i = 0; i < list.Count; i++)
            {
                storeId  = list[i].SKU;
                globalId = IAPManager.GetIAPIdentifier(storeId);

                if (!products.ContainsKey(globalId))
                {
                    products.Add(globalId, new ProductDescription(storeId, new ProductMetadata(list[i].LocalizedPrice,
                                                                                               list[i].Title, list[i].Description,
                                                                                               list[i].PriceCurrencyCode, (decimal)list[i].Price)));
                }

                //check for non-consumed consumables
                if (storeId in purchases)
                {
                    IAPObject obj = IAPManager.GetIAPObject(IAPManager.GetIAPIdentifier(purchases[i].SKU));
                    if (obj != null && obj.type == ProductType.Consumable)
                    {
                        AndroidInAppPurchaseManager.Client.Consume(purchases[i].SKU);
                        continue;
                    }
                }

                bool storeResult = inventory.IsProductPurchased(storeId);
                if (storeResult == true)
                {
                    products[globalId] = new ProductDescription(storeId, products[globalId].metadata, inventory.GetPurchaseDetails(storeId).Token, inventory.GetPurchaseDetails(storeId).OrderId);
                }

                #if !UNITY_EDITOR
                //auto restore products in case database does not match
                if (storeResult != DBManager.isPurchased(globalId))
                {
                    if (storeResult)
                    {
                        DBManager.SetToPurchased(globalId);
                    }
                    else
                    {
                        DBManager.RemovePurchased(globalId);
                    }
                }
                #endif
            }

            callback.OnProductsRetrieved(products.Values.ToList());
        }
 public void OnProductsRetrieved(List <ProductDescription> products)
 {
     m_Util.RunOnMainThread(() => m_ForwardTo.OnProductsRetrieved(products));
 }
示例#14
0
        public override async void RetrieveProducts(ReadOnlyCollection <ProductDefinition> definitions)
        {
            //var serverProductsResponse = await _server.LoadProductsAsync(_localizationService.Locale);
            //if (serverProductsResponse?.Status != ServerResponseStatus.Success || serverProductsResponse.Data == null)
            // {
            //     Debug.LogError("Unable to load server products definitions");
            //     _callback.OnSetupFailed(InitializationFailureReason.NoProductsAvailable);
            //     return;
            // }

            // var transactionsResponse = await _server.LoadTransactionsAsync();
            // if (transactionsResponse?.Status != ServerResponseStatus.Success || transactionsResponse.Data == null)
            // {
            //     Debug.LogError("Unable to load server transactions");
            //     _callback.OnSetupFailed(InitializationFailureReason.NoProductsAvailable);
            //     return;
            // }

            // var serverProducts = serverProductsResponse.Data;
            //var transactions = transactionsResponse.Data;

            foreach (var definition in definitions)
            {
                // var serverProduct = serverProducts.FirstOrDefault(product => product.ID.ToString() == definition.storeSpecificId);
                // if (serverProduct == null)
                // {
                //     Debug.LogWarningFormat("Unable to find server definition for product {0}:{1}", definition.id, definition.storeSpecificId);
                //     continue;
                // }

                // var transaction = transactions.FirstOrDefault(trans =>
                //     trans.ProductId.ToString() == definition.storeSpecificId && !trans.Completed);

                // var metadata = new ProductMetadata(
                //     string.Format("{0} {1}", serverProduct.LocalizedPrice, serverProduct.CurrencyCode),
                //     serverProduct.LocalizedTitle,
                //     serverProduct.LocalizedDescription,
                //     serverProduct.CurrencyCode,
                //     serverProduct.LocalizedPrice
                // );

                ProductDescription productDescription;

                // if (transaction != null)
                // {
                //     productDescription = new ProductDescription(
                //         definition.storeSpecificId,
                //         metadata,
                //         "{}",
                //         transaction.TransactionId
                //     );
                // }
                // else
                // {
                //     productDescription = new ProductDescription(
                //         definition.storeSpecificId,
                //         metadata
                //     );
                // }

                //_products.Add(productDescription);
            }

            _callback.OnProductsRetrieved(_products);
        }