/// <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));
 }
        private async void PartlyCloudy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var            licenseInformation = CurrentAppSimulator.LicenseInformation.ProductLicenses;
                var            x = licenseInformation.Keys;
                ProductLicense product;
                //Fetching the two product ID's (By default, it's "1" and "2", and trying to call the purchase on the first one.
                foreach (string y in x)
                {
                    product = licenseInformation[y];
                    await CurrentAppSimulator.RequestProductPurchaseAsync(product.ProductId);

                    break;
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.Log(String.Format("Unable to purchase the feature.Exception: {0}", ex.Message));

                /* Error message: Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.ni.dll
                 *
                 * ex.Message "Error HRESULT E_FAIL has been returned from a call to a COM component." */
            }
        }
Esempio n. 3
0
        private async void DonationButton_Click(object sender, RoutedEventArgs e)
        {
            DonationButton.Visibility         = Visibility.Collapsed;
            DonationSuccessMessage.Visibility = Visibility.Visible;
            try
            {
                rootPage.ShowProgressRing();
#if DEBUG
                var result = await CurrentAppSimulator.RequestProductPurchaseAsync("ThoughtRecordDonation", true);
#else
                var result = await CurrentApp.RequestProductPurchaseAsync("ThoughtRecordDonation", true);
#endif
                //Check the license state to determine if the in-app purchase was successful.
                if ((Application.Current as App).LicenseInformation.ProductLicenses["ThoughtRecordDonation"].IsActive)
                {
                    DonationSuccessMessage.Text = "Thanks! :)";
                }
                else
                {
                    DonationSuccessMessage.Text = "The Donation could not be processed. Try again later.";
                }
            }
            catch (Exception)
            {
                // The in-app purchase was not completed because an error occurred.
                DonationSuccessMessage.Text = "An error occurred and the donation could not be processed. Try again later.";
            }
            rootPage.HideProgressRing();
        }
Esempio n. 4
0
        private async void Buy2(object sender, RoutedEventArgs e)
        {
            LicenseInformation licenseInformation = CurrentAppSimulator.LicenseInformation;

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

                    if (licenseInformation.ProductLicenses["product2"].IsActive)
                    {
                        //rootPage.NotifyUser("You bought " + productName + ".", NotifyType.StatusMessage);
                        tb2.Text = "You have bought Product2";
                    }
                    else
                    {
                        //rootPage.NotifyUser(productName + " was not purchased.", NotifyType.StatusMessage);
                        tb2.Text = "Product2 was not purchased";
                    }
                }
                catch (Exception)
                {
                    //rootPage.NotifyUser("Unable to buy " + productName + ".", NotifyType.ErrorMessage);
                }
            }
            else
            {
                //rootPage.NotifyUser("You already own " + productName + ".", NotifyType.ErrorMessage);
            }
        }
        async void Example1()
        {
            Guid product1TempTransactionId = new Guid();

            //<MakePurchaseRequest>
            PurchaseResults purchaseResults = await CurrentAppSimulator.RequestProductPurchaseAsync("product1");

            switch (purchaseResults.Status)
            {
            case ProductPurchaseStatus.Succeeded:
                product1TempTransactionId = purchaseResults.TransactionId;

                // Grant the user their purchase here, and then pass the product ID and transaction ID to
                // CurrentAppSimulator.ReportConsumableFulfillment to indicate local fulfillment to the
                // Windows Store.
                break;

            case ProductPurchaseStatus.NotFulfilled:
                product1TempTransactionId = purchaseResults.TransactionId;

                // 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.
                break;
            }
            //</MakePurchaseRequest>
        }
Esempio n. 6
0
        private async void BuyAndFulfillProduct1()
        {
            rootPage.NotifyUser("Buying Product 1...", NotifyType.StatusMessage);
            try
            {
                PurchaseResults purchaseResults = await CurrentAppSimulator.RequestProductPurchaseAsync("product1");

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

                case ProductPurchaseStatus.NotFulfilled:
                    // The purchase failed because we haven't confirmed fulfillment of a previous purchase.
                    // Fulfill it now.
                    if (!IsLocallyFulfilled(purchaseResults.TransactionId))
                    {
                        GrantFeatureLocally(purchaseResults.TransactionId);
                    }
                    FulfillProduct1(purchaseResults.TransactionId);
                    break;

                case ProductPurchaseStatus.NotPurchased:
                    rootPage.NotifyUser("Product 1 was not purchased.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                rootPage.NotifyUser("Unable to buy Product 1.", NotifyType.ErrorMessage);
            }
        }
        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. 8
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. 9
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. 10
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. 12
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);
            }
        }
        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);
            }
        }
Esempio n. 14
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);
            }
        }
        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. 16
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. 17
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();
            }
        }
Esempio n. 18
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);
            }
        }
Esempio n. 19
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 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. 21
0
        internal async Task TryPurchaseAsync(string donationPack)
        {
#if DEBUG
            await CurrentAppSimulator.RequestProductPurchaseAsync(donationPack);
#else
            await CurrentApp.RequestProductPurchaseAsync(donationPack);
#endif
        }
