Ejemplo n.º 1
0
        public void OnPurchaseFailed (Product i, PurchaseFailureReason p) {

            Debug.Log("OnPurchaseFailed : " + p.ToString());
            Debug.Log(JsonConvert.SerializeObject(i));

            ProductMetadata metaData = i.metadata;

            if (this.PurchaseFailedDelegate != null) this.PurchaseFailedDelegate(p.ToString());

        }
        public void Init()
        {
            metadata = new ProductMetadata("£1.23", "Fake title", "Fake desc", "GBP", 1.23m);

            products = new List <ProductDefinition> ();
            products.Add(new ProductDefinition("ammo", "ammo.ios", ProductType.Consumable));
            products.Add(new ProductDefinition("bomb", "bomb.ios", ProductType.Consumable));
            products.Add(new ProductDefinition("sword", "sword.ios", ProductType.NonConsumable));
            products.Add(new ProductDefinition("nanogenes", "nanogenes.ios", ProductType.Subscription));
        }
Ejemplo n.º 3
0
 public void RetrieveProducts(ReadOnlyCollection<ProductDefinition> productDefinitions)
 {
     Debug.Log("RetrieveProducts");
     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));
     }
     m_Biller.OnProductsRetrieved(products);
 }
Ejemplo n.º 4
0
    private static Product BuildProduct()
    {
        PayoutDefinition  payout     = new PayoutDefinition("subtype", 3);
        ProductDefinition definition = new ProductDefinition("product_id", "store_id", ProductType.Consumable, true, payout);
        ProductMetadata   metadata   = new ProductMetadata("15.00", "my_product", "prodcut decription", "USD", decimal.Parse("15.00"));

        var     ctor    = typeof(Product).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(ProductDefinition), typeof(ProductMetadata), typeof(string) }, null);
        Product product = ctor.Invoke(new object[] { definition, metadata, IOSProductReceipt }) as Product;

        return(product);
    }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
    public string GetProduct_localpricestring(string id)
    {
        ProductMetadata productMetadata = this.GetProductMetadata(id);

        if ((productMetadata != null) && !string.IsNullOrEmpty(productMetadata.localizedPriceString))
        {
            return(productMetadata.localizedPriceString);
        }
        if (this.mDataString.ContainsKey(id))
        {
            return(this.mDataString[id]);
        }
        return(id);
    }
        public override void OnEnter()
        {
            #if EM_UIAP
            ProductMetadata data = InAppPurchasing.GetProductLocalizedData(productName.Value);

            if (data != null)
            {
                localizedTitle.Value       = data.localizedTitle;
                localizedDescription.Value = data.localizedDescription;
                isoCurrencyCode.Value      = data.isoCurrencyCode;
                localizedPrice.Value       = (float)data.localizedPrice;
                localizedPriceString.Value = data.localizedPriceString;
            }
            #endif

            Finish();
        }
Ejemplo n.º 8
0
        public ProductMetadata getProductMetadata(string productName)
        {
#if UNITY_EDITOR
            return(null);
#else
            if (IsInitialized())
            {
                ProductMetadata mataData = m_StoreController.products.WithID(productName).metadata;
                Debug.Log(mataData.isoCurrencyCode);
                Debug.Log(mataData.localizedDescription);
                Debug.Log(mataData.localizedPriceString);
                return(mataData);
            }
            else
            {
                Debug.Log("初始化失败");
                return(null);
            }
#endif
        }
Ejemplo n.º 9
0
        public async Task <IHttpActionResult> GetProductMetadata()
        {
            var minQty = await db.Products.MinAsync(p => p.TotalQuantity);

            var maxQty = await db.Products.MaxAsync(p => p.TotalQuantity);

            var minDiscountPer = await db.Products.MinAsync(p => p.DiscountPer);

            var maxDiscountPer = await db.Products.MaxAsync(p => p.DiscountPer);

            var productMetadata = new ProductMetadata()
            {
                QuantityRange    = new IRange <decimal>(minQty, maxQty),
                DiscountPerRange = new IRange <decimal?>(minDiscountPer, maxDiscountPer)
            };
            // Need to send the list as the client is expecting that.
            List <ProductMetadata> result = new List <ProductMetadata>();

            result.Add(productMetadata);
            return(Ok(result));
        }
Ejemplo n.º 10
0
        // The caller is responsible for locking the map access.
        private ProductDescription GetProductDescriptionForSku(string skuId)
        {
            var skuDetails      = _skuDetailsInventory[skuId];
            var productMetadata = new ProductMetadata(
                skuDetails.price,
                skuDetails.title,
                skuDetails.description,
                skuDetails.price_currency_code,
                decimal.Divide(new decimal(skuDetails.price_amount_micros), Micros));

            string receipt       = null;
            string transactionId = null;

            if (_purchaseInventory.ContainsKey(skuId))
            {
                receipt       = _purchaseInventory[skuId].JsonReceipt;
                transactionId = _purchaseInventory[skuId].TransactionId;
            }

            return(new ProductDescription(skuId, productMetadata, receipt, transactionId));
        }
