Example #1
0
 void PurchaseSuccessCallback(SKPaymentTransaction transaction, InAppProduct product)
 {
     if (product.ProductIdentifier == Constants.PURCHASE_ID[(int)Constants.PURCHASE_TYPE.VIEW])
     {
         ViewDropDetail();
     }
 }
Example #2
0
        /// <Docs>Table view requesting the cell.</Docs>
        /// <summary>
        /// Gets the cell.
        /// </summary>
        /// <returns>The cell.</returns>
        /// <param name="tableView">Table view.</param>
        /// <param name="indexPath">Index path.</param>
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            // Get table cell to hold data
            var cell = tableView.DequeueReusableCell(StoreTableCell.Key) as StoreTableCell;

            // Take action based on the section
            switch (indexPath.Section)
            {
            case 0:
                // Get product for given cell
                InAppProduct product = products [indexPath.Row];

                // Populate cell with product information
                cell.DisplayProduct(_controller.PurchaseManager, product);
                break;

            case 1:
                // Display the link to restore purchases
                cell.DisplayRestore(_controller.PurchaseManager);
                break;

            case 2:
                // Display the currently downloading item
                cell.DisplayDownload(_controller.PurchaseManager);
                break;
            }

            return(cell);
        }
Example #3
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------
    // Private methods
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    static float GetOneGoldCoinPrice(InAppProduct product, FundSettingsManager fundSettingsManager)
    {
        float productPrice   = GetProductPrice(product);
        int   goldCoinsCount = GetGoldCoinsCount(product, fundSettingsManager);

        return(productPrice / goldCoinsCount);
    }
Example #4
0
        /// <summary>
        /// Sets the screen up (UI components, multimedia content, etc.)
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            // TODO: Replace these comments with your own poetry, and enjoy!
            StoreConfiguration conf = new StoreConfiguration();
            conf.Android.Enabled = true;
            conf.IOS.Enabled = true;
            //conf.WindowsPhone.Enabled = true;

            List<InAppProduct> productList = new List<InAppProduct>();

            myProduct = new InAppProduct("com.syderis.cellsdk.myProduct", InAppProductType.NonConsumable);
            productList.Add(myProduct);

            conf.ProductList = productList;

            InAppStore.OnUpdateTransaction += HandleInAppStoreOnUpdateTransaction;

            InAppStore.Initialize(conf);

            Button buy = new Button("Buy!");
            buy.Released += new Component.ComponentEventHandler(buy_Released);
            AddComponent(buy, 100, 100);
        }
Example #5
0
        public async void QueryInventory()
        {
            var products = await this._serviceConnection.BillingHandler.QueryInventoryAsync(
                new List <string>()
            {
                this.PracticeModeProductId
            },
                ItemType.Product);

            // Update inventory
            foreach (var product in products)
            {
                var newProduct = new InAppProduct();
                newProduct.ProductId         = product.ProductId;
                newProduct.Type              = ItemType.Product;
                newProduct.Price             = product.Price;
                newProduct.Title             = product.Title;
                newProduct.Description       = product.Description;
                newProduct.PriceCurrencyCode = product.Price_Currency_Code;

                App.ViewModel.Products.Add(newProduct);
            }

            if (this.OnQueryInventory != null)
            {
                this.OnQueryInventory();
            }
        }
Example #6
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // Return the product sale relative to the base product.
    // return number < 0 if getting product sale fails
    public static int GetProductSaleInPercent(string productId,
                                              string baseProductId,
                                              InAppInventory productsInventory,
                                              FundSettingsManager fundSettingsManager)
    {
        // method failed return code
        const int failed = -1;

        InAppProduct product     = productsInventory.Product(productId);
        InAppProduct baseProduct = productsInventory.Product(baseProductId);

        if (baseProduct == null)
        {
            Debug.LogWarning("ProductsSalesProvider -> GetProductSaleInPercent: BaseProduct with id " + baseProductId +
                             " is not contained in the inventory. Product sale cannot be computed.");
            return(failed);
        }

        if (product == null)
        {
            return(failed);
        }

        float baseProductCoinPrice = GetOneGoldCoinPrice(baseProduct, fundSettingsManager);
        float productCoinPrice     = GetOneGoldCoinPrice(product, fundSettingsManager);

        float productSale          = (baseProductCoinPrice / productCoinPrice) - 1;
        int   productSaleInPercent = (int)Math.Round(productSale * 100);

        return(productSaleInPercent);
    }
