Esempio n. 1
0
        public async static void RequestLicense(string productKey)
        {
            if (NetworkInterface.GetIsNetworkAvailable() == true)
            {
                try
                {
#if DEBUG
                    await CurrentAppSimulator.RequestProductPurchaseAsync(productKey);
#else
                    var result = await CurrentApp.RequestProductPurchaseAsync(productKey);
#endif

                    if (licenseInformation.ProductLicenses[productKey].IsActive)
                    {
                        HelperUWP.Reporting.DisplayMessage("Successfully Purchased the product forever! " + HelperUWP.Reporting.AppName, "Successfully Purchased");
                    }
                    else
                    {
                        HelperUWP.Reporting.DisplayMessage("Product key was not purchased" + HelperUWP.Reporting.AppName + " Please restart app and try again" + " -> UpradePage");
                    }
                }
                catch (Exception ex)
                {
                    HelperUWP.Reporting.DisplayMessage(ex.Message + "Product key was not purchased" + HelperUWP.Reporting.AppName + " Please restart app and try again" + "->UpradePage");
                }
            }
            else
            {
                HelperUWP.Reporting.NoConnections();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Check if the product is already activated on MEGA license server
        /// </summary>
        /// <param name="productId">Product identifier</param>
        private static async Task CheckLicenseAsync(string productId)
        {
            try
            {
                if (string.IsNullOrEmpty(productId))
                {
                    return;
                }
#if DEBUG
                var receipt = await CurrentAppSimulator.GetProductReceiptAsync(productId);
#else
                var receipt = await CurrentApp.GetProductReceiptAsync(productId);
#endif
                if (string.IsNullOrEmpty(receipt))
                {
                    return;
                }

                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Checking product license...");
                LogService.Log(MLogLevel.LOG_LEVEL_DEBUG, "License info: " + receipt);

                if (!CheckReceiptIdStatus(receipt))
                {
                    await ActivateMegaLicenseAsync(receipt);
                }
            }
            catch (Exception e)
            {
                // If an error occurs, ignore. App will try again on restart
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error (re-)checking licenses", e);
            }
        }
        private async void Donation_Click(object sender, RoutedEventArgs e)
        {
            if (!Config.Instance.LicenseInformation.ProductLicenses[InAppPurchase.TokenDonation].IsActive)
            {
                try
                {
                    // show the purchase dialog.
#if DEBUG
                    await CurrentAppSimulator.RequestProductPurchaseAsync(InAppPurchase.TokenDonation);
#else
                    await CurrentApp.RequestProductPurchaseAsync(InAppPurchase.TokenDonation);
#endif
                    SetDonations();
                }
                catch (Exception)
                {
                    // The in-app purchase was not completed because
                    // an error occurred.
                }
            }
            else
            {
                SetDonations();
            }
        }
Esempio n. 4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;

            if (!licenseInformation.ProductLicenses["product2"].IsActive)
            {
                try
                {
                    await CurrentAppSimulator.RequestProductPurchaseAsync("product2");

                    if (licenseInformation.ProductLicenses["product2"].IsActive)
                    {
                        AdMediator.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        AdMediator.Visibility = Visibility.Visible;
                    }
                }
                catch (Exception)
                {
                    //rootPage.NotifyUser("Unable to buy " + productName + ".", NotifyType.ErrorMessage);
                }
            }
            else
            {
                //rootPage.NotifyUser("You already own " + productName + ".", NotifyType.ErrorMessage);
            }
        }
Esempio n. 5
0
        private async void PurchaseButton_Click(object sender, RoutedEventArgs e)
        {
            if (!AppLicenseInformation.ProductLicenses["MyInAppOfferToken"].IsActive)
            {
                try
                {
                    // The customer doesn't own this feature, so
                    // show the purchase dialog.

                    PurchaseResults results = await CurrentAppSimulator.RequestProductPurchaseAsync("RemoveAdsOffer");

                    //Check the license state to determine if the in-app purchase was successful.

                    if (results.Status == ProductPurchaseStatus.Succeeded)
                    {
                        AdMediator_40F141.Visibility = Visibility.Collapsed;
                        PurchaseButton.Visibility    = Visibility.Collapsed;
                    }
                }
                catch (Exception ex)
                {
                    // The in-app purchase was not completed because
                    // an error occurred.
                    throw ex;
                }
            }
            else
            {
                // The customer already owns this feature.
            }
        }
        private static async Task LoadConfigFile()
        {
            var storageFolder     = Package.Current.InstalledLocation;
            var storageFileResult = await storageFolder.GetFileAsync(@"trial-mode.xml");

            await CurrentAppSimulator.ReloadSimulatorAsync(storageFileResult);
        }
Esempio n. 7
0
        public async Task <InAppPurchaseHelper> Setup()
        {
            // license
            if (Simulate)
            {
#if DEBUG
                await SetupSimulation();

                m_License = CurrentAppSimulator.LicenseInformation;
                m_Listing = await CurrentAppSimulator.LoadListingInformationAsync();

                CanPurchase = true;
#endif
            }
            else
            {
                try
                {
                    m_License = CurrentApp.LicenseInformation;
                    m_Listing = await CurrentApp.LoadListingInformationAsync();

                    CanPurchase = true;
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("Setup/License [{0}, {1}, {2}]", this.Key, this.Simulate, e.Message));
                    CanPurchase = false;
                }
            }

            if (!CanPurchase)
            {
                return(this); // :(
            }
            try
            {
                // test setup
                m_License.LicenseChanged += () => { RaiseLicenseChanged(IsPurchased); };
                IReadOnlyDictionary <string, ProductLicense> _Licenses = m_License.ProductLicenses;
                if (!_Licenses.Any(x => x.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase)))
                {
                    throw new KeyNotFoundException(Key);
                }

                IReadOnlyDictionary <string, ProductListing> _Products = m_Listing.ProductListings;
                if (!_Products.Any(x => x.Key.Equals(Key, StringComparison.CurrentCultureIgnoreCase)))
                {
                    throw new KeyNotFoundException(Key);
                }

                // product
                m_Product = _Products[Key];
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Setup/Tests [{0}, {1}, {2}]", this.Key, this.Simulate, e.Message));
                CanPurchase = false;
            }
            return(this);
        }
