public async void requestProductData(string args)
        {
            try
            {
                string InAppProductKey = JsonHelper.Deserialize <string[]>(args)[0];

                // get specific in-app product by ID
                ListingInformation products = await CurrentApp.LoadListingInformationByProductIdsAsync(new string[] { InAppProductKey });

                ProductListing productListing = null;
                if (!products.ProductListings.TryGetValue(InAppProductKey, out productListing))
                {
                    this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Could not find product information"));
                    return;
                }


                System.Diagnostics.Debug.WriteLine(productListing.FormattedPrice);

                var results = new Dictionary <string, string>();
                results["productId"] = InAppProductKey;
                results["title"]     = productListing.Name;

                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, productListing.FormattedPrice));
                return;
            }

            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Unknown Error"));
            }
        }
        public async void invokePurchaceInterface(Grid layout, string productID)
        {
            if (!currentlyRunning)
            {
                try
                {
                    ok.Tap          += ok_Tap;
                    cancel.Tap      += cancel_Tap;
                    currentlyRunning = true;
                    pID                = productID;
                    baseGrid           = layout;
                    purchaseGrid.Width = layout.Width;
                    var info = await CurrentApp.LoadListingInformationByProductIdsAsync(new string[] { productID });

                    details.Text        = info.ProductListings[productID].Description + "\n\nPrice: " + info.ProductListings[productID].FormattedPrice;
                    productImage.Source = new BitmapImage(info.ProductListings[productID].ImageUri);
                    layout.Children.Add(purchaseGrid);
                }
                catch (Exception excep)
                {
                    MessageBox.Show("Server communication error! Please try again later.");
                    currentlyRunning = false;
                    closeInterface(false);
                }
            }
        }
Beispiel #3
0
        public static void LoadListings(string[] productIds)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                Dictionary <string, ProductListing> resultListings = new Dictionary <string, ProductListing>();
                IAsyncOperation <ListingInformation> asyncOp;
                try
                {
                    asyncOp = CurrentApp.LoadListingInformationByProductIdsAsync(productIds);
                }
                catch (Exception e)
                {
                    if (LoadListingsFailed != null)
                    {
                        LoadListingsFailed(GetErrorDescription(e));
                    }
                    return;
                }

                asyncOp.Completed = (op, status) =>
                {
                    if (op.Status == AsyncStatus.Error)
                    {
                        if (LoadListingsFailed != null)
                        {
                            LoadListingsFailed(GetErrorDescription(op.ErrorCode));
                        }
                        return;
                    }

                    if (op.Status == AsyncStatus.Canceled)
                    {
                        if (LoadListingsFailed != null)
                        {
                            LoadListingsFailed("QueryInventory was cancelled");
                        }
                        return;
                    }

                    var listings = op.GetResults();
                    foreach (var l in listings.ProductListings)
                    {
                        var listing       = l.Value;
                        var resultListing = new ProductListing(
                            listing.ProductId,
                            listing.Name,
                            listing.Description,
                            listing.FormattedPrice);
                        resultListings[l.Key] = resultListing;
                    }
                    if (LoadListingsSucceeded != null)
                    {
                        LoadListingsSucceeded(resultListings);
                    }
                };
            });
        }
        public async Task <IList <ProductItem> > LoadProductsAsync(IEnumerable <string> supportedProductIds, string localizedPurchasedText = null)
        {
            var productItems = new List <ProductItem>();

            // fallback purchased text
            if (string.IsNullOrEmpty(localizedPurchasedText))
            {
                localizedPurchasedText = "purchased";
            }

            try
            {
                // load supported products
#if DEBUG
                ListingInformation lisitingInfo = await CurrentAppSimulator.LoadListingInformationByProductIdsAsync(supportedProductIds);
#else
                ListingInformation lisitingInfo = await CurrentApp.LoadListingInformationByProductIdsAsync(supportedProductIds);
#endif

                foreach (var id in lisitingInfo.ProductListings.Keys)
                {
                    ProductListing product         = lisitingInfo.ProductListings[id];
                    var            isProductActive = IsProductActive(id);
                    var            status          = isProductActive ? localizedPurchasedText : product.FormattedPrice;
                    var            imageLink       = string.Empty;
                    productItems.Add(
                        new ProductItem
                    {
                        ImageUri    = product.ImageUri,
                        Name        = product.Name,
                        Description = product.Description,
                        Status      = status,
                        Id          = id,
                        IsActive    = isProductActive
                    }
                        );
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(e, "Loading of products failed");
                return(null);
            }

            return(productItems);
        }
        public async void makePurchase(string args)
        {
            try
            {
                string InAppProductKey = JsonHelper.Deserialize <string[]>(args)[0];


                // get specific in-app product by ID
                ListingInformation products = await CurrentApp.LoadListingInformationByProductIdsAsync(new string[] { InAppProductKey });

                ProductListing productListing = null;
                if (!products.ProductListings.TryGetValue(InAppProductKey, out productListing))
                {
                    this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Could not find product information"));
                    return;
                }

                // RequestProductPurchaseAsync requires use of the UI thread, so we use the dispatcher
                System.Windows.Deployment.Current.Dispatcher.BeginInvoke(async() => {
                    try
                    {
                        await CurrentApp.RequestProductPurchaseAsync(productListing.ProductId, false);

                        ProductLicense productLicense = null;
                        if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue(InAppProductKey, out productLicense))
                        {
                            if (productLicense.IsActive)
                            {
                                this.DispatchCommandResult(new PluginResult(PluginResult.Status.OK, "PaymentTransactionStatePurchased"));
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        //User cancelled the purchase
                        //this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Unknown Error"));
                    }
                });
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
                this.DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "Unknown Error"));
            }
        }
        /// <summary>
        /// Returns the list of all purchaseable items
        /// </summary>
        /// <returns></returns>
        public async Task <List <PurchaseableItem> > PurchaseableItems()
        {
            // First, retrieve the list of some products by their IDs.
        #if DEBUG
            ListingInformation listings = await CurrentAppSimulator.LoadListingInformationByProductIdsAsync(new string[] { "pebble_notifications" });
        #else
            ListingInformation listings = await CurrentApp.LoadListingInformationByProductIdsAsync(new string[] { "pebble_notifications" });
        #endif

            List <PurchaseableItem> Items = new List <PurchaseableItem>();

            foreach (var item in listings.ProductListings.Values)
            {
                Items.Add(new PurchaseableItem {
                    ID = item.ProductId, Name = item.Name, Description = item.Description, Price = item.FormattedPrice
                });
            }

            return(Items);
        }