Example #7
0
    void OnPurchaseSuccess(string id)
    {
        purchasing = false;

        InAppPurchasesSystem.OnPurchaseSuccess -= OnPurchaseSuccess;
        InAppPurchasesSystem.OnPurchaseFail    -= OnPurchaseFail;
        InAppPurchasesSystem.OnPurchaseCancel  -= OnPurchaseFail;

        InAppProduct product = InAppPurchasesSystem.Instance.GetProduct(id);

        if (product != null)
        {
                        #if UNITY_ANDROID
            AnalyticsBinding.LogEventPaymentAction(product.currencyCode, InAppPurchasesSystem.locale, "-" + product.price, id, 1, "lives_refill",
                                                   "consumable", "", LoadLevelButton.lastUnlockedLevel);
                        #else
            float price;
            if (!float.TryParse(product.price, out price))
            {
                price = 0.99f;
            }

            AnalyticsBinding.LogEventPaymentAction(product.currencyCode, InAppPurchasesSystem.locale, -price, id, 1, "lives_refill", "consumable", "", LoadLevelButton.lastUnlockedLevel);
                        #endif
        }


//		PlayerPrefs.SetInt(LivesSystem.livesKey, LivesSystem.maxLives);
//		PlayerPrefs.Save();
        UserManagerCloud.Instance.CurrentUser.NumsLiveLeft = LivesSystem.maxLives;
        UserCloud.Serialize(UserManagerCloud.FILE_NAME_LOCAL);
        LivesSystem.instance.Lives = LivesSystem.maxLives;

        fsm.SendEvent(sendEvent);
    }
Example #8
0
 void PurchaseSuccessCallback(SKPaymentTransaction transaction, InAppProduct product)
 {
     if (product.ProductIdentifier == Constants.PURCHASE_ID[(int)Constants.PURCHASE_TYPE.DROP])
     {
         CreateDrop(ItemModel.parseItem);
     }
     else if (product.ProductIdentifier == Constants.PURCHASE_ID[(int)Constants.PURCHASE_TYPE.EXPIRY])
     {
         SetNoExpiry();
     }
 }
Example #9
0
        /// <summary>
        /// 요청하는 ID해당하는 상품 값을 얻어온다.
        /// </summary>
        /// <param name="productID"> 마켓에 등록된 상품 ID </param>
        /// <param name="product"> 반환 될 상품 </param>
        /// <returns></returns>
        public virtual bool TryGetPriceInfo(string productID, out InAppProduct product)
        {
            if (!_DicProduct.TryGetValue(productID, out product))
            {
                product = new InAppProduct(productID, ConvertJsonToString(productID, _JsonProductInfo));
                _DicProduct.Add(productID, product);                    // 한번 조회한 데이터는 Dictionary에 캐싱
                return(false);
            }

            return(true);
        }
Example #10
0
        public void DisplayProduct(InAppPurchaseManager purchaseManager, InAppProduct product)
        {
            // Save copy of the current product and purchase manager
            _purchaseManager = purchaseManager;
            Product          = product;

            // Set image based on the product type
            switch (product.ProductType)
            {
            case InAppProductType.NonConsumable:
                if (product.Downloadable)
                {
                    // ItemImage.Image = UIImage.FromFile("Images/Downloadable.png");
                }
                else
                {
                    //  ItemImage.Image = UIImage.FromFile("Images/NonConsumable.png");
                }
                break;

            case InAppProductType.Consumable:
                //ItemImage.Image = UIImage.FromFile("Images/Consumable.png");
                break;

            case InAppProductType.AutoRenewableSubscription:
                // ItemImage.Image = UIImage.FromFile("Images/Subscription.png");
                break;

            case InAppProductType.FreeSubscription:
                //ItemImage.Image = UIImage.FromFile("Images/FreeSubscription.png");
                break;

            case InAppProductType.NonRenewingSubscription:
                //ItemImage.Image = UIImage.FromFile("Images/NonRenewingSubscription.png");
                break;

            case InAppProductType.Unknown:
                //ItemImage.Image = UIImage.FromFile("Images/Unknown.png");
                break;
            }

            // Fill in the rest of the information
            _isRestore = false;
            //ItemTitle.Text = product.Title;
            //DownloadProgress.Hidden = true;
            //ItemDescription.Text = product.Description;
            //ItemPrice.Text = product.FormattedPrice;
            //BuyButton.SetTitle("Buy", UIControlState.Normal);
            //BuyButton.Hidden = !_purchaseManager.CanMakePayments;
            //BuyButton.Enabled = true;

            // Wireup Button
            WireupBuyButton();
        }
        /// <Docs>Table view requesting the cell.</Docs>
        /// <summary>
        /// Gets the cell.
        /// </summary>
        /// <returns>The cell.</returns>
        /// <param name="tableView">Table view.</param>
        /// <param name="indexPath">Index path.</param>
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            var cell = tableView.DequeueReusableCell(PurchaseTableCell.Key) as PurchaseTableCell;

            // Get product for given cell
            InAppProduct product = purchases [indexPath.Row];

            // Populate cell with product information
            cell.DisplayProduct(_controller, _controller.PurchaseManager, product);

            return(cell);
        }