Esempio n. 8
0
        async Task PurchaseFeatureAsync(string feature_name)
        {
            var feature = App.License.ProductLicenses[feature_name];

            if (App.ListingInfo.ProductListings.ContainsKey(feature_name))
            {
                var feature_listinginfo = App.ListingInfo.ProductListings[feature_name];
                if (feature.IsActive)
                {
                    MessageDialog dlg = new MessageDialog($"You already have {feature_listinginfo.Name}");
                    await dlg.ShowAsync();
                }
                else
                {
                    MessageDialog dlg = new MessageDialog($"{feature_listinginfo.FormattedPrice} costs {feature_listinginfo.Name}", $"Buy {feature_listinginfo.Name}?");
                    dlg.Commands.Add(new UICommand($"Buy {feature_listinginfo.Name}", async delegate(IUICommand c)
                    {
                        await CurrentAppSimulator.RequestProductPurchaseAsync(feature.ProductId);
                        //CurrentAppSimulator.
                    }));
                    dlg.Commands.Add(new UICommand("No thanks", cmd =>
                    {
                    }));
                    await dlg.ShowAsync();
                }
            }
            else
            {
                MessageDialog dlg = new MessageDialog($"{feature_name} does not exist in this application");
                await dlg.ShowAsync();
            }
        }
 /// <summary>
 /// Loads the app listing information asynchronously, returning features
 /// and products in the ProductListings collection that match all supplied keywords.
 /// </summary>
 /// <param name="keywords">
 /// The list of keywords by which to filter the ProductListings
 /// collection that is returned in the ListingInformation object.
 /// </param>
 /// <returns>
 /// The app's listing information, with ProductListings collection filtered by keywords. If the method fails, it
 /// returns an HRESULT error code. If no products or features are found that match all of the given keywords, the
 /// ProductListings collection will be empty.
 /// </returns>
 public static IAsyncOperation <ListingInformation> LoadListingInformationByKeywordsAsync(
     IEnumerable <string> keywords)
 {
     return(IsMockEnabled
         ? CurrentAppSimulator.LoadListingInformationByKeywordsAsync(keywords)
         : CurrentApp.LoadListingInformationByKeywordsAsync(keywords));
 }
