Beispiel #1
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
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
 private IAsyncOperation <FulfillmentResult> ReportConsumableFulfillmentAsync(string productId, Guid transactionId)
 {
     if (_useSimulator)
     {
         return(CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId));
     }
     else
     {
         return(CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId));
     }
 }
 public static IAsyncOperation <FulfillmentResult> ReportConsumableFulfillmentAsync(string productId, Guid transactionId)
 {
     if (testmode == null)
     {
         throw new NotSupportedException();
     }
     else if (testmode.Value)
     {
         return(CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId));
     }
     else
     {
         return(CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId));
     }
 }
Beispiel #5
0
        public static void ReportConsumableFulfillment(string productId, Guid transactionId,
                                                       Action <CallbackResponse <FulfillmentResult> > OnReportConsumableFulfillmentFinished)
        {
            Utils.RunOnWindowsUIThread(async() =>
            {
                Windows.ApplicationModel.Store.FulfillmentResult result = Windows.ApplicationModel.Store.FulfillmentResult.ServerError;
                try
                {
                    if (_isLicenseSimulationOn)
                    {
                        result = await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId);
                    }
                    else
                    {
                        result = await CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId);
                    }
                }
                catch (Exception ex)
                {
                    DebugLog.Log(LogLevel.Error, "Error while reporting consumable fulfillment " + ex.ToString());
                    Utils.RunOnUnityAppThread(() => { if (OnReportConsumableFulfillmentFinished != null)
                                                      {
                                                          OnReportConsumableFulfillmentFinished(new CallbackResponse <FulfillmentResult> {
                                Status = CallbackStatus.Failure, Exception = ex, Result = FulfillmentResult.ServerError
                            });
                                                      }
                                              });
                    return;
                }

                // This should not really be throwing exceptions.. If it does, they will be raised on the Unity thread anyways, so game should handle it
                Utils.RunOnUnityAppThread(() =>
                {
                    if (OnReportConsumableFulfillmentFinished != null)
                    {
                        OnReportConsumableFulfillmentFinished(
                            new CallbackResponse <FulfillmentResult>
                        {
                            Result    = (Microsoft.UnityPlugins.FulfillmentResult)result,
                            Exception = null,
                            Status    = CallbackStatus.Success
                        });
                    }
                });
            });
        }
Beispiel #6
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();
            }
        }
Beispiel #7
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);
        }
Beispiel #8
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;
                }
            }));
        }
 public static void ReportConsumableProductFulfillment(InAppUnfulfilledProduct product, Action callback = null)
 {
     if (product == null)
     {
         return;
     }
     Execute.ExecuteOnUIThread(async delegate
     {
         try
         {
             await CurrentApp.ReportConsumableFulfillmentAsync(InAppPurchaseService.ToInAppProductId(product.ProductId), product.TransactionId);
         }
         catch
         {
         }
         Action expr_A2 = callback;
         if (expr_A2 != null)
         {
             expr_A2.Invoke();
         }
     });
 }
Beispiel #10
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);
        }
        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.";
            }
        }
Beispiel #13
0
 public static async Task <FulfillmentResult> ReportConsumableFulfillmentAsync(bool isTestingMode, string productId, Guid transactionId)
 {
     return(isTestingMode ? await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId) : await CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId));
 }