Esempio n. 22
0
        public async Task BuyIapAsync(object sender, RoutedEventArgs e)
        {
            string name = (sender as FrameworkElement).Name;

            // Send telemetry
            _analyticsService.TrackEvent("StartBuyIAP", new Dictionary <string, string> {
                { "iapName", name }
            });

#if DEBUG
            // Use simulator info
            var licenseInformation = CurrentAppSimulator.LicenseInformation;

            // Buy IAP
            var requestPurchase = await CurrentAppSimulator.RequestProductPurchaseAsync(name);
#else
            // Use release licensing info
            var licenseInformation = CurrentApp.LicenseInformation;

            // Buy IAP
            var requestPurchase = await CurrentApp.RequestProductPurchaseAsync(name);
#endif

            var productLicense = licenseInformation.ProductLicenses[name];
            if (productLicense != null && productLicense.IsActive)
            {
                // Show toast notification (thanks to support us)
                _toastNotificationService.SendTitleAndText(_resourceLoader.GetString("ThankYou"), _resourceLoader.GetString("ThankYouToSupportUs"), "purchase");

                // Save buyed IAP
                if (name == "theWord")
                {
                    IapBuyed.Word++;
                }
                if (name == "thePage")
                {
                    IapBuyed.Page++;
                }
                if (name == "theBook")
                {
                    IapBuyed.Book++;
                }

                UpdateUI();

                _storageService.Save(StorageConstants.IapBuyed, IapBuyed);

                // Send telemetry
                _analyticsService.TrackEvent("SuccessBuyIAP", new Dictionary <string, string> {
                    { "iapName", name }
                });
            }
            else
            {
                // Show toast notification (something going wrong)
                _toastNotificationService.SendTitleAndText(_resourceLoader.GetString("PurchaseFailed"), _resourceLoader.GetString("PurchaseFailedExtended"), "purchase");
            }
        }
Esempio n. 23
0
        private async void SwitchThemeMethod()
        {
            if (_hasPayed == false)
            {
                var dialog = new MessageDialog("夜晚刷知乎会损害您的视力健康,请付费使用黑暗模式。");
                dialog.Title = "ZhiHu Pro 温馨提示";
                dialog.Commands.Add(new UICommand()
                {
                    Label = "现在购买", Id = 0
                });
                dialog.Commands.Add(new UICommand()
                {
                    Label = "暂不购买", Id = 1
                });

                var dialogRslt = await dialog.ShowAsync();

                if ((Int32)dialogRslt.Id == 0)
                {
                    try
                    {
#if DEBUG
                        await CurrentAppSimulator.RequestProductPurchaseAsync("NightModeIAP");
#else
                        await CurrentApp.RequestProductPurchaseAsync("NightModeIAP");
#endif
                        CheckLicenseMethod();

                        if (_hasPayed)
                        {
                            ToasteIndicator.Instance.Show("提示", "购买已成功,黑暗模式已解锁!", null, 5);
                        }
                        else
                        {
                            ToasteIndicator.Instance.Show("提示", "购买出现问题,黑暗模式无法解锁!", null, 5);
                        }
                    }
                    catch (Exception)
                    {
                        // The in-app puchase was not completed because an error occurred.
                    }
                }
                RaisePropertyChanged(() => NightModeOn);
                return;
            }

            if (NightModeOn == false)
            {
                NightModeOn = true;
                Theme.Instance.TurnDark();
            }
            else
            {
                NightModeOn = false;
                Theme.Instance.TurnLight();
            }
        }
