Exemplo n.º 1
0
        public static async Task <string> GetLiteMonthlyFormattedPrice()
        {
            var pricingRequestListener = new GetPricingRequestListenerAsync();
            var pricingDetails         = await pricingRequestListener.ExecuteAsync(() =>
                                                                                   SdkService.MegaSdk.getPricing(pricingRequestListener));

            if (pricingDetails == null)
            {
                return(null);
            }

            int numberOfProducts = pricingDetails.getNumProducts();

            for (int i = 0; i < numberOfProducts; i++)
            {
                var accountType = (MAccountType)Enum.Parse(typeof(MAccountType),
                                                           pricingDetails.getProLevel(i).ToString());

                if ((accountType == MAccountType.ACCOUNT_TYPE_LITE) && (pricingDetails.getMonths(i) == 1))
                {
                    // Try get the local pricing details from the store
                    var storeProduct = await LicenseService.GetProductAsync(ResourceService.AppResources.GetString("AR_ProLiteMonth"));

                    if (storeProduct != null)
                    {
                        UpgradeAccount.LiteMonthlyFormattedPrice = storeProduct.FormattedPrice;
                        break;
                    }

                    // Get the price from the MEGA server
                    UpgradeAccount.LiteMonthlyFormattedPrice = string.Format("{0:N} {1}",
                                                                             (double)pricingDetails.getAmount(i) / 100, GetCurrencySymbol(pricingDetails.getCurrency(i)));
                }
            }

            return(UpgradeAccount.LiteMonthlyFormattedPrice);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all pricing details info.
        /// </summary>
        private static async void GetPricingDetails()
        {
            // Only if they were not obtained before
            if (UpgradeAccount.Plans.Any() && UpgradeAccount.Products.Any())
            {
                return;
            }

            var pricingRequestListener = new GetPricingRequestListenerAsync();
            var pricingDetails         = await pricingRequestListener.ExecuteAsync(() =>
                                                                                   SdkService.MegaSdk.getPricing(pricingRequestListener));

            if (pricingDetails == null)
            {
                return;
            }

            int numberOfProducts = pricingDetails.getNumProducts();

            for (int i = 0; i < numberOfProducts; i++)
            {
                var accountType = (MAccountType)Enum.Parse(typeof(MAccountType),
                                                           pricingDetails.getProLevel(i).ToString());

                var product = new Product
                {
                    AccountType    = accountType,
                    FormattedPrice = string.Format("{0:N} {1}", (double)pricingDetails.getAmount(i) / 100, GetCurrencySymbol(pricingDetails.getCurrency(i))),
                    Currency       = GetCurrencySymbol(pricingDetails.getCurrency(i)),
                    GbStorage      = pricingDetails.getGBStorage(i),
                    GbTransfer     = pricingDetails.getGBTransfer(i),
                    Months         = pricingDetails.getMonths(i),
                    Handle         = pricingDetails.getHandle(i)
                };

                // Try get the local pricing details from the store
                var storeProduct = await LicenseService.GetProductAsync(product.MicrosoftStoreId);

                if (storeProduct != null)
                {
                    product.FormattedPrice = storeProduct.FormattedPrice;

                    try
                    {
                        // 'ProductListing.CurrencyCode' property was introduced on the Windows 10.0.10586 build.
                        // In previous builds like Windows 10.0.10240, it will throw an 'InvalidCastException'.
                        product.Currency = GetCurrencySymbol(
                            ApiInformation.IsPropertyPresent("Windows.ApplicationModel.Store.ProductListing", "CurrencyCode") ?
                            storeProduct.CurrencyCode : GetCurrencyFromFormattedPrice(storeProduct.FormattedPrice));
                    }
                    catch (InvalidCastException)
                    {
                        product.Currency = GetCurrencySymbol(GetCurrencyFromFormattedPrice(storeProduct.FormattedPrice));
                    }
                }

                switch (accountType)
                {
                case MAccountType.ACCOUNT_TYPE_FREE:
                    product.Name            = ResourceService.AppResources.GetString("AR_AccountTypeFree");
                    product.ProductColor    = (Color)Application.Current.Resources["MegaFreeAccountColor"];
                    product.ProductPathData = ResourceService.VisualResources.GetString("VR_AccountTypeFreePathData");
                    break;

                case MAccountType.ACCOUNT_TYPE_LITE:
                    product.Name            = ResourceService.AppResources.GetString("AR_AccountTypeLite");
                    product.ProductColor    = (Color)Application.Current.Resources["MegaProLiteAccountColor"];
                    product.ProductPathData = ResourceService.VisualResources.GetString("VR_AccountTypeProLitePathData");

                    // If product is is LITE monthly, store the price and currency for upgrade notifications purposes
                    // and include Centili and Fortumo payments methods if available
                    if (product.Months == 1)
                    {
                        product.IsCentiliPaymentMethodAvailable  = UpgradeAccount.IsCentiliPaymentMethodAvailable;
                        product.IsFortumoPaymentMethodAvailable  = UpgradeAccount.IsFortumoPaymentMethodAvailable;
                        UpgradeAccount.LiteMonthlyFormattedPrice = product.FormattedPrice;
                    }
                    break;

                case MAccountType.ACCOUNT_TYPE_PROI:
                    product.Name            = ResourceService.AppResources.GetString("AR_AccountTypePro1");
                    product.ProductColor    = (Color)Application.Current.Resources["MegaProAccountColor"];
                    product.ProductPathData = ResourceService.VisualResources.GetString("VR_AccountTypePro1PathData");
                    break;

                case MAccountType.ACCOUNT_TYPE_PROII:
                    product.Name            = ResourceService.AppResources.GetString("AR_AccountTypePro2");
                    product.ProductColor    = (Color)Application.Current.Resources["MegaProAccountColor"];
                    product.ProductPathData = ResourceService.VisualResources.GetString("VR_AccountTypePro2PathData");
                    break;

                case MAccountType.ACCOUNT_TYPE_PROIII:
                    product.Name            = ResourceService.AppResources.GetString("AR_AccountTypePro3");
                    product.ProductColor    = (Color)Application.Current.Resources["MegaProAccountColor"];
                    product.ProductPathData = ResourceService.VisualResources.GetString("VR_AccountTypePro3PathData");
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                // If CC payment method is active, include it into the product
                //product.IsCreditCardPaymentMethodAvailable = UpgradeAccount.IsCreditCardPaymentMethodAvailable;

                // If in-app payment method is active, include it into the product
                product.IsInAppPaymentMethodAvailable = UpgradeAccount.IsInAppPaymentMethodAvailable;

                await UiService.OnUiThreadAsync(() => UpgradeAccount.Products.Add(product));

                // Plans show only the information off the monthly plans
                if (pricingDetails.getMonths(i) == 1)
                {
                    var plan = new ProductBase
                    {
                        AccountType     = accountType,
                        Name            = product.Name,
                        FormattedPrice  = product.FormattedPrice,
                        Currency        = product.Currency,
                        GbStorage       = product.GbStorage,
                        GbTransfer      = product.GbTransfer,
                        ProductPathData = product.ProductPathData,
                        ProductColor    = product.ProductColor
                    };

                    await UiService.OnUiThreadAsync(() => UpgradeAccount.Plans.Add(plan));
                }
            }
        }