Example #12
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // return number < 0 if fails
    static float GetProductPrice(InAppProduct product)
    {
        // method failed return code
        const float failed = -1;

        try
        {
            return(Convert.ToSingle(product.Price));
        }
        catch (Exception e)
        {
            Debug.LogError("ProductsSalesProvider->GetProductPrice\n" + "Product price: " + product.Price + "\n" + "Exception: " + e.ToString());
            return(failed);
        }
    }
Example #13
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // return number < 0 if fails
    static int GetGoldCoinsCount(InAppProduct product, FundSettingsManager fundSettingsManager)
    {
        // method failed return code
        const int failed = -1;

        try
        {
            int          fundGUID = GetFundGUID(product.ProductId);
            FundSettings fund     = fundSettingsManager.FindByGUID(fundGUID);

            return(fund.AddGold);
        }
        catch
        {
            return(failed);
        }
    }
Example #14
0
		public void DisplayProduct(InAppPurchaseManager purchaseManager, InAppProduct product) {

			// Save copy of the current product and purchase manager
			_purchaseManager = purchaseManager;
			Product = product;

			// Set image based on the product type
			switch (product.ProductType) {
			case InAppProductType.NonConsumable:
				if (product.Downloadable) {
					ItemImage.Image = UIImage.FromFile ("Images/Downloadable.png");
				} else {
					ItemImage.Image = UIImage.FromFile ("Images/NonConsumable.png");
				}
				break;
			case InAppProductType.Consumable:
				ItemImage.Image = UIImage.FromFile ("Images/Consumable.png");
				break;
			case InAppProductType.AutoRenewableSubscription:
				ItemImage.Image = UIImage.FromFile ("Images/Subscription.png");
				break;
			case InAppProductType.FreeSubscription:
				ItemImage.Image = UIImage.FromFile ("Images/FreeSubscription.png");
				break;
			case InAppProductType.NonRenewingSubscription:
				ItemImage.Image = UIImage.FromFile ("Images/NonRenewingSubscription.png");
				break;
			case InAppProductType.Unknown:
				ItemImage.Image = UIImage.FromFile ("Images/Unknown.png");
				break;
			}

			// Fill in the rest of the information
			_isRestore = false;
			ItemTitle.Text = product.Title;
			DownloadProgress.Hidden = true;
			ItemDescription.Text = product.Description;
			ItemPrice.Text = product.FormattedPrice;
			BuyButton.SetTitle ("Buy", UIControlState.Normal);
			BuyButton.Hidden = !_purchaseManager.CanMakePayments;
			BuyButton.Enabled = true;

			// Wireup Button
			WireupBuyButton ();
		}
Example #15
0
    public override InAppProduct GetProduct(string productId)
    {
        if (productList == null)
        {
            return(base.GetProduct(productId));
        }

        foreach (GoogleSkuInfo product in productList)
        {
            if (product.productId == productId)
            {
                InAppProduct myProduct = new InAppProduct();

                myProduct.id = productId;

                Regex regex = new Regex("(?<price>([0-9]*[.,]?[0-9]+)+)");
                Match match = regex.Match(product.price);

                Debug.Log("Product price: " + product.price);
                if (match.Success)
                {
                    myProduct.price        = match.Groups["price"].Value;
                    myProduct.currencyCode = product.price.Replace(myProduct.price, "").Trim();
                    if (currencies.ContainsKey(myProduct.currencyCode))
                    {
                        myProduct.currencyCode = currencies[myProduct.currencyCode];
                    }
                    else if (myProduct.currencyCode.Length != 3)
                    {
                        myProduct.currencyCode = "NUL";                         //fallback
                    }
                    Debug.Log("Product currency code: " + myProduct.currencyCode);
                }
                else
                {
                    myProduct.price        = product.price;
                    myProduct.currencyCode = "NUL";                     //fallback
                }

                return(myProduct);
            }
        }

        return(base.GetProduct(productId));
    }
