/// <summary>
        /// Check if the license for the selected product is already active. If not revalidate the receipt at MEGA license server
        /// </summary>
        /// <param name="productId">Produc identifier to check license validation status</param>
        private static async void LicenseCheck(string productId)
        {
            try
            {
                // Retrieve the original Windows Store receipt
                var receipt = await CurrentApp.GetProductReceiptAsync(productId);

                if (string.IsNullOrEmpty(receipt))
                {
                    return;
                }

                var xDoc     = XDocument.Parse(receipt, LoadOptions.None);
                var uniqueId = xDoc.Root.Descendants().First().Attribute("Id").Value;

                var currentIds     = SettingsService.LoadSetting(SettingsResources.Receipts, string.Empty);
                var currentIdsList = currentIds.Split(';');
                var isValidated    = currentIdsList.Any(id => id.Equals(uniqueId));
                if (!isValidated)
                {
                    SendLicenseToMega(receipt);
                }
            }
            catch
            {
                // if an error occurs, ignore. App will try again on restart
            }
        }
Beispiel #2
0
        /// <summary>
        /// Check if the product is already activated on MEGA license server
        /// </summary>
        /// <param name="productId">Product identifier</param>
        private static async Task CheckLicenseAsync(string productId)
        {
            try
            {
                if (string.IsNullOrEmpty(productId))
                {
                    return;
                }
#if DEBUG
                var receipt = await CurrentAppSimulator.GetProductReceiptAsync(productId);
#else
                var receipt = await CurrentApp.GetProductReceiptAsync(productId);
#endif
                if (string.IsNullOrEmpty(receipt))
                {
                    return;
                }

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

                if (!CheckReceiptIdStatus(receipt))
                {
                    await ActivateMegaLicenseAsync(receipt);
                }
            }
            catch (Exception e)
            {
                // If an error occurs, ignore. App will try again on restart
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error (re-)checking licenses", e);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Check if the license for the selected product is already active. If not revalidate the receipt at MEGA license server
        /// </summary>
        /// <param name="productId">Produc identifier to check license validation status</param>
        private static async void LicenseCheck(string productId)
        {
            try
            {
                // Retrieve the original Windows Store receipt
                var receipt = await CurrentApp.GetProductReceiptAsync(productId);

                if (string.IsNullOrEmpty(receipt))
                {
                    return;
                }

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

                var xDoc     = XDocument.Parse(receipt, LoadOptions.None);
                var uniqueId = xDoc.Root.Descendants().First().Attribute("Id").Value;

                var currentIds     = SettingsService.LoadSetting(SettingsResources.Receipts, string.Empty);
                var currentIdsList = currentIds.Split(';');
                var isValidated    = currentIdsList.Any(id => id.Equals(uniqueId));
                if (!isValidated)
                {
                    SendLicenseToMega(receipt);
                }
            }
            catch (Exception e)
            {
                // If an error occurs, ignore. App will try again on restart
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error (re-)checking licenses", e);
            }
        }
Beispiel #4
0
        public static async Task <string> GetProductReceiptAsync(string productId)
        {
#if DEBUG
            return(await CurrentAppSimulator.GetProductReceiptAsync(productId));
#else
            return(await CurrentApp.GetProductReceiptAsync(productId));
#endif
        }
Beispiel #5
0
        private async Task BuildCustomSupportCertificate()
        {
            // Gets the receipt for the product.
            string receipt = await CurrentApp.GetProductReceiptAsync(CustomSupportProductId);

            // Because the receipt might contain user information (such as user ID), it is encrypted
            // using AES+RSA in order to store it safely on the user's hard drive.
            EncryptToFile(receipt, CustomSupportLicenseFilepath);
        }
Beispiel #6
0
        private async Task <bool> GetLicenseStatus(string id)
        {
            try
            {
                var result = await CurrentApp.GetProductReceiptAsync(id);
            }

            catch //user didnt buy
            {
                return(false);
            }

            return(true);
        }
        public static async void LoadProductReceipt(string productId, Action <string> callback)
        {
            if (callback != null)
            {
                string text = "";
                try
                {
                    productId = InAppPurchaseService.ToInAppProductId(productId);
                    string text2 = await CurrentApp.GetProductReceiptAsync(productId);

                    text = text2;
                }
                catch
                {
                }
                callback.Invoke(text);
            }
        }
Beispiel #8
0
        private static async void LoadProductReceipts(List <string> productIds, Action <List <ProductReceipt>, Exception> onComplete)
        {
            var receipts = new List <ProductReceipt>();

            for (int index = 0; index < productIds.Count; index++)
            {
                var productId = productIds[index];

                if (string.IsNullOrEmpty(productId))
                {
                    continue;
                }

                try
                {
#if DEBUG
                    var task = CurrentApp.GetProductReceiptAsync(productId);
#else
                    var task = CurrentApp.GetProductReceiptAsync(productId).AsTask();
#endif
                    await task;

                    var receiptXml = task.Result;

                    var receipt = ProductReceipt.CreateReceipt(receiptXml);

                    receipts.Add(receipt);
                }
                catch (Exception ex)
                {
                    if (onComplete != null)
                    {
                        EtceteraWindows.RunOnUnityThread(() => onComplete(null, ex));
                    }
                    return;
                }
            }

            if (onComplete != null)
            {
                EtceteraWindows.RunOnUnityThread(() => onComplete(receipts, null));
            }
        }
Beispiel #9
0
        public static void GetProductReceipt(string productId, Action <CallbackResponse <string> > OnProductReceiptAcquired)
        {
            Utils.RunOnWindowsUIThread(async() =>
            {
                String receipt = String.Empty;

                // exceptions raised on the UI thread will be delivered on the UI thread.. so catch exception that is happening on
                // the UI thread, and marshal it back to the Unity app thread.
                try
                {
                    if (_isLicenseSimulationOn)
                    {
                        receipt = await CurrentAppSimulator.GetProductReceiptAsync(productId);
                    }
                    else
                    {
                        receipt = await CurrentApp.GetProductReceiptAsync(productId);
                    }
                }
                catch (Exception ex)
                {
                    Utils.RunOnUnityAppThread(() => { if (OnProductReceiptAcquired != null)
                                                      {
                                                          OnProductReceiptAcquired(new CallbackResponse <string> {
                                Result = null, Exception = ex, Status = CallbackStatus.Failure
                            });
                                                      }
                                              });
                    return;
                }

                Utils.RunOnUnityAppThread(() => { if (OnProductReceiptAcquired != null)
                                                  {
                                                      OnProductReceiptAcquired(new CallbackResponse <string> {
                            Result = receipt, Exception = null, Status = CallbackStatus.Success
                        });
                                                  }
                                          });
            });
        }
Beispiel #10
0
 public static async Task <string> GetProductReceiptAsync(bool isTestingMode, String productId)
 {
     return(isTestingMode ? await CurrentAppSimulator.GetProductReceiptAsync(productId) : await CurrentApp.GetProductReceiptAsync(productId));
 }