private async void PurchaseAddon(string storeId)
        {
            try
            {
                PurchaseResults purchaseResults = await CurrentApp.RequestProductPurchaseAsync(storeId);

                switch (purchaseResults.Status)
                {
                case ProductPurchaseStatus.Succeeded:
                    FulfillProduct(storeId, purchaseResults.TransactionId);
                    break;

                case ProductPurchaseStatus.NotFulfilled:
                    FulfillProduct(storeId, purchaseResults.TransactionId);
                    break;

                case ProductPurchaseStatus.NotPurchased:
                    textBlockPurchase.Text = "Product was not purchased.";
                    break;
                }
            }
            catch
            {
                textBlockPurchase.Text = "Unable to buy product";
            }
        }
Пример #2
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);
            }
        }
        public async Task UpgradeToPremium()
        {
            MessageDialog messageDialog;

            try
            {
                //PurchaseResults results = await CurrentAppSimulator.RequestProductPurchaseAsync("premium_user");
                PurchaseResults results = await CurrentApp.RequestProductPurchaseAsync("premium_user");

                //Check the license state to determine if the in-app purchase was successful.
                if (PBAApplication.getInstance().IsPremiumUser())
                {
                    messageDialog  = new MessageDialog("Thank you! Please restart the app for changes to take efffect.");
                    VisibilityMode = Visibility.Collapsed;
                    CurrentLicense = "You have already upgraded to premium service";
                }
                else
                {
                    messageDialog = new MessageDialog("Some error occured during purchase. Please try again.");
                }
            }
            catch (Exception ex)
            {
                // The in-app purchase was not completed because an error occurred.
                messageDialog = new MessageDialog("Some exception occured during purchase. Please try again.");
            }

            await messageDialog.ShowAsync();
        }
Пример #4
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;
            }
        }
Пример #5
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);
            }
        }
        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>
        }
Пример #7
0
 public static void RequestProductPurchase(string productId, Action <InAppProductPurchaseResult> callback)
 {
     if (callback == null)
     {
         return;
     }
     Execute.ExecuteOnUIThread(async delegate
     {
         InAppProductPurchaseResult inAppProductPurchaseResult = new InAppProductPurchaseResult
         {
             Status = InAppProductPurchaseStatus.Cancelled
         };
         try
         {
             productId = InAppPurchaseService.ToInAppProductId(productId);
             PurchaseResults purchaseResults = await CurrentApp.RequestProductPurchaseAsync(productId);
             if (purchaseResults != null)
             {
                 inAppProductPurchaseResult.ReceiptXml    = purchaseResults.ReceiptXml;
                 inAppProductPurchaseResult.TransactionId = purchaseResults.TransactionId;
                 if (!string.IsNullOrEmpty(purchaseResults.ReceiptXml))
                 {
                     inAppProductPurchaseResult.Status = InAppProductPurchaseStatus.Purchased;
                 }
             }
         }
         catch
         {
             inAppProductPurchaseResult.Status = InAppProductPurchaseStatus.Error;
         }
         callback.Invoke(inAppProductPurchaseResult);
     });
 }
Пример #8
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);
            }
        }
Пример #9
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.
            }
        }
Пример #10
0
        private async void donateButton_Click(object sender, RoutedEventArgs e)
        {
            PurchaseResults purchaseResults = await CurrentApp.RequestProductPurchaseAsync(ProductKey);

            switch (purchaseResults.Status)
            {
            case ProductPurchaseStatus.Succeeded:
                int count = UpdateAndGetDonationCount();
                await CurrentApp.ReportConsumableFulfillmentAsync(ProductKey, purchaseResults.TransactionId);

                MessageDialog msgDialog;
                if (count > 1)
                {
                    msgDialog = new MessageDialog(string.Format("这已经是您的第{0}次打赏了,真是万分感谢!"));
                }
                else
                {
                    msgDialog = new MessageDialog("感谢您的打赏!您随时可以再次打赏哟!");
                }
                await msgDialog.ShowAsync();

                break;

            case ProductPurchaseStatus.NotFulfilled:
                await CurrentApp.ReportConsumableFulfillmentAsync(ProductKey, purchaseResults.TransactionId);

                msgDialog = new MessageDialog
                                ("不好意思,您上次的打赏似乎出了点问题,但现在已经解决了。您现在可以再次打赏了。");
                await msgDialog.ShowAsync();

                break;
            }
        }
        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);
            }
        }