Esempio n. 24
0
        public async static Task <bool> LicenseRequestDirectAsync(string productKey, bool InternetEnabled)
        {
            bool IsSuccess = false;

            if (!licenseInformation.ProductLicenses[productKey].IsActive)
            {
                if (NetworkInterface.GetIsNetworkAvailable() == InternetEnabled)
                {
                    try
                    {
                        if (!licenseInformation.ProductLicenses[productKey].IsActive)
                        {
#if DEBUG
                            await CurrentAppSimulator.RequestProductPurchaseAsync(productKey);
#else
                            var result = await CurrentApp.RequestProductPurchaseAsync(productKey);
#endif

                            if (licenseInformation.ProductLicenses[productKey].IsActive)
                            {
                                HelperUWP.Reporting.DisplayMessage("Product Purchased Successfully." + HelperUWP.Reporting.AppName, "Successfully Purchased");
                                IsSuccess = true;
                            }
                            else
                            {
                                HelperUWP.Reporting.DisplayMessage("Product key was not purchased" + HelperUWP.Reporting.AppName + " Please restart app and try again" + " -> UpradePage");
                                IsSuccess = false;
                            }
                        }
                        else
                        {
                            Reporting.DisplayMessage("Product already purchased");
                            IsSuccess = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        HelperUWP.Reporting.DisplayMessage(ex.Message + "Product key was not purchased" + HelperUWP.Reporting.AppName + " Please restart app and try again" + "->UpradePage");
                        IsSuccess = false;
                    }
                }
                else
                {
                    HelperUWP.Reporting.NoConnections();
                }
            }
            else
            {
                IsSuccess = true;
            }



            return(IsSuccess);
        }
Esempio n. 25
0
 private IAsyncOperation <PurchaseResults> RequestProductPurchaseAsync(string productId)
 {
     if (_useSimulator)
     {
         return(CurrentAppSimulator.RequestProductPurchaseAsync(productId));
     }
     else
     {
         return(CurrentApp.RequestProductPurchaseAsync(productId));
     }
 }
Esempio n. 26
0
        public async Task <bool> BuyInAppItem(string appID)
        {
                        #if DEBUG
            await CurrentAppSimulator.RequestProductPurchaseAsync(appID, false);

            return(CurrentAppSimulator.LicenseInformation.ProductLicenses[appID].IsActive);
                        #else
            await CurrentApp.RequestProductPurchaseAsync(appID, false);

            return(CurrentApp.LicenseInformation.ProductLicenses[appID].IsActive);
                        #endif
        }
Esempio n. 27
0
        /// <summary>
        /// Purchase a product
        /// </summary>
        /// <param name="id">The products id</param>
        /// <param name="response">A callback indicating if the action was successful</param>
        public static void PurchaseProduct(string id, Action <WSAPurchaseResult> response)
        {
#if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0)
            if (_isTest)
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    PurchaseResults purchaseResults = await CurrentAppSimulator.RequestProductPurchaseAsync(id);

                    WSAPurchaseResult result = new WSAPurchaseResult()
                    {
                        OfferId       = purchaseResults.OfferId,
                        ReceiptXml    = purchaseResults.ReceiptXml,
                        Status        = MapPurchaseResult(purchaseResults.Status),
                        TransactionId = purchaseResults.TransactionId
                    };

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(result);
                        }
                    }, true);
                }, false);
            }
            else
            {
                UnityEngine.WSA.Application.InvokeOnUIThread(async() =>
                {
                    PurchaseResults purchaseResults = await CurrentApp.RequestProductPurchaseAsync(id);

                    WSAPurchaseResult result = new WSAPurchaseResult()
                    {
                        OfferId       = purchaseResults.OfferId,
                        ReceiptXml    = purchaseResults.ReceiptXml,
                        Status        = MapPurchaseResult(purchaseResults.Status),
                        TransactionId = purchaseResults.TransactionId
                    };

                    UnityEngine.WSA.Application.InvokeOnAppThread(() =>
                    {
                        if (response != null)
                        {
                            response(result);
                        }
                    }, true);
                }, false);
            }
#endif
        }
Esempio n. 28
0
        private async void shield2_Click(object sender, RoutedEventArgs e)
        {
            var listing = await CurrentAppSimulator.LoadListingInformationAsync();

            listing.ToString();
            // LicenseInformation listing = await CurrentApp.LoadListingInformationAsync();
            var superweapon =
                listing.ProductListings.FirstOrDefault(p => p.Value.ProductId == "1");
            String message1 = superweapon.Value.Name;

            // var dialog = new MessageDialog(listing.ToString());
            //await dialog.ShowAsync();
            // CurrentApp.AppId.ToString();
            try
            {
                if (CurrentAppSimulator.LicenseInformation.ProductLicenses["1"].IsActive)
                {
                    PurchaseResults result = await CurrentAppSimulator.RequestProductPurchaseAsync("1");

                    var dialog1 = new MessageDialog("you buy super shield");
                    await dialog1.ShowAsync();
                }
                else
                {
                    try {
                        //  var receipt = await CurrentApp.RequestProductPurchaseAsync("shield", false);
                        PurchaseResults receipt = await CurrentAppSimulator.RequestProductPurchaseAsync("shield");

                        message.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        message.Text       = CurrentApp.AppId.ToString();

                        var dialo2 = new MessageDialog(message.Text);
                        await dialo2.ShowAsync();
                    }
                    catch (Exception ex)
                    {
                        String message = ex.ToString();
                        //  var dialog3 = new MessageDialog(message);
                        //  await dialog3.ShowAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                String message = ex.ToString();
                // var dialog3 = new MessageDialog(message);
                //  await dialog3.ShowAsync();
            }
            //MessageBox.Show(sb.ToString(), "List all products", MessageBoxButton.OK);
        }
Esempio n. 29
0
 public async Task RequestAsync(InappPurchaseItem item)
 {
     try
     {
         #if DEBUG
         await CurrentAppSimulator.RequestProductPurchaseAsync(item.Id).AsTask().ConfigureAwait(false);
         #else
         await CurrentApp.RequestProductPurchaseAsync(item.Id).AsTask().ConfigureAwait(false);
         #endif
     }
     catch (Exception)
     {
     }
 }
    public async Task <bool> PurchaseProductAsync(string productId)
    {
        try
        {
            var purchase = await CurrentAppSimulator.RequestProductPurchaseAsync(productId);

            return(purchase.Status == ProductPurchaseStatus.Succeeded || purchase.Status == ProductPurchaseStatus.AlreadyPurchased);
        }
        catch (Exception)
        {
            // The purchase did not complete because an error occurred.
            return(false);
        }
    }