Ejemplo n.º 11
0
        void ProductsLoaded()
        {
            var descList = new List <ProductDescription>(this.productsList.Count);

            foreach (var product in this.productsList)
            {
                string priceString;
                float  price = product.MicrosPrice * 0.000001f;

                if (price < 100)
                {
                    priceString = price.ToString("0.00");
                }
                else
                {
                    priceString = ((int)(price + 0.5f)).ToString();
                }

                var prodMeta = new ProductMetadata(priceString, product.ProductName, product.ProductDesc, product.Currency, (decimal)price);
                ProductDescription prodDesc;

                if (this.purchasedData.TryGetValue(product.ProductId, out var purchaseData))
                {
                    // var receipt = CreateReceipt(purchaseData);
                    this.inAppPurchaseData.TryGetValue(product.ProductId, out var purchaseOriginalJson);
                    this.inAppSignature.TryGetValue(product.ProductId, out var purchaseSignature);
                    var receipt = EncodeReceipt(purchaseOriginalJson, purchaseSignature, ProductToJson(product));

                    prodDesc = new ProductDescription(product.ProductId, prodMeta, receipt, purchaseData.OrderID);
                }
                else
                {
                    prodDesc = new ProductDescription(product.ProductId, prodMeta);
                }

                descList.Add(prodDesc);
            }

            this.storeEvents.OnProductsRetrieved(descList);
        }
Ejemplo n.º 12
0
        private void ProcessStoreItems()
        {
            Debug.Assert(
                _pendingProducts != null,
                "Trying to initialize without product definitions");

            try
            {
                // Use the item data to populate the price information for the produts.
                var products = _pendingProducts
                               .Where(product => _storeItems.ContainsKey(product.id))
                               .Select(product =>
                {
                    var storeItem = _storeItems[product.id];
                    var metatdata = new ProductMetadata(
                        $"{storeItem.Price} Kreds",
                        storeItem.Name,
                        storeItem.Description,
                        "kreds",
                        storeItem.Price);

                    // If the product is present in the user's item list, provide
                    // the receipt and transaction ID so that the game code can
                    // restore the purchase.
                    if (_userItems.TryGetValue(product.id, out var ownedItems))
                    {
                        var receipt = new Receipt()
                        {
                            AuthToken = KongregateWeb.GameAuthToken,
                            Items     = ownedItems.Select(item => item.Id).ToArray(),
                        };

                        // NOTE: We make up a transaction ID by joining the various item
                        // IDs since Kongregate doesn't directly provide a transaction ID.
                        // The item ID itself will be unique for the purchase so this
                        // should be fine when there's only a single item in the user's
                        // inventory. It might be weird if there are ever multiple items,
                        // though.
                        var transactionId = string.Join(",", ownedItems.Select(item => item.Id));

                        return(new ProductDescription(
                                   product.id,
                                   metatdata,
                                   JsonUtility.ToJson(receipt),
                                   transactionId));
                    }
                    else
                    {
                        return(new ProductDescription(product.id, metatdata));
                    }
                })
                               .ToList();
                _callback.OnProductsRetrieved(products);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
                _callback.OnSetupFailed(InitializationFailureReason.NoProductsAvailable);
            }
            finally
            {
                // Clear variables used to track the intialization process.
                _pendingProducts = null;
                _storeItems      = null;
                _userItems       = null;
            }
        }
Ejemplo n.º 13
0
        public void ProductMetadata_AutoBlacklist_ShouldBeTrue()
        {
            var metadata = new ProductMetadata();

            metadata.AutoBlacklist.Should().BeTrue();
        }