Пример #12
0
        private async void OnDonateButtonClick(object sender, RoutedEventArgs args)
        {
            using (ProgressRingViewer.Show()) {
                MessageDialog dialog = new MessageDialog("");
                try {
                    ListingInformation info = await CurrentApp.LoadListingInformationAsync();

                    ProductListing donation;
                    if (info.ProductListings.TryGetValue("donation", out donation))
                    {
                        if (await FulfillDonation())
                        {
                            PurchaseResults purchaseResult =
                                await CurrentApp.RequestProductPurchaseAsync(donation.ProductId);

                            if (purchaseResult.Status == ProductPurchaseStatus.Succeeded)
                            {
                                dialog.Content = ResourceLoader.GetForCurrentView().GetString("thanksForDonation") +
                                                 "\n" + ResourceLoader.GetForCurrentView().GetString("youCanRate");
                            }
                            else if (purchaseResult.Status == ProductPurchaseStatus.NotPurchased)
                            {
                                dialog.Content =
                                    ResourceLoader.GetForCurrentView().GetString("anywayThanksForUsingApp") +
                                    "\n" + ResourceLoader.GetForCurrentView().GetString("youCanRate");
                            }
                            else
                            {
                                dialog.Content = ResourceLoader.GetForCurrentView().GetString("errorOcurred") +
                                                 "\n" +
                                                 ResourceLoader.GetForCurrentView()
                                                 .GetString("thanksAnywayTryAgainOrRate");
                            }
                        }
                        else
                        {
                            dialog.Content =
                                ResourceLoader.GetForCurrentView().GetString("errorOcurredDonationPendingOrServerError") +
                                "\n" + ResourceLoader.GetForCurrentView().GetString("thanksAnywayTryAgainOrRate");
                        }
                    }
                    else
                    {
                        dialog.Content = ResourceLoader.GetForCurrentView().GetString("noActiveDonations") +
                                         "\n" + ResourceLoader.GetForCurrentView().GetString("youCanRate");
                    }
                } catch {
                    dialog.Content = ResourceLoader.GetForCurrentView().GetString("errorOcurred") +
                                     "\n" + ResourceLoader.GetForCurrentView().GetString("thanksAnywayTryAgainOrRate");
                }

                await dialog.ShowAsync();
            }
        }
        public void NonexistentItemIdReturnsItemNotFound()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(true);

            // Act
            PurchaseResults result = mocks.controller.Post(NONEXISTENT_ITEM);

            // Assert
            Assert.AreEqual(PurchaseResults.ItemNotFound, result, "API should have reported item not found.");
        }
        public void PurchasingOutOfStockItemReturnsOutOfStock()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(true);

            // Act
            PurchaseResults result = mocks.controller.Post(OUT_OF_STOCK_ITEM);

            // Assert
            Assert.AreEqual(PurchaseResults.OutOfStock, result, "API should have reported out of stock item.");
        }
        public void PurchasingInStockItemRequestsShipment()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(true);

            // Act
            PurchaseResults result = mocks.controller.Post(IN_STOCK_ITEM);

            // Assert
            Assert.AreEqual(1, mocks.shipping.getOrders().Count, "Order should have been sent to the shipping service.");
            Assert.AreEqual(IN_STOCK_ITEM, mocks.shipping.getOrders()[0].Item1, string.Format("We should have ordered item {0} instead of item {1}", IN_STOCK_ITEM, mocks.shipping.getOrders()[0].Item1));
        }