Beispiel #7
0
        private async void LoadWindowsPrices()
        {
            try
            {
                List <string> productsIds = new List <string>();

                availableTraps.ForEach(a =>
                {
                    productsIds.Add(a.KeyWindows);
                });

                ListingInformation products = await CurrentApp.LoadListingInformationByProductIdsAsync(productsIds);

                if (products != null)
                {
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Beispiel #8
0
 public static void LoadListings(string[] productIds)
 {
     Deployment.Current.Dispatcher.BeginInvoke(() =>
     {
         Dictionary <string, ProductListing> resultListings = new Dictionary <string, ProductListing>();
         try
         {
             IAsyncOperation <ListingInformation> asyncOp = CurrentApp.LoadListingInformationByProductIdsAsync(productIds);
             asyncOp.Completed = (op, status) =>
             {
                 var listings = op.GetResults();
                 foreach (var l in listings.ProductListings)
                 {
                     var listing       = l.Value;
                     var resultListing = new ProductListing(
                         listing.ProductId,
                         listing.Name,
                         listing.Description,
                         listing.FormattedPrice);
                     resultListings[l.Key] = resultListing;
                 }
                 if (LoadListingsSucceeded != null)
                 {
                     LoadListingsSucceeded(resultListings);
                 }
             };
         }
         catch (Exception e)
         {
             if (LoadListingsFailed != null)
             {
                 LoadListingsFailed(e.Message);
             }
         }
     });
 }
Beispiel #9
0
        public async void inAppPurchase_Purchase(string productID)
        {
            try
            {
                ListingInformation products = await CurrentApp.LoadListingInformationByProductIdsAsync(new[] { productID });

                // get specific in-app product by ID
                ProductListing productListing = null;
                if (!products.ProductListings.TryGetValue(productID, out productListing))
                {
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "false");
                    return;
                }

                bool           isActive = false;
                ProductLicense pLicense;
                if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue(productID, out pLicense))
                {
                    isActive = pLicense.IsActive;
                }

                if (isActive)
                {
                    // Auto-consume product
                    if (pLicense.IsConsumable)
                    {
                        CurrentApp.ReportProductFulfillment(productID);
                    }
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true");
                    return;
                }

                string result = await CurrentApp.RequestProductPurchaseAsync(productID, true);

                if (CurrentApp.LicenseInformation.ProductLicenses.TryGetValue(productID, out pLicense))
                {
                    // Auto-consume product
                    if (pLicense.IsConsumable)
                    {
                        CurrentApp.ReportProductFulfillment(productID);
                    }
                }

                if (result.Length > 0)
                {
                    // Purchased
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true");
                }
                else
                {
                    MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "true");
                }
            }
            catch (Exception e)
            {
#if DEBUGON
                MainPage.m_d3dInterop.Print("InAppPurchase::Error" + e.ToString());
#endif

                // The in-app purchase was not completed because the
                // customer canceled it or an error occurred.
                MainPage.m_d3dInterop.csActionResult("CCAppManager::InAppPurchaseSuccessful", "false");
            }
        }
 LoadListingInformationByProductIdsAsync(IEnumerable <string> productIds)
 {
     return(IsMockEnabled
         ? CurrentAppSimulator.LoadListingInformationByProductIdsAsync(productIds)
         : CurrentApp.LoadListingInformationByProductIdsAsync(productIds));
 }
Beispiel #11
0
        //public static async Task<ListingInformation> LoadListingInformationAsync(bool isTestingMode)
        //{
        //   return isTestingMode ? await CurrentAppSimulator.LoadListingInformationAsync() : await CurrentApp.LoadListingInformationAsync();
        //}

        public static async Task <ListingInformation> LoadListingInformationByProductIdsAsync(bool isTestingMode, IEnumerable <string> productIds)
        {
            // This won't work until the app is public
            return(isTestingMode ? await CurrentAppSimulator.LoadListingInformationByProductIdsAsync(productIds) : await CurrentApp.LoadListingInformationByProductIdsAsync(productIds));
        }