Exemple #1
0
        private void FulfillProduct1(string productId, Guid transactionId)
        {
            try
            {
                FulfillmentResult result = CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId).AsTask().ConfigureAwait(false).GetAwaiter().GetResult();
                switch (result)
                {
                case FulfillmentResult.Succeeded:
                    Debug.WriteLine("You bought and fulfilled product 1.");
                    break;

                case FulfillmentResult.NothingToFulfill:
                    Debug.WriteLine("There is no purchased product 1 to fulfill.");
                    break;

                case FulfillmentResult.PurchasePending:
                    Debug.WriteLine("You bought product 1. The purchase is pending so we cannot fulfill the product.");
                    break;

                case FulfillmentResult.PurchaseReverted:
                    Debug.WriteLine("You bought product 1. But your purchase has been reverted.");
                    // 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:
                    Debug.WriteLine("You bought product 1. There was an error when fulfilling.");
                    break;
                }
            }
            catch (System.Exception e)
            {
                Debug.WriteLine("You bought Product 1. There was an error when fulfilling.  " + e);
            }
        }
Exemple #2
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
        }
        private async void Example2()
        {
            //<ReportFulfillment>
            FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(
                "product2", product2TempTransactionId);

            //</ReportFulfillment>
        }
Exemple #4
0
        private async void ReportFulfillment()
        {
            ListingInformation listing = await CurrentAppSimulator.LoadListingInformationAsync();

            var    product1            = listing.ProductListings["product1"];
            string product1ListingName = string.Empty;
            string productId           = product1.ProductId;
            Guid   transactionId       = new Guid();

            //<ReportFulfillment>
            string offerId = "1234";

            product1ListingName = product1.Name;
            string displayPropertiesName = "MusicOffer1";

            if (String.IsNullOrEmpty(displayPropertiesName))
            {
                displayPropertiesName = product1ListingName;
            }
            var offerIdMsg = " with offer id " + offerId;

            if (String.IsNullOrEmpty(offerId))
            {
                offerIdMsg = " with no offer id";
            }

            FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId);

            switch (result)
            {
            case FulfillmentResult.Succeeded:
                Log("You bought and fulfilled " + displayPropertiesName + offerIdMsg);
                break;

            case FulfillmentResult.NothingToFulfill:
                Log("There is no purchased product 1 to fulfill.");
                break;

            case FulfillmentResult.PurchasePending:
                Log("You bought product 1. The purchase is pending so we cannot fulfill the product.");
                break;

            case FulfillmentResult.PurchaseReverted:
                Log("You bought product 1. But your purchase has been reverted.");
                // 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("You bought product 1. There was an error when fulfilling.");
                break;
            }
            //</ReportFulfillment>
        }
        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);
            }
        }
Exemple #6
0
        public async Task AdTapped()
        {
            AdSuccess = false;
            if (Type == AdType.INAPP)
            {
                FulfillmentResult fr = await MarketplaceHelper.Instance.PurchaseProduct(productId);

                if (fr == FulfillmentResult.Succeeded)
                {
                    AdSuccess = true;
                }
            }
            else if (Type == AdType.WEBLINK)
            {
                AdSuccess = true;
                await Windows.System.Launcher.LaunchUriAsync(new Uri(uriLink));
            }
        }