Example #16
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // return null if fails
    static InAppProduct GetCheapestProduct(InAppInventory productsInventory)
    {
        InAppProduct cheapestProduct      = null;
        float        cheapestProductPrice = float.MaxValue;

        foreach (InAppProduct product in productsInventory)
        {
            float productPrice = GetProductPrice(product);

            if (productPrice >= 0 && productPrice < cheapestProductPrice)
            {
                cheapestProduct      = product;
                cheapestProductPrice = productPrice;
            }
        }

        return(cheapestProduct);
    }
    void OnPurchaseSuccess(string id)
    {
        purchasing = false;

        InAppPurchasesSystem.OnPurchaseSuccess -= OnPurchaseSuccess;
        InAppPurchasesSystem.OnPurchaseFail    -= OnPurchaseFail;
        InAppPurchasesSystem.OnPurchaseCancel  -= OnPurchaseFail;

        InAppProduct product = InAppPurchasesSystem.Instance.GetProduct(id);

        if (product != null)
        {
            BasicItem itemComponent = item.itemPrefab.GetComponent <BasicItem>();

            string subtype = "small";
            if (packIndex == 1)
            {
                subtype = "medium";
            }
            else if (packIndex == 2)
            {
                subtype = "large";
            }

                        #if UNITY_ANDROID
            AnalyticsBinding.LogEventPaymentAction(product.currencyCode, InAppPurchasesSystem.locale, "-" + product.price, id, 1, itemComponent.ItemName,
                                                   "consumable", endGame ? "postgame" : "ingame", Match3BoardRenderer.levelIdx);
                        #else
            float price;
            if (!float.TryParse(product.price, out price))
            {
                price = 0.99f + packIndex * 1f;
            }

            AnalyticsBinding.LogEventPaymentAction(product.currencyCode, InAppPurchasesSystem.locale, -price, id, 1, itemComponent.ItemName,
                                                   "consumable", endGame ? "postgame" : "ingame", Match3BoardRenderer.levelIdx);
                        #endif
        }

        item.AddItems(itemCount + freeItemCount);
        buyFSM.SendEvent("BuyFinished");
    }
Example #18
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    // return number < 0 if fails
    static float GetProductPriceForFund(ShopItemId shopFund, InAppInventory productsInventory, FundSettingsManager fundSettingsManager)
    {
        // method failed return code
        const float failed = -1;

        string productId = GetProductId(shopFund, fundSettingsManager);

        if (productId == null)
        {
            return(failed);
        }

        InAppProduct product = productsInventory.Product(productId);

        if (product == null)
        {
            return(failed);
        }

        return(GetProductPrice(product));
    }
Example #19
0
    public void UpdateContent()
    {
        Debug.Log("DiamondTable update content!");
        for (int i = 0; i < transform.childCount; i++)
        {
            DiamondCell cellCom = transform.GetChild(i).gameObject.GetComponent <DiamondCell>();
            cellCom.diamondProductID = i;

            DiamondProductData diamondProduct = ItemModel.Instance.diamondProducts[i];
            Debug.Log("productID:" + diamondProduct.productID);
            InAppProduct product = InAppPurchasesSystem.Instance.GetProduct(diamondProduct.productID);

            if (product != null)
            {
                // RMB number
                Debug.Log("text: " + product.currencyCode.ToString() + " " + product.price.ToString());
                GameObject diamondNumObj = cellCom.transform.Find("ConfirmButton/NumLabel").gameObject;
                UILabel    diamondNumCom = diamondNumObj.GetComponent <UILabel>();
                diamondNumCom.text = product.currencyCode.ToString() + " " + product.price.ToString();
            }
        }
    }
	public override InAppProduct GetProduct(string productId)
	{
		if (productList == null) {
			return base.GetProduct(productId);
		}
		
		foreach (StoreKitProduct product in productList) 
		{
			if (product.productIdentifier == productId) 
			{
				InAppProduct myProduct = new InAppProduct();
				
				myProduct.id = productId;
				myProduct.price = product.price;
				myProduct.currencyCode = product.currencyCode;
				
				return myProduct;
			}
		}
		
		return base.GetProduct(productId);
	}
    public override InAppProduct GetProduct(string productId)
    {
        if (productList == null)
        {
            return(base.GetProduct(productId));
        }

        foreach (StoreKitProduct product in productList)
        {
            if (product.productIdentifier == productId)
            {
                InAppProduct myProduct = new InAppProduct();

                myProduct.id           = productId;
                myProduct.price        = product.price;
                myProduct.currencyCode = product.currencyCode;

                return(myProduct);
            }
        }

        return(base.GetProduct(productId));
    }
Example #22
0
    protected override void OnViewShow()
    {
        base.OnViewShow();

        Debug.Log("Not Funds Show");
        //Show fund info
        if (!ShopDataBridge.Instance.IsIAPFund(AddFundsID))
        {
            Debug.LogError("Selected funds is not IAP: " + AddFundsID);
        }

        ShopItemInfo inf    = ShopDataBridge.Instance.GetItemInfo(AddFundsID);
        string       strBuy = TextDatabase.instance[02030093];

        strBuy = strBuy.Replace("%d1", inf.AddGold.ToString());

        string productId = FundSettingsManager.Instance.Get((E_FundID)(AddFundsID.Id)).GUID.ToString();

        InAppInventory inventory = InAppPurchaseMgr.Instance.Inventory;
        InAppProduct   product   = null;

        if (inventory != null)
        {
            product = inventory.Product(productId);
        }

        if (product != null)
        {
            // add price to the buy label string
            strBuy += " (" + product.Price + " " + product.CurrencyCode + ")";
        }

        GUIBase_Label buyLabel = GuiBaseUtils.PrepareLabel(m_ScreenLayout, "Buy_Label");

        buyLabel.SetNewText(strBuy);
    }