Ejemplo n.º 14
0
        public void ProductMetadata_RequiresParent_ShouldBeTrue()
        {
            var metadata = new ProductMetadata();

            metadata.RequiresParent.Should().BeTrue();
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Parametrized Constructor.
 /// With the transaction data and type.
 /// </summary>
 /// <param name="id"> The id of the product. </param>
 /// <param name="metadata"> The metadata of the product. </param>
 /// <param name="receipt"> The receipt of the purchase of the product. </param>
 /// <param name="transactionId"> The transaction id of the purchase of the product. </param>
 /// <param name="type"> The type of the product. </param>
 public ProductDescription(string id, ProductMetadata metadata,
                           string receipt, string transactionId, ProductType type)
     : this(id, metadata, receipt, transactionId)
 {
     this.type = type;
 }
        public static ProductAndProductMetadata ReadAsinLookupResponse(IEnumerable <XmlNode> nodes)
        {
            Product         product         = new Product();
            ProductMetadata productMetadata = new ProductMetadata();

            if (nodes == null)
            {
                return(null);
            }

            List <XmlNode> itemElements = nodes.ToList();

            if (!itemElements.Any())
            {
                return(null);
            }

            XmlNode firstItemElement = itemElements.First();

            XmlNode asinElement = firstItemElement.GetChildXmlNode("ASIN");

            if (asinElement != null)
            {
                XmlNode asinElementInnerXml = asinElement.ChildNodes.Cast <XmlNode>().First();
                if (asinElementInnerXml != null)
                {
                    product.ASIN = asinElementInnerXml.InnerText;
                }
            }

            XmlNode largeImageElement = firstItemElement.GetChildXmlNode("LargeImage");

            if (largeImageElement != null)
            {
                XmlNode largeImageElementInnerXml = largeImageElement.ChildNodes.Cast <XmlNode>().First();
                if (largeImageElementInnerXml != null)
                {
                    productMetadata.ImageUrl = largeImageElementInnerXml.InnerText;
                }
            }

            string salesRank;

            firstItemElement.GetValueFromChildNode("SalesRank", out salesRank);
            productMetadata.SalesRank = salesRank;

            XmlNode itemAttributeNode = firstItemElement.GetChildXmlNode("ItemAttributes");

            if (itemAttributeNode != null)
            {
                string productName;
                itemAttributeNode.GetValueFromChildNode("Title", out productName);
                product.Name = productName;

                string productGroup;
                itemAttributeNode.GetValueFromChildNode("ProductGroup", out productGroup);
                productMetadata.ProductGroup = productGroup;

                string manufacturerName;
                itemAttributeNode.GetValueFromChildNode("Manufacturer", out manufacturerName);
                productMetadata.Manufacturer = manufacturerName;

                // Use name 'ItemNumber' instead of model.
                string model;
                itemAttributeNode.GetValueFromChildNode("Model", out model);
                product.ItemNumber = model;

                // Use UPC if one is found, rather than the EAN.
                string ean;
                itemAttributeNode.GetValueFromChildNode("EAN", out ean);
                product.UPC = ean;

                string upc;
                itemAttributeNode.GetValueFromChildNode("UPC", out upc);
                product.UPC = upc;

                XmlNode packageDimensionsNode = itemAttributeNode.GetChildXmlNode("PackageDimensions");
                if (packageDimensionsNode != null)
                {
                    decimal height;
                    if (packageDimensionsNode.GetValueFromChildNode("Height", out height, DimensionUtility.GetInchesConverter()))
                    {
                        product.Height = height;
                    }

                    decimal width;
                    if (packageDimensionsNode.GetValueFromChildNode("Width", out width, DimensionUtility.GetInchesConverter()))
                    {
                        product.Width = width;
                    }

                    decimal length;
                    if (packageDimensionsNode.GetValueFromChildNode("Length", out length, DimensionUtility.GetInchesConverter()))
                    {
                        product.Length = length;
                    }

                    decimal weight;
                    if (packageDimensionsNode.GetValueFromChildNode("Weight", out weight, DimensionUtility.GetPoundsConverter()))
                    {
                        product.Weight = weight;
                    }
                }

                XmlNode listPriceNode = itemAttributeNode.GetChildXmlNode("ListPrice");
                if (listPriceNode != null)
                {
                    string listPrice;
                    listPriceNode.GetValueFromChildNode("FormattedPrice", out listPrice);
                    productMetadata.ListPrice = listPrice;
                }
            }

            return(new ProductAndProductMetadata(product, productMetadata));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Products must have a definition as minimum.
 ///
 /// Further metadata may be populated following retrieval from the
 /// store system.
 /// </summary>
 internal Product(ProductDefinition definition, ProductMetadata metadata, string receipt)
 {
     this.definition = definition;
     this.metadata   = metadata;
     this.receipt    = receipt;
 }
Ejemplo n.º 18
0
 internal Product(ProductDefinition definition, ProductMetadata metadata) : this(definition, metadata, null)
 {
 }
Ejemplo n.º 19
0
        public void ProductMetadata_ChildrenListType_ShouldBeWhiteList()
        {
            var metadata = new ProductMetadata();

            metadata.ChildrenListType.Should().Be(ChildrenListType.WhiteList);
        }
        public LookupProductResponse(Product product, ProductSearchMethod productSearchMethod, ProductMetadata productMetadata = null)
        {
            m_product = product;

            m_productSearchMethod = productSearchMethod;

            m_productMetadata = productMetadata;
        }
Ejemplo n.º 21
0
        public void ProductMetadata_ChildrenList_ShouldBeEmpty()
        {
            var metadata = new ProductMetadata();

            metadata.ChildrenList.Should().BeEquivalentTo(new List <Type>());
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Parametrized Constructor.
 /// Without transaction data.
 /// </summary>
 /// <param name="id"> The id of the product. </param>
 /// <param name="metadata"> The metadata of the product. </param>
 public ProductDescription(string id, ProductMetadata metadata) : this(id, metadata, null, null)
 {
 }
Ejemplo n.º 23
0
        public ProductAndProductMetadata(Product product, ProductMetadata productMetadata)
        {
            m_product = product;

            m_productMetadata = productMetadata;
        }