Esempio n. 1
0
        public InAppViewModel()
        {
            _inAppService = DependencyService.Get <IFortumoInAppService>();
            _inAppService.OnQueryInventory  += OnQueryInventory;
            _inAppService.OnPurchaseProduct += OnPurchaseProduct;
            _inAppService.OnRestoreProducts += OnRestoreProducts;

            _purchases    = new ObservableCollection <InAppPurchase>();
            _purchaseList = new InAppPurchaseList();

            InitializeProducts();

            QueryCommand = new Command <InAppProduct>(
                execute: (product) =>
            {
                _inAppService.QueryInventory();
            });

            PurchaseCommand = new Command <InAppProduct>(
                execute: (product) =>
            {
                _inAppService.PurchaseProduct(product.ProductId);
            });

            RestoreCommand = new Command <InAppProduct>(
                execute: (product) =>
            {
                _inAppService.RestoreProducts();
            });
        }
Esempio n. 2
0
        public void RestoreState(IDictionary <string, object> dictionary)
        {
            string purchases = GetDictionaryEntry(dictionary, "Purchases", string.Empty);

            if (purchases != string.Empty)
            {
                DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(InAppPurchaseList));
                using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(purchases)))
                {
                    InAppPurchaseList purchaseList = (InAppPurchaseList)ser.ReadObject(ms);
                    Purchases = new ObservableCollection <InAppPurchase>(purchaseList.Purchases);
                }
            }
        }