Example #23
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    internal void AddProduct(InAppProduct product)
    {
        m_Products[product.ProductId] = product;
    }
Example #24
0
        public void DisplayProduct(PurchaseTableViewController controller, InAppPurchaseManager purchaseManager, InAppProduct product)
        {
            // Save copy of the current product and purchase manager
            _controller      = controller;
            _purchaseManager = purchaseManager;
            Product          = product;

            // Set image based on the product type
            switch (product.ProductType)
            {
            case InAppProductType.NonConsumable:
                if (product.Downloadable)
                {
                    ItemImage.Image = UIImage.FromFile("Images/Downloadable.png");
                }
                else
                {
                    ItemImage.Image = UIImage.FromFile("Images/NonConsumable.png");
                }
                break;

            case InAppProductType.Consumable:
                ItemImage.Image = UIImage.FromFile("Images/Consumable.png");
                break;

            case InAppProductType.AutoRenewableSubscription:
                ItemImage.Image = UIImage.FromFile("Images/Subscription.png");
                break;

            case InAppProductType.FreeSubscription:
                ItemImage.Image = UIImage.FromFile("Images/FreeSubscription.png");
                break;

            case InAppProductType.NonRenewingSubscription:
                ItemImage.Image = UIImage.FromFile("Images/NonRenewingSubscription.png");
                break;

            case InAppProductType.Unknown:
                ItemImage.Image = UIImage.FromFile("Images/Unknown.png");
                break;
            }

            // Fill in the rest of the information
            ItemTitle.Text       = product.Title;
            ItemDescription.Text = product.Description;
            UpdateButton.Hidden  = true;

            // Take action based on the product type
            switch (Product.ProductType)
            {
            case InAppProductType.Consumable:
                // Show remaining quantity
                AvailableQuantity.Hidden = false;
                AvailableQuantity.Text   = String.Format("{0} qty", product.AvailableQuantity);
                break;

            case InAppProductType.AutoRenewableSubscription:
            case InAppProductType.NonRenewingSubscription:
                // Force this product to use a calculated date
                product.UseCalculatedExpirationDate = true;

                // Show expiration date
                AvailableQuantity.Hidden = false;
                AvailableQuantity.Text   = String.Format("Exp {0:d}", product.SubscriptionExpirationDate);
                break;

            case InAppProductType.FreeSubscription:
                // Show it never expires
                AvailableQuantity.Hidden = false;
                AvailableQuantity.Text   = "Unlimited";
                break;

            case InAppProductType.NonConsumable:
                if (Product.Downloadable)
                {
                    // Use quantity to show download state
                    if (Product.NewContentAvailable)
                    {
                        AvailableQuantity.Text = string.Format("v{0} Available", Product.DownloadableContentVersion);

                        // Display update button and wire it up
                        _displayContent     = false;
                        UpdateButton.Hidden = _purchaseManager.DownloadInProgress;
                        UpdateButton.SetTitle("Update", UIControlState.Normal);
                        WireupUpdateButton();
                    }
                    else if (Product.ContentDownloaded)
                    {
                        AvailableQuantity.Text = string.Format("Ready v{0}", Product.DownloadableContentVersion);

                        // Display button
                        _displayContent     = true;
                        UpdateButton.Hidden = false;
                        UpdateButton.SetTitle("Show", UIControlState.Normal);
                        WireupUpdateButton();
                    }
                    else
                    {
                        AvailableQuantity.Text = "Awaiting Content";

                        // Display update button and wire it up
                        _displayContent     = false;
                        UpdateButton.Hidden = _purchaseManager.DownloadInProgress;
                        UpdateButton.SetTitle("Get", UIControlState.Normal);
                        WireupUpdateButton();
                    }
                    AvailableQuantity.Hidden = false;
                }
                else
                {
                    // Not downloadable, hide quantity
                    AvailableQuantity.Hidden = true;
                }
                break;

            default:
                AvailableQuantity.Hidden = true;
                break;
            }
        }