Esempio n. 10
0
        internal async void PurchaseFullLicense()
        {
            MainPageViewModel mainPageVM = ServiceLocator.Current.GetInstance <MainPageViewModel>();

            licenseInformation = CurrentAppSimulator.LicenseInformation;
            if (licenseInformation.IsTrial)
            {
                try
                {
                    await CurrentAppSimulator.RequestAppPurchaseAsync(false);

                    if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                    {
                        mainPageVM.ResumeDownloadAction();
                    }
                    else
                    {
                        mainPageVM.CancelDownloadAction();
                    }
                }
                catch (Exception)
                {
                    mainPageVM.CancelDownloadAction();
                }
            }
        }
Esempio n. 11
0
        public async Task <ProductPurchaseStatus> BuyFullVersion(bool isPermanent)
        {
            try
            {
                ProductPurchaseStatus status;

                if (isPermanent)
                {
                    status = (await CurrentAppSimulator.RequestProductPurchaseAsync(StoreConstants.FullVersionVKSaverPernament)).Status;
                }
                else
                {
                    status = (await CurrentAppSimulator.RequestProductPurchaseAsync(StoreConstants.FullVersionVKSaver)).Status;
                }

                var dict = new Dictionary <string, string>(1);
                if (status == ProductPurchaseStatus.Succeeded)
                {
                    dict["Purchased"] = isPermanent ? FULL_VERSION_PERMANENT : FULL_VERSION_MONTH;
                    _metricaService.LogEvent(FULL_VERSION_PURCHASED_EVENT, JsonConvert.SerializeObject(dict));
                }
                else if (status == ProductPurchaseStatus.AlreadyPurchased)
                {
                    dict["AlreadyPurchased"] = isPermanent ? FULL_VERSION_PERMANENT : FULL_VERSION_MONTH;
                    _metricaService.LogEvent(FULL_VERSION_PURCHASED_EVENT, JsonConvert.SerializeObject(dict));
                }

                return(status);
            }
            catch (Exception ex)
            {
                _logService.LogException(ex);
                return(ProductPurchaseStatus.NotPurchased);
            }
        }
        private async Task LoadInAppPurchaseProxyFileAsync()
        {
            StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("data");

            StorageFile proxyFile = await proxyDataFolder.GetFileAsync("in-app-purchase.xml");

            licenseChangeHandler = new LicenseChangedEventHandler(InAppPurchaseRefreshScenario);
            CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

            // setup application upsell message
            try
            {
                ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync();

                var product1 = listing.ProductListings["product1"];
                var product2 = listing.ProductListings["product2"];
                Product1SellMessage.Text = "You can buy " + product1.Name + " for: " + product1.FormattedPrice + ".";
                Product2SellMessage.Text = "You can buy " + product2.Name + " for: " + product2.FormattedPrice + ".";
            }
            catch (Exception)
            {
                rootPage.NotifyUser("LoadListingInformationAsync API call failed", NotifyType.ErrorMessage);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Requests purchase of your app if it is in trial mode, returns an xml reciept if successful
        /// </summary>
        /// <param name="response">A callback containing the receipt</param>
        public static void PurchaseApp(Action <string> response)
        {
#if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0)
            if (_isTest)
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    string result = await CurrentAppSimulator.RequestAppPurchaseAsync(true);

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(result);
                        }
                    }, true);
                }, true);
            }
            else
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    string result = await CurrentApp.RequestAppPurchaseAsync(true);

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(result);
                        }
                    }, true);
                }, true);
            }
#endif
        }
Esempio n. 14
0
        /// <summary>
        /// Reports that your app has fullfilled the consumable product, the product cannot be purchased again until this is called
        /// </summary>
        /// <param name="id">The id of the product</param>
        /// <param name="transactionId">The transaction id</param>
        /// <param name="response">A callback indicating the result</param>
        public static void ReportConsumableProductFulfillment(string id, Guid transactionId, Action <WSAFulfillmentResult> response)
        {
#if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0)
            if (_isTest)
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(id, transactionId);

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(MapFulfillmentResult(result));
                        }
                    }, true);
                }, false);
            }
            else
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    FulfillmentResult result = await CurrentApp.ReportConsumableFulfillmentAsync(id, transactionId);

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(MapFulfillmentResult(result));
                        }
                    }, true);
                }, false);
            }