Beispiel #14
0
        private async void buyInAppAsync(string inAppID, InAppPurchaseBuyCallbackMethod purchasedCallback)
                #endif
        {
                        #if WINDOWS_PHONE
            WinRTPlugin.Dispatcher.BeginInvoke(async delegate()
                        #else
            await WinRTPlugin.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async delegate()
                        #endif
            {
                                #if WINDOWS_PHONE
                if ((testing && (!wp8TestLicenseInformation.ProductLicenses[inAppID].IsActive || wp8TestLicenseInformation.ProductLicenses[inAppID].IsConsumable)) ||
                    (!testing && (!licenseInformation.ProductLicenses[inAppID].IsActive || licenseInformation.ProductLicenses[inAppID].IsConsumable)))
                                #else
                if (!licenseInformation.ProductLicenses[inAppID].IsActive || isConsumbable(inAppID))
                                #endif
                {
                    try
                    {
                        string receipt = null;
                                                #if WINDOWS_PHONE
                        string productID = null;
                        if (testing)
                        {
                            productID = wp8TestListingInformation.ProductListings[inAppID].ProductId;
                        }
                        else
                        {
                            productID = licenseInformation.ProductLicenses[inAppID].ProductId;
                        }
                                                #elif UNITY_METRO_8_0
                        string productID = licenseInformation.ProductLicenses[inAppID].ProductId;
                                                #else
                        PurchaseResults results;
                        string productID = licenseInformation.ProductLicenses[inAppID].ProductId;
                                                #endif

                        if (testing)
                        {
                                                        #if WINDOWS_PHONE
                            receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(productID, true);
                            if (wp8TestLicenseInformation.ProductLicenses[inAppID].IsActive)
                            {
                                PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true);
                            }
                                                        #elif UNITY_METRO_8_0
                            receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(productID, true);
                                                        #else
                            results = await CurrentAppSimulator.RequestProductPurchaseAsync(productID);
                            receipt = results.ReceiptXml;
                                                        #endif
                        }
                        else
                        {
                                                        #if WINDOWS_PHONE
                            receipt = await CurrentApp.RequestProductPurchaseAsync(productID, true);
                            if (licenseInformation.ProductLicenses[inAppID].IsActive)
                            {
                                PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true);
                            }
                                                        #elif UNITY_METRO_8_0
                            receipt = await CurrentApp.RequestProductPurchaseAsync(productID, true);
                                                        #else
                            results = await CurrentApp.RequestProductPurchaseAsync(productID);
                            receipt = results.ReceiptXml;
                                                        #endif
                        }

                                                #if UNITY_METRO_8_0
                        if (!string.IsNullOrEmpty(receipt) || licenseInformation.ProductLicenses[inAppID].IsActive)
                        {
                            PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true);
                        }
                                                #elif UNITY_METRO
                        if (results.Status == ProductPurchaseStatus.Succeeded || results.Status == ProductPurchaseStatus.AlreadyPurchased || licenseInformation.ProductLicenses[inAppID].IsActive)
                        {
                            PlayerPrefsEx.SetIntAsync("ReignIAP_PurchasedAwarded_" + inAppID, 0, true);
                        }
                                                #endif

                        if (purchasedCallback != null)
                        {
                                                        #if WINDOWS_PHONE
                            if (testing)
                            {
                                purchasedCallback(inAppID, receipt, wp8TestLicenseInformation.ProductLicenses[inAppID].IsActive);
                                if (wp8TestLicenseInformation.ProductLicenses[inAppID].IsConsumable)
                                {
                                    CurrentAppSimulator.ReportProductFulfillment(productID);
                                }
                            }
                            else
                            {
                                purchasedCallback(inAppID, receipt, licenseInformation.ProductLicenses[inAppID].IsActive);
                                if (licenseInformation.ProductLicenses[inAppID].IsConsumable)
                                {
                                    CurrentApp.ReportProductFulfillment(productID);
                                }
                            }
                                                        #elif UNITY_METRO_8_0
                            purchasedCallback(inAppID, receipt, !string.IsNullOrEmpty(receipt) || licenseInformation.ProductLicenses[inAppID].IsActive);
                            if (isConsumbable(inAppID))
                            {
                                Debug.LogError("NOTE: Consumable IAP not supported in 8.0");
                            }
                                                        #else
                            purchasedCallback(inAppID, receipt, results.Status == ProductPurchaseStatus.Succeeded || results.Status == ProductPurchaseStatus.AlreadyPurchased || licenseInformation.ProductLicenses[inAppID].IsActive);
                            if (isConsumbable(inAppID))
                            {
                                if (testing)
                                {
                                    await CurrentAppSimulator.ReportConsumableFulfillmentAsync(productID, results.TransactionId);
                                }
                                else
                                {
                                    await CurrentApp.ReportConsumableFulfillmentAsync(productID, results.TransactionId);
                                }
                            }
                                                        #endif
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.Message);
                        if (purchasedCallback != null)
                        {
                            purchasedCallback(inAppID, null, false);
                        }
                    }
                }
                else
                {
                    if (purchasedCallback != null)
                    {
                        purchasedCallback(inAppID, null, true);
                    }
                }
            });
        }
 ReportConsumableFulfillmentAsync(string productId, Guid transactionId)
 {
     return(IsMockEnabled
         ? CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId)
         : CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId));
 }
Beispiel #16
0
 protected async Task <FulfillmentResult> ReportConsumableFulfillmentAsyncInternal(string productId, Guid transactionId)
 {
     return(await CurrentApp.ReportConsumableFulfillmentAsync(productId, transactionId));
 }