Example #25
0
        public void Initialize()
        {
            this._customPaymentObserver = new CustomPaymentObserver(this);
            SKPaymentQueue.DefaultQueue.AddTransactionObserver(this._customPaymentObserver);

            this._queryInventoryObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppQueryInventoryNotification,
                                                                                          (notification) =>
            {
                var info = notification.UserInfo;
                if (info == null)
                {
                    // TODO: Had to put this in so it wouldn't crash, needs a revisit
                    return;
                }
                var practiceModeProductId = new NSString(this.PracticeModeProductId);

                var product = (SKProduct)info.ObjectForKey(practiceModeProductId);

                // Update inventory
                var newProduct               = new InAppProduct();
                newProduct.ProductId         = this.PracticeModeProductId;
                newProduct.Type              = "inapp";
                newProduct.Price             = this.LocalizedPrice(product);
                newProduct.PriceCurrencyCode = product.PriceLocale.CurrencyCode;
                newProduct.Title             = product.LocalizedTitle;
                newProduct.Description       = product.LocalizedDescription;

                App.ViewModel.Products.Add(newProduct);

                // Notify anyone who needed to know that our inventory is in
                if (this.OnQueryInventory != null)
                {
                    this.OnQueryInventory();
                }
            });

            this._queryInventoryErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppQueryInventoryErrorNotification,
                                                                                               (notification) =>
            {
                // Notify anyone who needed to know that there was a query inventory error
                if (this.OnQueryInventoryError != null)
                {
                    this.OnQueryInventoryError(0, null);
                }
            });

            this._purchaseProductObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppPurchaseProductNotification,
                                                                                           (notification) =>
            {
                // Notify anyone who needed to know that product was purchased
                if (this.OnPurchaseProduct != null)
                {
                    this.OnPurchaseProduct();
                }
            });

            this._purchaseProductErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppPurchaseProductErrorNotification,
                                                                                                (notification) =>
            {
                // Notify anyone who needed to know that there was a product purchase error
                if (this.OnPurchaseProductError != null)
                {
                    this.OnPurchaseProductError(0, string.Empty);
                }
            });

            this._restoreProductsObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppRestoreProductsNotification,
                                                                                           (notification) =>
            {
                // Notify anyone who needed to know that products were restored
                if (this.OnRestoreProducts != null)
                {
                    this.OnRestoreProducts();
                }
            });

            this._restoreProductsErrorObserver = NSNotificationCenter.DefaultCenter.AddObserver(InAppService.InAppRestoreProductsErrorNotification,
                                                                                                (notification) =>
            {
                // Notify anyone who needed to know that there was an error in restoring products
                if (this.OnRestoreProductsError != null)
                {
                    this.OnRestoreProductsError(0, null);
                }
            });

            if (this.CanMakePayments())
            {
                // Async request
                // StoreKit -> App Store -> ReceivedResponse (see below)
                this.QueryInventory();
            }
        }
Example #26
0
 public InAppAsyncOpResult RequestPurchaseProduct(InAppProduct product)
 {
     // TODO: implement minimum placeholder functionality (return an request which fails in few tens of seconds
     return(null);
 }
Example #27
0
 private void OnInAppProductPurchaseFailed(SKPaymentTransaction transaction, InAppProduct product)
 {
     Console.WriteLine("OnInAppProductPurchaseFailed");
 }
Example #28
0
        /// <summary>
        /// Updates the details of an in-app product.
        /// Documentation https://developers.google.com/androidpublisher/v2/reference/inappproducts/update
        /// Generation Note: This does not always build corectly.  Google needs to standardise things I need to figuer out which ones are wrong.
        /// </summary>
        /// <param name="service">Authenticated AndroidPublisher service.</param>
        /// <param name="packageName">Unique identifier for the Android app with the in-app product; for example, "com.spiffygame".</param>
        /// <param name="sku">Unique identifier for the in-app product.</param>
        /// <param name="body">A valid AndroidPublisher v2 body.</param>
        /// <param name="optional">Optional paramaters.</param>        /// <returns>InAppProductResponse</returns>
        public static InAppProduct Update(AndroidPublisherService service, string packageName, string sku, InAppProduct body, InappproductsUpdateOptionalParms optional = null)
        {
            try
            {
                // Initial validation.
                if (service == null)
                {
                    throw new ArgumentNullException("service");
                }
                if (body == null)
                {
                    throw new ArgumentNullException("body");
                }
                if (packageName == null)
                {
                    throw new ArgumentNullException(packageName);
                }
                if (sku == null)
                {
                    throw new ArgumentNullException(sku);
                }

                // Building the initial request.
                var request = service.Inappproducts.Update(body, packageName, sku);

                // Applying optional parameters to the request.
                request = (InappproductsResource.UpdateRequest)SampleHelpers.ApplyOptionalParms(request, optional);

                // Requesting data.
                return(request.Execute());
            }
            catch (Exception ex)
            {
                throw new Exception("Request Inappproducts.Update failed.", ex);
            }
        }
	public override InAppProduct GetProduct(string productId)
	{
		if (productList == null) {
			return base.GetProduct(productId);
		}
		
		foreach (GoogleSkuInfo product in productList) 
		{
			if (product.productId == productId) 
			{
				InAppProduct myProduct = new InAppProduct();
				
				myProduct.id = productId;

		        Regex regex = new Regex("(?<price>([0-9]*[.,]?[0-9]+)+)");
		        Match match = regex.Match(product.price);
		
				Debug.Log("Product price: " + product.price);
		        if (match.Success)
		        {
		            myProduct.price = match.Groups["price"].Value;
					myProduct.currencyCode = product.price.Replace(myProduct.price ,"").Trim();
					if (currencies.ContainsKey(myProduct.currencyCode)) {
						myProduct.currencyCode = currencies[myProduct.currencyCode];
					}
					else if (myProduct.currencyCode.Length != 3) {
						myProduct.currencyCode = "NUL"; //fallback
					}
					Debug.Log("Product currency code: " + myProduct.currencyCode);
		        }
				else {
					myProduct.price = product.price;
					myProduct.currencyCode = "NUL"; //fallback
				}
				
				return myProduct;
			}
		}
		
		return base.GetProduct(productId);
	}