#endif
        }
Esempio n. 15
0
        private async void BuyAndFulfillProduct1Button_Click(object sender, RoutedEventArgs e)
        {
            Log("Buying Product 1...", NotifyType.StatusMessage);
            try
            {
                PurchaseResults purchaseResults = await CurrentAppSimulator.RequestProductPurchaseAsync("product1");

                switch (purchaseResults.Status)
                {
                case ProductPurchaseStatus.Succeeded:
                    GrantFeatureLocally("product1", purchaseResults.TransactionId);
                    FulfillProduct1("product1", purchaseResults.TransactionId);
                    break;

                case ProductPurchaseStatus.NotFulfilled:
                    if (!IsLocallyFulfilled("product1", purchaseResults.TransactionId))
                    {
                        GrantFeatureLocally("product1", purchaseResults.TransactionId);
                    }
                    FulfillProduct1("product1", purchaseResults.TransactionId);
                    break;

                case ProductPurchaseStatus.NotPurchased:
                    Log("Product 1 was not purchased.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                Log("Unable to buy Product 1.", NotifyType.ErrorMessage);
            }
        }
 /// <summary>
 /// Requests the purchase of an in-app product. Additionally, calling this method displays the UI that is used to complete
 /// the transaction via the Windows Store.
 /// </summary>
 /// <param name="productId">Specifies the id of the in-app product.</param>
 /// <param name="offerId">
 /// The specific in-app feature or content within the large purchase catalog represented on the
 /// Windows Store by the productId. This value correlates with the content your app is responsible for fulfilling. The
 /// Windows Store only uses this value to itemize the PurchaseResults.
 /// </param>
 /// <param name="displayProperties">
 /// The name of the app feature or content offer that is displayed to the user at time of
 /// purchase.
 /// </param>
 /// <returns>The results of the in-app product purchase request.</returns>
 public static IAsyncOperation <PurchaseResults> RequestProductPurchaseAsync(string productId, string offerId,
                                                                             ProductPurchaseDisplayProperties displayProperties)
 {
     return(IsMockEnabled
         ? CurrentAppSimulator.RequestProductPurchaseAsync(productId, offerId, displayProperties)
         : CurrentApp.RequestProductPurchaseAsync(productId, offerId, displayProperties));
 }
        /// <summary>
        /// Invoked when the user asks purchase the app.
        /// </summary>
        private async void PurchaseFullLicense()
        {
            LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;

            rootPage.NotifyUser("Buying the full license...", NotifyType.StatusMessage);
            if (licenseInformation.IsTrial)
            {
                try
                {
                    await CurrentAppSimulator.RequestAppPurchaseAsync(false);

                    if (!licenseInformation.IsTrial && licenseInformation.IsActive)
                    {
                        rootPage.NotifyUser("You successfully upgraded your app to the fully-licensed version.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("You still have a trial license for this app.", NotifyType.ErrorMessage);
                    }
                }
                catch (Exception)
                {
                    rootPage.NotifyUser("The upgrade transaction failed. You still have a trial license for this app.", NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("You already bought this app and have a fully-licensed version.", NotifyType.ErrorMessage);
            }
        }
Esempio n. 18
0
        public async Task <bool> BuyProduct(string FeatureName)
        {
            try
            {
#if DEBUG
                if (licenseInformation.IsTrial)
                {
                    await CurrentAppSimulator.RequestAppPurchaseAsync(false);
                }

                PurchaseResults Result = await CurrentAppSimulator.RequestProductPurchaseAsync(FeatureName);
#else
                PurchaseResults Result = await CurrentApp.RequestProductPurchaseAsync(FeatureName);
#endif

                //Reset status;
                _HasRemoveAds = null;

                //Check the license state to determine if the in-app purchase was successful.
                return(Result.Status == ProductPurchaseStatus.Succeeded || Result.Status == ProductPurchaseStatus.AlreadyPurchased);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private async void DoTapAction(StoreItem key)
        {
            if (!LicenseInformation.ProductLicenses[key.Code].IsActive)
            {
                try
                {
#if DEBUG
                    var result = await CurrentAppSimulator.RequestProductPurchaseAsync(key.Code);
#else
                    var result = await CurrentApp.RequestProductPurchaseAsync(key.Code);
#endif

                    CheckBuy();

                    CheckType();
                }
                catch (Exception e)
                {
                }
            }
            else
            {
                var item = AvailableProducts.Where(x => x.Code == key.Code).FirstOrDefault();
                if (item != null)
                {
                    item.Purchased = true;
                }
            }
        }
Esempio n. 20
0
        private async void FulfillPreviousPurchase(object sender, RoutedEventArgs e)
        {
            try
            {
                IReadOnlyList <UnfulfilledConsumable> consumables = await CurrentAppSimulator.GetUnfulfilledConsumablesAsync();

                string logMessage = "Number of unfulfilled consumables: " + consumables.Count;

                foreach (UnfulfilledConsumable consumable in consumables)
                {
                    logMessage += "\nProduct Id: " + consumable.ProductId + " Transaction Id: " + consumable.TransactionId;
                    // This is where you would grant the user their consumable content and call currentApp.reportConsumableFulfillment
                    // For demonstration purposes, we leave the purchase unfulfilled.
                    if (!IsLocallyFulfilled(consumable.TransactionId))
                    {
                        GrantFeatureLocally(consumable.TransactionId);
                    }
                    FulfillProduct(consumable.TransactionId);
                }
                //NotifyUser("product1 was fulfilled.You are now able to buy another one");
                //tb2.Text = logMessage.ToString();
            }
            catch (Exception)
            {
                //rootPage.NotifyUser("GetUnfulfilledConsumablesAsync API call failed", NotifyType.ErrorMessage);
            }
        }
Esempio n. 21
0
        public static void RequestAppPurchase(bool requireReceipt, Action <CallbackResponse <string> > OnAppPurchaseFinished)
        {
            string result             = String.Empty;
            bool   didPurchaseSucceed = false;

            Utils.RunOnWindowsUIThread(async() =>
            {
                try
                {
                    if (_isLicenseSimulationOn)
                    {
                        result = await CurrentAppSimulator.RequestAppPurchaseAsync(requireReceipt);
                        if (CurrentAppSimulator.LicenseInformation.IsActive && !CurrentAppSimulator.LicenseInformation.IsTrial)
                        {
                            didPurchaseSucceed = true;
                        }
                    }
                    else
                    {
                        result = await CurrentApp.RequestAppPurchaseAsync(requireReceipt);
                        if (CurrentApp.LicenseInformation.IsActive && !CurrentApp.LicenseInformation.IsTrial)
                        {
                            didPurchaseSucceed = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    DebugLog.Log(LogLevel.Error, "Error purchasing the app " + ex.ToString());
                    Utils.RunOnUnityAppThread(() =>
                    {
                        if (OnAppPurchaseFinished != null)
                        {
                            OnAppPurchaseFinished(
                                new CallbackResponse <string>
                            {
                                Status    = CallbackStatus.Failure,
                                Result    = null,
                                Exception = ex
                            });
                        }
                    });

                    return;
                }

                Utils.RunOnUnityAppThread(() =>
                {
                    if (OnAppPurchaseFinished != null)
                    {
                        OnAppPurchaseFinished(new CallbackResponse <string>
                        {
                            Status    = didPurchaseSucceed ? CallbackStatus.Success : CallbackStatus.Failure,
                            Result    = result,
                            Exception = null
                        });
                    }
                });
            });
        }
Esempio n. 22
0
        private async void Buy(object sender, RoutedEventArgs e)
        {
            PurchaseResults purchaseResults = await CurrentAppSimulator.RequestProductPurchaseAsync("product1");

            switch (purchaseResults.Status)
            {
            case ProductPurchaseStatus.Succeeded:
                //Local fulfillment
                //GrantFeatureLocally(purchaseResults.TransactionId);
                ////Reporting product fulfillment to the Store
                //FulfillProduct(purchaseResults.TransactionId);
                NotifyUser("You bought product1. Transaction Id: " + purchaseResults.TransactionId);
                break;

            case ProductPurchaseStatus.NotFulfilled:
                // First check for unfulfilled purchases and grant any unfulfilled purchases from an earlier transaction.
                // Once products are fulfilled pass the product ID and transaction ID to currentAppSimulator.reportConsumableFulfillment
                // To indicate local fulfillment to the Windows Store.
                //NotifyUser("You have an unfulfilled copy of " + info.nameRun.Text + ". Fulfill it before purchasing another one.");
                NotifyUser("You have an unfulfilled copy of product1.Fulfill it before purchasing another one.");
                break;

            case ProductPurchaseStatus.NotPurchased:
                NotifyUser("product1 was not purchased.");
                break;
            }
        }
Esempio n. 23
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            // Remove these lines of code before publishing!
            // The actual CurrentApp will create a WindowsStoreProxy.xml
            // in the package's \LocalState\Microsoft\Windows Store\ApiData
            // folder where it stores the actual purchases.
            // Here we're just giving it a fake version of that file
            // for testing.
            StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");

            StorageFile proxyFile = await proxyDataFolder.GetFileAsync("test.xml");

            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            // You may want to put this at the App level
            AppLicenseInformation = CurrentAppSimulator.LicenseInformation;

            if (AppLicenseInformation.ProductLicenses["RemoveAdsOffer"].IsActive)
            {
                // Customer can access this feature.
                AdMediator_40F141.Visibility = Visibility.Collapsed;
                PurchaseButton.Visibility    = Visibility.Collapsed;
            }
            else
            {
                // Customer can NOT access this feature.
                AdMediator_40F141.Visibility = Visibility.Visible;
                PurchaseButton.Visibility    = Visibility.Visible;
            }
        }
Esempio n. 24
0
        private async void BuyProduct1Button_Click(object sender, RoutedEventArgs e)
        {
            LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;

            if (!licenseInformation.ProductLicenses["product1"].IsActive)
            {
                rootPage.NotifyUser("Buying Product 1...", NotifyType.StatusMessage);
                try
                {
                    await CurrentAppSimulator.RequestProductPurchaseAsync("product1", false);

                    if (licenseInformation.ProductLicenses["product1"].IsActive)
                    {
                        rootPage.NotifyUser("You bought Product 1.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("", NotifyType.StatusMessage);
                    }
                }
                catch (Exception)
                {
                    rootPage.NotifyUser("Unable to buy Product 1.", NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("You already own Product 1.", NotifyType.ErrorMessage);
            }
        }
Esempio n. 25
0
        public static async Task <Boolean> Purchase()
        {
            try
            {
#if DEBUG
                await CurrentAppSimulator.RequestAppPurchaseAsync(false);
#else
                await CurrentApp.RequestAppPurchaseAsync(false);
#endif
                if (!IsTrial())
                {
                    ResourceLoader _res          = ResourceLoader.GetForCurrentView();
                    MessageDialog  messageDialog = new MessageDialog(_res.GetString("VersionFull"), _res.GetString("ThanksPurchase"));
                    messageDialog.Commands.Add(new UICommand("Ok", (command) => { }));
                    messageDialog.CancelCommandIndex  = 0;
                    messageDialog.DefaultCommandIndex = 0;
                    await messageDialog.ShowAsync();

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
        private async Task BuyProductAsync(string productId, string productName)
        {
            LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;

            if (!licenseInformation.ProductLicenses[productId].IsActive)
            {
                rootPage.NotifyUser("Buying " + productName + "...", NotifyType.StatusMessage);
                try
                {
                    await CurrentAppSimulator.RequestProductPurchaseAsync(productId);

                    if (licenseInformation.ProductLicenses[productId].IsActive)
                    {
                        rootPage.NotifyUser("You bought " + productName + ".", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser(productName + " was not purchased.", NotifyType.StatusMessage);
                    }
                }
                catch (Exception)
                {
                    rootPage.NotifyUser("Unable to buy " + productName + ".", NotifyType.ErrorMessage);
                }
            }
            else
            {
                rootPage.NotifyUser("You already own " + productName + ".", NotifyType.ErrorMessage);
            }
        }
Esempio n. 27
0
        private async void BuyButton_Click(object sender, RoutedEventArgs e)
        {
            var proxyFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");

            var proxyFile = await proxyFolder.GetFileAsync("WindowsStoreProxy.xml");

            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);


            try
            {
                var listing = await CurrentAppSimulator.LoadListingInformationAsync();

                var product = listing.ProductListings["product1"];

                var results = await CurrentAppSimulator.RequestProductPurchaseAsync("product1");

                if (results.Status == ProductPurchaseStatus.Succeeded)
                {
                    VKAppPlatform.Instance.ReportInAppPurchase(new VKAppPlatform.InAppPurchaseData(results.ReceiptXml, product.FormattedPrice));
                }
            }
            catch (Exception exc)
            {
                /* Handle exception */
            }
        }
Esempio n. 28
0
        internal async void GetPrice()
        {
            try
            {
#if DEBUG
                ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync();
#else
                ListingInformation listing = await CurrentApp.LoadListingInformationAsync();
#endif
                List <string> ps = new List <string>();
                foreach (var item in DonationPack)
                {
                    var product = listing.ProductListings[item];
                    ps.Add(product.FormattedPrice);
                }
                Price = ps.ToArray();

                licenseChangeHandler = new LicenseChangedEventHandler(licenseChangedEventHandler);
#if DEBUG
                CurrentAppSimulator.LicenseInformation.LicenseChanged += licenseChangeHandler;
#else
                CurrentApp.LicenseInformation.LicenseChanged += licenseChangeHandler;
#endif
            }
            catch (Exception)
            {
                Price = null;
            }
        }
Esempio n. 29
0
        public static async void LoadAddons()
        {
            StorageFolder proxyDataFolder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");

            StorageFile proxyFile = await proxyDataFolder.GetFileAsync("test.xml");

            await CurrentAppSimulator.ReloadSimulatorAsync(proxyFile);

            //TODO
            if (App.AppLicenseInformation.ProductLicenses[catsPackageToken].IsActive)
            {
                var collection = await CreateAddonCollectionAsync("Cats").ConfigureAwait(true);

                App.PurchaseCollections.Add(collection);
            }
            if (App.AppLicenseInformation.ProductLicenses[mountainsPackageToken].IsActive)
            {
                var collection = await CreateAddonCollectionAsync("Mountains").ConfigureAwait(true);

                App.PurchaseCollections.Add(collection);
            }
            if (App.AppLicenseInformation.ProductLicenses[spacePackageToken].IsActive)
            {
                var collection = await CreateAddonCollectionAsync("Space").ConfigureAwait(true);

                App.PurchaseCollections.Add(collection);
            }
            if (App.AppLicenseInformation.ProductLicenses[sunsetsPackageToken].IsActive)
            {
                var collection = await CreateAddonCollectionAsync("Sunsets").ConfigureAwait(true);

                App.PurchaseCollections.Add(collection);
            }
        }
        private async void BuyProduct2Button_Click(object sender, RoutedEventArgs e)
        {
            Log("Buying Product 2...", NotifyType.StatusMessage);
            try
            {
                PurchaseResults purchaseResults = await CurrentAppSimulator.RequestProductPurchaseAsync("product2");

                switch (purchaseResults.Status)
                {
                case ProductPurchaseStatus.Succeeded:
                    product2NumPurchases++;
                    product2TempTransactionId = purchaseResults.TransactionId;
                    Log("You bought product 2. Transaction Id: " + purchaseResults.TransactionId, NotifyType.StatusMessage);

                    // Normally you would grant the user their content here, and then call currentApp.reportConsumableFulfillment
                    break;

                case ProductPurchaseStatus.NotFulfilled:
                    product2TempTransactionId = purchaseResults.TransactionId;
                    Log("You have an unfulfilled copy of product 2. Hit \"Fulfill product 2\" before you can purchase a second copy.", NotifyType.StatusMessage);

                    // Normally you would grant the user their content here, and then call currentApp.reportConsumableFulfillment
                    break;

                case ProductPurchaseStatus.NotPurchased:
                    Log("Product 2 was not purchased.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                Log("Unable to buy Product 2.", NotifyType.ErrorMessage);
            }
        }