Пример #16
0
        public async void Donate(string productId)
        {
            string title = null;
            string msg   = null;

            try
            {
                PurchaseResults purchaseResults = await IAPs.RequestProductPurchaseAsync(productId);

                switch (purchaseResults.Status)
                {
                case ProductPurchaseStatus.Succeeded:
                    //GrantFeatureLocally(purchaseResults.TransactionId);
                    FulfillProduct(productId, 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);
                    //}
                    FulfillProduct(productId, purchaseResults.TransactionId);
                    break;

                case ProductPurchaseStatus.NotPurchased:
                    //rootPage.NotifyUser("Product 1 was not purchased.", NotifyType.StatusMessage);
                    title = "IAPs/Purchase/Failed/Title";
                    msg   = "IAPs/Purchase/Failed/Content";
                    break;
                }
            }
            catch (Exception)
            {
                //rootPage.NotifyUser("Unable to buy Product 1.", NotifyType.ErrorMessage);
                title = "IAPs/Purchase/Failed/Title";
                msg   = "IAPs/Purchase/Failed/Content";
            }

            if (title != null && msg != null)
            {
                ResourceLoader resource = ResourceLoader.GetForCurrentView();
                var            dlg      = DialogHelper.GetSimpleContentDialog(
                    resource.GetString(title),
                    resource.GetString(msg),
                    resource.GetString("Button/Ok/Content"));
                await dlg.ShowAsync();

                App.ContentDlgOp = null;
            }
        }
        private async void FulfillProduct(string productId, PurchaseResults purchaseResults)
        {
            string itemDescription      = product1ListingName + BuildOfferStringForDisplay(purchaseResults.OfferId);
            string purchaseStringSimple = "You bought " + itemDescription + ".";

            if (purchaseResults.Status == ProductPurchaseStatus.NotFulfilled)
            {
                purchaseStringSimple = "You already purchased " + itemDescription + ".";
            }

            try
            {
                FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, purchaseResults.TransactionId);

                switch (result)
                {
                case FulfillmentResult.Succeeded:
                    if (purchaseResults.Status == ProductPurchaseStatus.NotFulfilled)
                    {
                        rootPage.NotifyUser("You already purchased " + itemDescription + " and it was just fulfilled.", NotifyType.StatusMessage);
                    }
                    else
                    {
                        rootPage.NotifyUser("You bought and fulfilled " + itemDescription, NotifyType.StatusMessage);
                    }
                    break;

                case FulfillmentResult.NothingToFulfill:
                    rootPage.NotifyUser("There is no purchased product 1 to fulfill with that transaction id.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchasePending:
                    rootPage.NotifyUser(purchaseStringSimple + " The purchase is pending so we cannot fulfill the product.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchaseReverted:
                    rootPage.NotifyUser(purchaseStringSimple + " But your purchase has been reverted.", NotifyType.StatusMessage);
                    // Since the user's purchase was revoked, they got their money back.
                    // You may want to revoke the user's access to the consumable content that was granted.
                    break;

                case FulfillmentResult.ServerError:
                    rootPage.NotifyUser(purchaseStringSimple + " There was an error when fulfilling.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                rootPage.NotifyUser(purchaseStringSimple + " There was an error when fulfilling.", NotifyType.ErrorMessage);
            }
        }
Пример #18
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
        }
        public void PurchasingInStockItemLogsPurchase()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(true);

            // Act
            PurchaseResults result = mocks.controller.Post(IN_STOCK_ITEM);

            // Assert
            List <string> logEntries = mocks.logging.GetLogEntries();

            Assert.AreEqual(1, logEntries.Count, "Purchase should have been logged.");
            Assert.AreNotEqual(-1, logEntries[0].IndexOf("Item 1 purchased by "), "Logging should indicate successful purchase.");
        }
Пример #20
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);
        }
        public void PurchasingOutOfStockItemLogsAttemptedPurchaseOfOutOfStockItem()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(true);

            // Act
            PurchaseResults result = mocks.controller.Post(OUT_OF_STOCK_ITEM);

            // Assert
            List <string> logEntries = mocks.logging.GetLogEntries();

            Assert.AreEqual(1, logEntries.Count, "Attempted purchase should have been logged.");
            Assert.AreNotEqual(-1, logEntries[0].IndexOf(" attempted to purchase item 2, which is out of stock."), "Logging should indicate attempt at purchasing an out of stock item.");
        }
        public void NonexistentItemIdLogsRequestForNonexistentItem()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(true);

            // Act
            PurchaseResults result = mocks.controller.Post(NONEXISTENT_ITEM);

            // Assert
            List <string> logEntries = mocks.logging.GetLogEntries();

            Assert.AreEqual(1, logEntries.Count, "Attempted purchase should have been logged.");
            Assert.AreNotEqual(-1, logEntries[0].IndexOf(" attempted to purchase item 314, which doesn't exist."), "Logging should indicate attempt at purchasing a nonexistent item.");
        }
        public void FailedPaymentMethodLogsAttemptedPurchaseWithFailedPayment()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(false);
            int beginningQuantity        = mocks.inventory.GetItemQuantity(IN_STOCK_ITEM);

            // Act
            PurchaseResults result = mocks.controller.Post(IN_STOCK_ITEM);

            // Assert
            List <string> logEntries = mocks.logging.GetLogEntries();

            Assert.AreEqual(1, logEntries.Count, "Attempted purchase should have been logged.");
            Assert.AreNotEqual(-1, logEntries[0].IndexOf(" attempted to purchase item 1, but payment failed."), "Logging should indicate failed payment.");
        }