Example #30
0
		public void DisplayProduct(PurchaseTableViewController controller, InAppPurchaseManager purchaseManager, InAppProduct product) {

			// Save copy of the current product and purchase manager
			_controller = controller;
			_purchaseManager = purchaseManager;
			Product = product;

			// Set image based on the product type
			switch (product.ProductType) {
			case InAppProductType.NonConsumable:
				if (product.Downloadable) {
					ItemImage.Image = UIImage.FromFile ("Images/Downloadable.png");
				} else {
					ItemImage.Image = UIImage.FromFile ("Images/NonConsumable.png");
				}
				break;
			case InAppProductType.Consumable:
				ItemImage.Image = UIImage.FromFile ("Images/Consumable.png");
				break;
			case InAppProductType.AutoRenewableSubscription:
				ItemImage.Image = UIImage.FromFile ("Images/Subscription.png");
				break;
			case InAppProductType.FreeSubscription:
				ItemImage.Image = UIImage.FromFile ("Images/FreeSubscription.png");
				break;
			case InAppProductType.NonRenewingSubscription:
				ItemImage.Image = UIImage.FromFile ("Images/NonRenewingSubscription.png");
				break;
			case InAppProductType.Unknown:
				ItemImage.Image = UIImage.FromFile ("Images/Unknown.png");
				break;
			}

			// Fill in the rest of the information
			ItemTitle.Text = product.Title;
			ItemDescription.Text = product.Description;
			UpdateButton.Hidden = true;

			// Take action based on the product type
			switch (Product.ProductType) {
			case InAppProductType.Consumable:
				// Show remaining quantity
				AvailableQuantity.Hidden = false;
				AvailableQuantity.Text = String.Format ("{0} qty", product.AvailableQuantity);
				break;
			case InAppProductType.AutoRenewableSubscription:
			case InAppProductType.NonRenewingSubscription:
				// Force this product to use a calculated date
				product.UseCalculatedExpirationDate = true;

				// Show expiration date
				AvailableQuantity.Hidden = false;
				AvailableQuantity.Text = String.Format ("Exp {0:d}", product.SubscriptionExpirationDate);
				break;
			case InAppProductType.FreeSubscription:
				// Show it never expires
				AvailableQuantity.Hidden = false;
				AvailableQuantity.Text = "Unlimited";
				break;
			case InAppProductType.NonConsumable:
				if (Product.Downloadable) {
					// Use quantity to show download state
					if (Product.NewContentAvailable) {
						AvailableQuantity.Text = string.Format("v{0} Available",Product.DownloadableContentVersion);

						// Display update button and wire it up
						_displayContent = false;
						UpdateButton.Hidden = _purchaseManager.DownloadInProgress;
						UpdateButton.SetTitle ("Update", UIControlState.Normal);
						WireupUpdateButton ();
					} else if (Product.ContentDownloaded) {
						AvailableQuantity.Text = string.Format("Ready v{0}",Product.DownloadableContentVersion);

						// Display button
						_displayContent = true;
						UpdateButton.Hidden = false;
						UpdateButton.SetTitle ("Show", UIControlState.Normal);
						WireupUpdateButton ();
					} else {
						AvailableQuantity.Text = "Awaiting Content";

						// Display update button and wire it up
						_displayContent = false;
						UpdateButton.Hidden = _purchaseManager.DownloadInProgress;
						UpdateButton.SetTitle ("Get", UIControlState.Normal);
						WireupUpdateButton ();
					}
					AvailableQuantity.Hidden = false;
				} else {
					// Not downloadable, hide quantity
					AvailableQuantity.Hidden = true;
				}
				break;
			default:
				AvailableQuantity.Hidden = true;
				break;
			}

		}