Exemple #7
0
        private async void FulfillProduct(string productId, Guid transactionId)
        {
            try
            {
                FulfillmentResult result = await IAPs.ReportConsumableFulfillmentAsync(productId, transactionId);

                switch (result)
                {
                case FulfillmentResult.Succeeded:
                    break;

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

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

                case FulfillmentResult.PurchaseReverted:
                    //rootPage.NotifyUser("You bought product 1, 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("You bought product 1. There was an error when fulfilling.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                //rootPage.NotifyUser("You bought Product 1. There was an error when fulfilling.", NotifyType.ErrorMessage);
            }
            ResourceLoader resource = ResourceLoader.GetForCurrentView();
            var            dlg      = DialogHelper.GetSimpleContentDialog(
                resource.GetString("IAPs/Donation/Thanks/Title"),
                resource.GetString("IAPs/Donation/Thanks/Content"),
                resource.GetString("Button/Ok/Content"));
            await dlg.ShowAsync();

            App.ContentDlgOp = null;
        }
        private async void FulfillProduct(ProductPurchaseInfo info)
        {
            if (!IsLocallyFulfilled(info, info.tempTransactionId))
            {
                GrantFeatureLocally(info, info.tempTransactionId);
            }

            try
            {
                FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(info.productId, info.tempTransactionId);

                switch (result)
                {
                case FulfillmentResult.Succeeded:
                    info.numFulfillments++;
                    rootPage.NotifyUser(info.nameRun.Text + " was fulfilled. You are now able to buy another one.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.NothingToFulfill:
                    rootPage.NotifyUser("There is nothing to fulfill. You must purchase " + info.nameRun.Text + " before it can be fulfilled.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchasePending:
                    rootPage.NotifyUser("Purchase hasn't completed yet. Wait and try again.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchaseReverted:
                    rootPage.NotifyUser("Purchase was reverted before fulfillment.", 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("There was an error when fulfilling.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                rootPage.NotifyUser("There was an error when fulfilling.", NotifyType.ErrorMessage);
            }
            UpdateStatistics();
        }
Exemple #9
0
        private static async Task <FulfillmentResult> FulfillAsync(string productID, Guid transactionID)
        {
            if (ApplicationInfo.Current.HasInternetConnection == false)
            {
                return(FulfillmentResult.ServerError);
            }

            FulfillmentResult result = FulfillmentResult.PurchasePending;

            try
            {
                result = await CurrentApp.ReportConsumableFulfillmentAsync(
                    productID, transactionID);
            }
            catch
            {
            }

            return(result);
        }
Exemple #10
0
        private IAsyncOperation <bool> FulfillProductInternal(Guid transactionId)
        {
            return(AsyncInfo.Run(async cancellationToken =>
            {
                try
                {
#if DEBUG
                    FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync("Credits", transactionId);
#else
                    FulfillmentResult result = await CurrentApp.ReportConsumableFulfillmentAsync("Credits", transactionId);
                    Analytics.TrackEvent("credits.fulfillement", new Dictionary <string, string> {
                        ["result"] = result.ToString()
                    });
#endif
                    switch (result)
                    {
                    case FulfillmentResult.Succeeded:
                        return true;

                    case FulfillmentResult.NothingToFulfill:
                        return true;

                    case FulfillmentResult.PurchasePending:
                        return true;

                    case FulfillmentResult.PurchaseReverted:
                        return true;

                    case FulfillmentResult.ServerError:
                        return true;

                    default:
                        return false;
                    }
                }
                catch (Exception)
                {
                    return false;
                }
            }));
        }
        private async void FulfillProduct2Button_Click(object sender, RoutedEventArgs e)
        {
            if (!IsLocallyFulfilled("product2", product2TempTransactionId))
            {
                GrantFeatureLocally("product2", product2TempTransactionId);
            }

            try {
                FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync("product2", product2TempTransactionId);

                switch (result)
                {
                case FulfillmentResult.Succeeded:
                    product2NumFulfillments++;
                    Log("Product 2 was fulfilled. You are now able to buy product 2 again.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.NothingToFulfill:
                    Log("There is nothing to fulfill. You must purchase product 2 before it can be fulfilled.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchasePending:
                    Log("Purchase hasn't completed yet. Wait and try again.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchaseReverted:
                    Log("Purchase was reverted before fulfillment.", 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("There was an error when fulfilling.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                Log("There was an error when fulfilling.", NotifyType.ErrorMessage);
            }
        }
Exemple #12
0
        private async Task <bool> FulfillDonation()
        {
            var unfulfilledConsumables = await CurrentApp.GetUnfulfilledConsumablesAsync();

            foreach (UnfulfilledConsumable consumable in unfulfilledConsumables)
            {
                if (consumable.ProductId == "donation")
                {
                    FulfillmentResult fulfillmentResult = await CurrentApp.ReportConsumableFulfillmentAsync(consumable.ProductId, consumable.TransactionId);

                    switch (fulfillmentResult)
                    {
                    case FulfillmentResult.Succeeded:
                    case FulfillmentResult.NothingToFulfill:
                    case FulfillmentResult.PurchaseReverted:
                        return(true);
                    }
                    return(false);
                }
            }
            return(true);
        }
Exemple #13
0
        private static WSAFulfillmentResult MapFulfillmentResult(FulfillmentResult result)
        {
            switch (result)
            {
            case FulfillmentResult.NothingToFulfill:
                return(WSAFulfillmentResult.NothingToFulfill);

            case FulfillmentResult.PurchasePending:
                return(WSAFulfillmentResult.PurchasePending);

            case FulfillmentResult.PurchaseReverted:
                return(WSAFulfillmentResult.PurchaseReverted);

            case FulfillmentResult.ServerError:
                return(WSAFulfillmentResult.ServerError);

            case FulfillmentResult.Succeeded:
                return(WSAFulfillmentResult.Succeeded);
            }

            return(WSAFulfillmentResult.NothingToFulfill);
        }
        public async Task <FulfillmentResult> PurchaseProduct(string productId)
        {
            try
            {
                await CurrentApp.RequestProductPurchaseAsync(productId);

                try
                {
                    var licenses = CurrentApp.LicenseInformation.ProductLicenses;
                    if (licenses[productId].IsConsumable && licenses[productId].IsActive)
                    {
                        Guid transactionID   = new Guid();
                        FulfillmentResult fr = await CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionID);

                        return(fr);
                    }
                }
                catch (Exception) { }
            }
            catch (Exception) { }

            return(FulfillmentResult.ServerError);
        }
        private async void FulfillProduct(string storeId, Guid transactionId)
        {
            try
            {
                FulfillmentResult result = await CurrentApp.ReportConsumableFulfillmentAsync(storeId, transactionId);

                switch (result)
                {
                case FulfillmentResult.Succeeded:
                    textBlockPurchase.Text = "You bought and fulfilled product";
                    break;

                case FulfillmentResult.NothingToFulfill:
                    textBlockPurchase.Text = "There is no purchased product to fulfill.";
                    break;

                case FulfillmentResult.PurchasePending:
                    textBlockPurchase.Text = "You bought product. The purchase is pending so we cannot fulfill the product.";
                    break;

                case FulfillmentResult.PurchaseReverted:
                    textBlockPurchase.Text = "You bought product, but your purchase has been reverted.";
                    // 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:
                    textBlockPurchase.Text = "You bought product. There was an error when fulfilling.";
                    break;
                }
            }
            catch
            {
                textBlockPurchase.Text = "You bought product. There was an error when fulfilling.";
            }
        }
        private async void FulfillProduct1(string productId, Guid transactionId)
        {
            try
            {
                FulfillmentResult result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId);

                switch (result)
                {
                case FulfillmentResult.Succeeded:
                    Log("You bought and fulfilled product 1.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.NothingToFulfill:
                    Log("There is no purchased product 1 to fulfill.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchasePending:
                    Log("You bought product 1. The purchase is pending so we cannot fulfill the product.", NotifyType.StatusMessage);
                    break;

                case FulfillmentResult.PurchaseReverted:
                    Log("You bought product 1. 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("You bought product 1. There was an error when fulfilling.", NotifyType.StatusMessage);
                    break;
                }
            }
            catch (Exception)
            {
                Log("You bought Product 1. There was an error when fulfilling.", NotifyType.ErrorMessage);
            }
        }
Exemple #17
0
        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);
            }
        }
Exemple #18
0
        public static async Task <ProductPurchaseStatus> PurchaseAsync(ProductListing product)
        {
            ProductPurchaseStatus status = ProductPurchaseStatus.NotPurchased;

            try
            {
                Guid            productTransactionId;
                List <Guid>     grantedConsumableTransactionIds = new List <Guid>();
                PurchaseResults purchaseResults = await CurrentApp.RequestProductPurchaseAsync(product.ProductId);

                status = purchaseResults.Status;

                switch (status)
                {
                case ProductPurchaseStatus.Succeeded:
                    productTransactionId = purchaseResults.TransactionId;

                    FulfillmentResult fulfillmentResult = await FulfillAsync(product.ProductId, productTransactionId);

                    break;

                case ProductPurchaseStatus.NotFulfilled:

                    if (ApplicationInfo.Current.HasInternetConnection)
                    {
                        var unfulfilledPurchases = await CurrentApp.GetUnfulfilledConsumablesAsync();

                        foreach (UnfulfilledConsumable unfulfilledConsumable in unfulfilledPurchases)
                        {
                            await FulfillAsync(unfulfilledConsumable.ProductId, unfulfilledConsumable.TransactionId);
                        }
                    }

                    break;

                case ProductPurchaseStatus.NotPurchased:

                    break;
                }

                //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.NotPurchased:

                //        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;
                //}
            }
            catch
            {
            }

            return(status);
        }