Пример #24
0
 private IAsyncOperation <bool> GrantFeatureInternal(PurchaseResults purchaseResults, string token)
 {
     return(AsyncInfo.Run(async cancellationToken =>
     {
         try
         {
             var result = await ApiService.Instance.AddCredits(purchaseResults.TransactionId, purchaseResults.ReceiptXml, token);
             return result.IsSuccessStatusCode;
         }
         catch
         {
             return false;
         }
     }));
 }
        public void PurchasingInStockItemDecreasesQuantity()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(true);
            int beginningQuantity        = mocks.inventory.GetItemQuantity(IN_STOCK_ITEM);

            // Act
            PurchaseResults result = mocks.controller.Post(IN_STOCK_ITEM);

            // Assert
            int expectedValue = beginningQuantity - 1;
            int actualValue   = mocks.inventory.GetItemQuantity(IN_STOCK_ITEM);

            Assert.AreEqual(result, PurchaseResults.ItemPurchased, "Item should have been successfully purchased.");
            Assert.AreEqual(expectedValue, actualValue, string.Format("Expected {0} of item {1} instead of {2}. Purchasing an item should decrement the quantity by one.", expectedValue, IN_STOCK_ITEM, actualValue));
        }
        public void FailedPaymentMethodDoesNotDecreaseQuantity()
        {
            // Arrange
            PurchaseMockCollection mocks = CreateController(false);
            int beginningQuantity        = mocks.inventory.GetItemQuantity(IN_STOCK_ITEM);

            // Act
            PurchaseResults result = mocks.controller.Post(IN_STOCK_ITEM);

            // Assert
            int expectedValue = beginningQuantity - 1;
            int actualValue   = mocks.inventory.GetItemQuantity(IN_STOCK_ITEM);

            Assert.AreEqual(PurchaseResults.PaymentFailed, result, "API should have reported payment failure.");
            Assert.AreEqual(beginningQuantity, actualValue, string.Format("Expected {0} of item {1} instead of {2}. Failed payment should not affect the quantity.", expectedValue, IN_STOCK_ITEM, actualValue));
        }
Пример #27
0
        //send request to remove ads
        public static async Task Purchased()
        {
            if (!MainPage.AppLicenseInformation.ProductLicenses["RemoveBannerAdOffer"].IsActive)
            {
                try
                {
                    // The customer doesn't own this feature, so
                    // show the purchase dialog.

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

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

                    if (results.Status == ProductPurchaseStatus.Succeeded)
                    {
                        AdManager.IfPurchaseCompleted = true;
                        AdManager.IfPurchaseRequested = false;

                        //    RemoveAd();
                        // ADGRid.Visibility = Visibility.Collapsed;
                        //   MyBannerAd.Visibility = Visibility.Collapsed;
                        /// PurchaseButton.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        AdManager.IfPurchaseRequested = false;
                        AdManager.IfPurchaseCompleted = false;
                    }
                }
                catch (Exception ex)
                {
                    AdManager.IfPurchaseRequested = false;
                    AdManager.IfPurchaseCompleted = false;
                    // The in-app purchase was not completed because
                    // an error occurred.
                    throw ex;
                }
            }
            else
            {
                AdManager.IfPurchaseCompleted = true;
                AdManager.IfPurchaseRequested = false;

                // The customer already owns this feature.
            }
        }