Example #31
0
        void ExpiryPurchase()
        {
            InAppProduct product = AppDelegate.PurchaseManager.FindProduct(Constants.PURCHASE_ID[(int)Constants.PURCHASE_TYPE.EXPIRY]);

            AppDelegate.PurchaseManager.BuyProduct(product);
        }
Example #32
0
        void OpenPurchase()
        {
            InAppProduct product = AppDelegate.PurchaseManager.FindProduct(Constants.PURCHASE_ID[(int)Constants.PURCHASE_TYPE.DROP]);

            AppDelegate.PurchaseManager.BuyProduct(product);
        }
Example #33
0
        public void QueryInventory()
        {
            // Are we connected to a network?
            ConnectivityManager connectivityManager = (ConnectivityManager)MainActivity.Instance.GetSystemService(MainActivity.ConnectivityService);
            NetworkInfo         activeConnection    = connectivityManager.ActiveNetworkInfo;

            if ((activeConnection != null) && activeConnection.IsConnected)
            {
                // Ok, carefully attempt to connect to the in-app service
                try
                {
                    // Asynchronously get inventory
                    Task.Factory.StartNew(() =>
                                          MP.MpUtils.FetchPaymentData(Android.App.Application.Context, FortumoInAppService._serviceId, FortumoInAppService._inAppSecret));

                    // Asnchronously get purchases
                    Task.Factory.StartNew(() =>
                    {
                        var responses = MP.MpUtils.GetPurchaseHistory(Android.App.Application.Context, FortumoInAppService._serviceId, FortumoInAppService._inAppSecret, FortumoInAppService._timeOut);

                        // Record what we purchased
                        foreach (var response in responses)
                        {
                            var paymentResponse = response as PaymentResponse;

                            // Sanity checks
                            if (paymentResponse == null ||
                                paymentResponse.BillingStatus != MP.MpUtils.MessageStatusBilled)
                            {
                                continue;
                            }

                            // Ok to record payment
                            this.UpdatePayment(paymentResponse);
                        }
                    });

                    // Get local inventory
                    // IMPORTANT: First time this is called, result will be empty)
                    var priceData = MP.MpUtils.GetFetchedPriceData(Android.App.Application.Context, FortumoInAppService._serviceId, FortumoInAppService._inAppSecret);

                    // TODO: Process priceData
                    // Update inventory
                    var inAppSkuRepository = new InAppProduct();

                    /*
                     * foreach (var product in products)
                     * {
                     *  var existingProduct = inAppSkuRepository.GetSkuByProductId(product.ProductId);
                     *  if (existingProduct != null)
                     *  {
                     *      existingProduct.Type = ItemType.Product;
                     *      existingProduct.Price = product.Price;
                     *      existingProduct.Title = product.Title;
                     *      existingProduct.Description = product.Description;
                     *      existingProduct.PriceCurrencyCode = product.Price_Currency_Code;
                     *
                     *      inAppSkuRepository.Update(existingProduct);
                     *  }
                     *  else
                     *  {
                     *      var newProduct = new InAppSkuEntity();
                     *      newProduct.ProductId = product.ProductId;
                     *      newProduct.Type = ItemType.Product;
                     *      newProduct.Price = product.Price;
                     *      newProduct.Title = product.Title;
                     *      newProduct.Description = product.Description;
                     *      newProduct.PriceCurrencyCode = product.Price_Currency_Code;
                     *
                     *      inAppSkuRepository.Create(newProduct);
                     *  }
                     * }
                     */

                    this.FireOnQueryInventory();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Exception trying to connect to in app service: " + ex);
                    this.FireOnQueryInventoryError(-1, null);
                }
            }
        }
Example #34
0
        private async void ProductPurchased(StoreKit.SKPaymentTransaction transaction, InAppProduct product)
        {
            // update list to remove any non-consumable products that were
            var result = await App.Locator.ReloadCredit.InsertPurchase(product.ProductIdentifier
                                                                       , string.Empty
                                                                       , string.Empty
                                                                       , PlateformeVersionEnum.IOS);

            if (result == 0)
            {
                using (var alert = new UIAlertView(Application.LocalizedString("BuyPack")
                                                   , string.Format(Application.LocalizedString("BuySuccess")
                                                                   , product.Title)
                                                   , null
                                                   , Application.LocalizedString("OK")
                                                   , null))
                {
                    alert.Show();
                }
            }
        }
Example #35
0
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------

    internal void RemoveProduct(InAppProduct product)
    {
        m_Products.Remove(product.ProductId);
    }