/// <summary> /// Gets the available payment methods /// </summary> private static async void GetPaymentMethods() { UpgradeAccount.IsInAppPaymentMethodAvailable = await LicenseService.GetIsAvailableAsync(); var paymentMethodsRequestListener = new GetPaymentMethodsRequestListenerAsync(); var availablePaymentMethods = await paymentMethodsRequestListener.ExecuteAsync(() => SdkService.MegaSdk.getPaymentMethods(paymentMethodsRequestListener)); UpgradeAccount.IsCentiliPaymentMethodAvailable = Convert.ToBoolean(availablePaymentMethods & (1 << (int)MPaymentMethod.PAYMENT_METHOD_CENTILI)); UpgradeAccount.IsFortumoPaymentMethodAvailable = Convert.ToBoolean(availablePaymentMethods & (1 << (int)MPaymentMethod.PAYMENT_METHOD_FORTUMO)); //UpgradeAccount.IsCreditCardPaymentMethodAvailable = Convert.ToBoolean(availablePaymentMethods & (1 << (int)MPaymentMethod.PAYMENT_METHOD_CREDIT_CARD)); }
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); }
/// <summary> /// Gets all pricing details info. /// </summary> /// <param name="pricingDetails">Details about pricing plans</param> public static void GetPricingDetails(MPricing pricingDetails) { Deployment.Current.Dispatcher.BeginInvoke(async() => { AccountService.UpgradeAccount.Products.Clear(); AccountService.UpgradeAccount.Plans.Clear(); if (App.AppInformation.IsNewlyActivatedAccount) { var freePlan = new ProductBase { AccountType = MAccountType.ACCOUNT_TYPE_FREE, Name = AppResources.AccountTypeFree, ProductColor = Color.FromArgb(255, 19, 224, 60), ProductPathData = VisualResources.CrestFreeAccountPathData }; AccountService.UpgradeAccount.Plans.Add(freePlan); App.AppInformation.IsNewlyActivatedAccount = false; } 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, Amount = pricingDetails.getAmount(i), FormattedPrice = string.Format("{0:N} {1}", (double)pricingDetails.getAmount(i) / 100, AccountService.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; product.Currency = AccountService.GetCurrencySymbol( AccountService.GetCurrencyFromFormattedPrice(storeProduct.FormattedPrice)); } switch (accountType) { case MAccountType.ACCOUNT_TYPE_FREE: product.Name = AppResources.AccountTypeFree; product.ProductPathData = VisualResources.CrestFreeAccountPathData; break; case MAccountType.ACCOUNT_TYPE_LITE: product.Name = AppResources.AccountTypeLite; product.ProductColor = Color.FromArgb(255, 255, 165, 0); product.ProductPathData = VisualResources.CrestLiteAccountPathData; // If Centili payment method is active, and product is LITE monthly include it into the product if (AccountService.UpgradeAccount.CentiliPaymentMethodAvailable && product.Months == 1) { var centiliPaymentMethod = new PaymentMethod { PaymentMethodType = MPaymentMethod.PAYMENT_METHOD_CENTILI, Name = String.Format("Centili - " + UiResources.PhoneBill + " (" + UiResources.Punctual.ToLower() + ")"), PaymentMethodPathData = VisualResources.PhoneBillingPathData }; product.PaymentMethods.Add(centiliPaymentMethod); } // If Fortumo payment method is active, and product is LITE monthly include it into the product if (AccountService.UpgradeAccount.FortumoPaymentMethodAvailable && product.Months == 1) { var fortumoPaymentMethod = new PaymentMethod { PaymentMethodType = MPaymentMethod.PAYMENT_METHOD_FORTUMO, Name = String.Format("Fortumo - " + UiResources.PhoneBill + " (" + UiResources.Punctual.ToLower() + ")"), PaymentMethodPathData = VisualResources.PhoneBillingPathData }; product.PaymentMethods.Add(fortumoPaymentMethod); } break; case MAccountType.ACCOUNT_TYPE_PROI: product.Name = AppResources.AccountTypePro1; product.ProductColor = Color.FromArgb(255, 217, 0, 7); product.ProductPathData = VisualResources.CrestProIAccountPathData; break; case MAccountType.ACCOUNT_TYPE_PROII: product.Name = AppResources.AccountTypePro2; product.ProductColor = Color.FromArgb(255, 217, 0, 7); product.ProductPathData = VisualResources.CrestProIIAccountPathData; break; case MAccountType.ACCOUNT_TYPE_PROIII: product.Name = AppResources.AccountTypePro3; product.ProductColor = Color.FromArgb(255, 217, 0, 7); product.ProductPathData = VisualResources.CrestProIIIAccountPathData; break; default: product.ProductColor = Color.FromArgb(255, 217, 0, 7); break; } // If CC payment method is active, include it into the product if (AccountService.UpgradeAccount.CreditCardPaymentMethodAvailable) { var creditCardPaymentMethod = new PaymentMethod { PaymentMethodType = MPaymentMethod.PAYMENT_METHOD_CREDIT_CARD, Name = String.Format(UiResources.CreditCard + " (" + UiResources.Recurring.ToLower() + ")"), PaymentMethodPathData = VisualResources.CreditCardPathData }; product.PaymentMethods.Add(creditCardPaymentMethod); } // If in-app payment method is active, include it into the product if (AccountService.UpgradeAccount.InAppPaymentMethodAvailable) { var inAppPaymentMethod = new PaymentMethod { PaymentMethodType = MPaymentMethod.PAYMENT_METHOD_WINDOWS_STORE, Name = String.Format(UiResources.UI_InAppPurchase + " - " + UiResources.PhoneBill + " (" + UiResources.Punctual.ToLower() + ")"), PaymentMethodPathData = VisualResources.PhoneBillingPathData }; product.PaymentMethods.Add(inAppPaymentMethod); } AccountService.UpgradeAccount.Products.Add(product); #if DEBUG // Fill the Mocking IAP product listing with actual MEGA product id's LicenseService.AddProductToMockIap(product); #endif // Plans show only the information off the annualy plans if (pricingDetails.getMonths(i) == 12) { var plan = new ProductBase { AccountType = accountType, Name = product.Name, Amount = product.Amount, FormattedPrice = product.FormattedPrice, Currency = product.Currency, GbStorage = product.GbStorage, GbTransfer = product.GbTransfer / 12, ProductPathData = product.ProductPathData, ProductColor = product.ProductColor, IsNewOffer = product.IsNewOffer }; AccountService.UpgradeAccount.Plans.Add(plan); // Check if the user has a product/plan already purchased and fill the structure to show it if (accountType == AccountService.AccountDetails.AccountType && pricingDetails.getMonths(i) == 12) { AccountService.UpgradeAccount.ProductPurchased = product; AccountService.UpgradeAccount.ProductPurchased.GbTransfer = pricingDetails.getGBTransfer(i) / 12; AccountService.UpgradeAccount.ProductPurchased.IsNewOffer = false; AccountService.UpgradeAccount.ProductPurchased.Purchased = true; } } } }); }
/// <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)); } } }