Пример #28
0
        private async void MakePurchase(object sender, RoutedEventArgs e)
        {
            LicenseInformation licenseInformation = CurrentApp.LicenseInformation;
            string             addon = (sender as Button).Tag.ToString();

            if (!licenseInformation.ProductLicenses[addon].IsActive)
            {
                try
                {
                    // The customer doesn't own this feature, so
                    // show the purchase dialog.
                    PurchaseResults purchase = await CurrentApp.RequestProductPurchaseAsync(addon);

                    if (licenseInformation.ProductLicenses[addon].IsActive)
                    {
                        MessageDialog msg = new MessageDialog(App.GetString("/Dialogs/AddOnPurchased"));
                        await msg.ShowAsync();
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog(App.GetString("/Dialogs/AddOnNotPurchased"));
                        await msg.ShowAsync();
                    }

                    licenseInformation = CurrentApp.LicenseInformation;

                    if (licenseInformation.ProductLicenses[addon].IsActive)
                    {
                        BuyAdRemovalButton.Visibility = Visibility.Collapsed;
                        App.ShowAds = false;
                    }
                    //Check the license state to determine if the in-app purchase was successful.
                }
                catch (Exception)
                {
                    MessageDialog msg = new MessageDialog(App.GetString("/Dialogs/AddOnError"));
                    await msg.ShowAsync();
                }
            }
            else
            {
                // The customer already owns this feature.
            }
        }
Пример #29
0
        public static async Task <ProductPurchaseStatus> buyNoAds()
        {
            //ListingInformation information = await CurrentApp.LoadListingInformationAsync();
            //List<ProductListing> products = information.ProductListings.Values.ToList();
            //System.Diagnostics.Debug.WriteLine(information.ProductListings.Count);
            //foreach (ProductListing prod in products)
            //{
            //    System.Diagnostics.Debug.WriteLine("Prodotto: " + prod.ProductId + " Nome: " + prod.Name);
            //}
            //ProductListing product = products.Single(x => x.ProductId == prodotto);
            //System.Diagnostics.Debug.WriteLine(product.Name);
#if DEBUG
            PurchaseResults result = await CurrentAppSimulator.RequestProductPurchaseAsync(prodotto);
#else
            PurchaseResults result = await CurrentApp.RequestProductPurchaseAsync(prodotto);
#endif
            return(result.Status);
            //return ProductPurchaseStatus.NotPurchased;
        }
Пример #30
0
        private async void shield1_Click(object sender, RoutedEventArgs e)
        {
            // var result = await CurrentApp.GetProductReceiptAsync("shield");
            try {
                //await Windows.System.Launcher.LaunchUriAsync(
                //new Uri("ms-windows-store:reviewapp?appid=B5EB66C4-C37A-4DAF-9280-CA85810D0C52"));
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    async() =>
                {
                    try {
                        PurchaseResults result = await CurrentApp.RequestProductPurchaseAsync("shield");

                        //  var result = await CurrentApp.LoadListingInformationAsync();
                        var hasPaid = CurrentApp.LicenseInformation.ProductLicenses[("shield")].IsActive;
                        switch (result.Status)
                        {
                        case ProductPurchaseStatus.Succeeded:
                            await CurrentApp.ReportConsumableFulfillmentAsync("shield", result.TransactionId);
                            //  OnPurchaseDismissed("1");
                            break;

                        case ProductPurchaseStatus.NotFulfilled:
                            //   InAppPurchaseManager.Instance.CheckUnfulfilledConsumables();
                            await CurrentApp.ReportConsumableFulfillmentAsync("shield", result.TransactionId);
                            //   OnPurchaseDismissed("1");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        String message = ex.ToString();
                        var dialog1    = new MessageDialog(message);
                        await dialog1.ShowAsync();
                    }
                });
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
        private async void FulfillProduct1(string productId, PurchaseResults purchaseResults)
        {
            string displayPropertiesName = DisplayPropertiesNameTextBox.Text;
            if (String.IsNullOrEmpty(displayPropertiesName))
            {
                displayPropertiesName = product1ListingName;
            }
            string offerIdMsg = " with offer id " + purchaseResults.OfferId;
            if (String.IsNullOrEmpty(purchaseResults.OfferId))
            {
                offerIdMsg = " with no offer id";
            }
            string purchaseStringSimple = "You bought product 1.";
            if (purchaseResults.Status == ProductPurchaseStatus.NotFulfilled)
            {
                purchaseStringSimple = "You already purchased product 1.";
            }

            try
            {
                FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, purchaseResults.TransactionId);
                switch (result)
                {
                    case FulfillmentResult.Succeeded:
                        if (purchaseResults.Status == ProductPurchaseStatus.NotFulfilled)
                        {
                            Log("You already purchased " + product1ListingName + offerIdMsg + " and it was just fulfilled.", NotifyType.StatusMessage);
                        }
                        else
                        {
                            Log("You bought and fulfilled " + displayPropertiesName + offerIdMsg, NotifyType.StatusMessage);
                        }
                        break;
                    case FulfillmentResult.NothingToFulfill:
                        Log("There is no purchased product 1 to fulfill with that transaction id.", NotifyType.StatusMessage);
                        break;
                    case FulfillmentResult.PurchasePending:
                        Log(purchaseStringSimple + " The purchase is pending so we cannot fulfill the product.", NotifyType.StatusMessage);
                        break;
                    case FulfillmentResult.PurchaseReverted:
                        Log(purchaseStringSimple + " But your purchase has been reverted.", NotifyType.StatusMessage);
                        // Since the user's purchase was revoked, they got their money back.
                        // You may want to revoke the user's access to the consumable content that was granted.
                        break;
                    case FulfillmentResult.ServerError:
                        Log(purchaseStringSimple + " There was an error when fulfilling.", NotifyType.StatusMessage);
                        break;
                }
            }
            catch (Exception)
            {
                Log(purchaseStringSimple + " There was an error when fulfilling.", NotifyType.ErrorMessage);
            }
        }
        private async void FulfillProduct(string productId, PurchaseResults purchaseResults)
        {
            string itemDescription = product1ListingName + BuildOfferStringForDisplay(purchaseResults.OfferId);
            string purchaseStringSimple = "You bought " + itemDescription + ".";
            if (purchaseResults.Status == ProductPurchaseStatus.NotFulfilled)
            {
                purchaseStringSimple = "You already purchased " + itemDescription + ".";
            }

            try
            {
                FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, purchaseResults.TransactionId);
                switch (result)
                {
                    case FulfillmentResult.Succeeded:
                        if (purchaseResults.Status == ProductPurchaseStatus.NotFulfilled)
                        {
                            rootPage.NotifyUser("You already purchased " + itemDescription + " and it was just fulfilled.", NotifyType.StatusMessage);
                        }
                        else
                        {
                            rootPage.NotifyUser("You bought and fulfilled " + itemDescription, NotifyType.StatusMessage);
                        }
                        break;
                    case FulfillmentResult.NothingToFulfill:
                        rootPage.NotifyUser("There is no purchased product 1 to fulfill with that transaction id.", NotifyType.StatusMessage);
                        break;
                    case FulfillmentResult.PurchasePending:
                        rootPage.NotifyUser(purchaseStringSimple + " The purchase is pending so we cannot fulfill the product.", NotifyType.StatusMessage);
                        break;
                    case FulfillmentResult.PurchaseReverted:
                        rootPage.NotifyUser(purchaseStringSimple + " But your purchase has been reverted.", NotifyType.StatusMessage);
                        // Since the user's purchase was revoked, they got their money back.
                        // You may want to revoke the user's access to the consumable content that was granted.
                        break;
                    case FulfillmentResult.ServerError:
                        rootPage.NotifyUser(purchaseStringSimple + " There was an error when fulfilling.", NotifyType.StatusMessage);
                        break;
                }
            }
            catch (Exception)
            {
                rootPage.NotifyUser(purchaseStringSimple + " There was an error when fulfilling.", NotifyType.ErrorMessage);
            }
        }
        private async void ReportConsumableFulfilled(PurchaseResults purchaseResult)
        {
            if(purchaseResult != null && purchaseResult.Status == ProductPurchaseStatus.Succeeded)
            {
                //We will assume the result is purchase pending. 
                //Then put the fulfillment in a loop until it is one of the success values.
                FulfillmentResult result = FulfillmentResult.PurchasePending;
                try
                {
                    while (result == FulfillmentResult.PurchasePending)
                    {
#if DEBUG
                        if (System.Diagnostics.Debugger.IsAttached)
                        {
                            result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(purchaseResult.OfferId, purchaseResult.TransactionId);
                        }
                        else
#endif
                        {
                            result = await CurrentApp.ReportConsumableFulfillmentAsync(purchaseResult.OfferId, purchaseResult.TransactionId);
                        }

                        //ToDo: Save the purchase result info to disk if we have a server error.
                        if(result == FulfillmentResult.ServerError)
                        {
                        }

                    }
                }
                catch (Exception e)
                {
#if DEBUG
                    FlatRedBall.Debugging.Debugger.Write("Unable to Fulfill consumable: " + e.ToString());
#endif
                }
                
            }
        }