Пример #1
0
        private static async Task <bool> CheckIfUserHasSubscriptionAsync(string msProductId)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            // Check if the customer has the rights to the subscription.
            foreach (var addOnLicense in appLicense.AddOnLicenses)
            {
                StoreLicense license = addOnLicense.Value;
                if (license.SkuStoreId.StartsWith(msProductId))
                {
                    if (license.IsActive)
                    {
                        // The expiration date is available in the license.ExpirationDate property.
                        accountType = "starter";
                        updateCloureAccount(license.ExpirationDate);
                        return(true);
                    }
                }
            }

            // The customer does not have a license to the subscription.
            return(false);
        }
Пример #2
0
        /// <summary>
        /// Get All Purchases
        /// </summary>
        /// <param name="itemType">not used for UWP</param>
        /// <returns></returns>
        public async Task <List <PurchaseResult> > GetPurchasesAsync(ItemType itemType = ItemType.InAppPurchase, IInAppBillingVerifyPurchase verifyPurchase = null, string verifyOnlyProductId = null)
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }
            var             PurchaseHistoryResult = new List <PurchaseResult>();
            StoreAppLicense appLicense            = await context.GetAppLicenseAsync();

            if (appLicense?.AddOnLicenses?.Count > 0)
            {
                foreach (var addOnLicense in appLicense.AddOnLicenses)
                {
                    StoreLicense license         = addOnLicense.Value;
                    var          purchaseHistory = new PurchaseResult();
                    purchaseHistory.Sku           = license.InAppOfferToken; //UWP SkuStoreId is different than Product ID, InAppOfferToken is the product ID
                    purchaseHistory.PurchaseToken = license.SkuStoreId;

                    purchaseHistory.ExpirationDate = license.ExpirationDate;
                    if (!license.IsActive)
                    {
                        purchaseHistory.PurchaseState = PurchaseState.Cancelled;
                    }
                    else
                    {
                        purchaseHistory.PurchaseState = PurchaseState.Purchased;
                    }

                    PurchaseHistoryResult.Add(purchaseHistory);
                }
            }

            // The customer does not have a license to the subscription.
            return(PurchaseHistoryResult);
        }
Пример #3
0
        public async Task <IActionResult> PutStoreLicense(Guid id, StoreLicense storeLicense)
        {
            if (id != storeLicense.LicenseId)
            {
                return(BadRequest());
            }

            _context.Entry(storeLicense).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StoreLicenseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public static void CheckForPremiumStatus()
        {
#if DEBUG
            if (LicenseInformation.ProductLicenses["PremiumStatus"].IsActive)
            {
                IsPremium = RemoveAds = true;
            }
#else
            var subscriptionStoreId = "9PMT47KC5W6C";

            foreach (var addOnLicense in _appLicense.AddOnLicenses)
            {
                StoreLicense license = addOnLicense.Value;
                if (license.SkuStoreId.StartsWith(subscriptionStoreId))
                {
                    if (license.IsActive)
                    {
                        IsPremium = RemoveAds = true;
                        return;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            IsPremium = RemoveAds = false;
#endif
        }
Пример #5
0
        public async void GetLicenseInfo()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            if (appLicense == null)
            {
                // textBlock.Text = "An error occurred while retrieving the license.";
                return;
            }

            // Access the add on licenses for add-ons for this app.
            foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses)
            {
                StoreLicense addOnLicense = item.Value;
                // Use members of the addOnLicense object to access license info
                // for the add-on...
                //addOnLicense.
                if (addOnLicense.IsActive)
                {
                    AdGrid.Visibility = Visibility.Collapsed;
                }
            }
        }
        public async void GetLicenseInfo()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }

            workingProgressRing.IsActive = true;
            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            workingProgressRing.IsActive = false;

            if (appLicense == null)
            {
                textBlock.Text = "An error occurred while retrieving the license.";
                return;
            }

            // Use members of the appLicense object to access license info...

            // Access the valid licenses for durable add-ons for this app.
            foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses)
            {
                StoreLicense addOnLicense = item.Value;
                // Use members of the addOnLicense object to access license info
                // for the add-on.
            }
        }
        public async Task <ActionResult <StoreLicense> > PostStoreLicense(StoreLicense storeLicense)
        {
            _context.StoreLicenses.Add(storeLicense);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetStoreLicense", new { id = storeLicense.LicenseId }, storeLicense));
        }
Пример #8
0
        public async Task <bool> CheckIfUserHasAdFreeSubscriptionAsync()
        {
            if (storeContext == null)
            {
                storeContext = StoreContext.GetDefault();

                //IInitializeWithWindow initWindow = (IInitializeWithWindow)(object)storeContext;
                //initWindow.Initialize(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
            }

            StoreAppLicense appLicense = await storeContext.GetAppLicenseAsync();

            // Check if the customer has the rights to the subscription.
            foreach (var addOnLicense in appLicense.AddOnLicenses)
            {
                StoreLicense license = addOnLicense.Value;
                if (license.SkuStoreId.StartsWith(adFreeSubscriptionStoreId))
                {
                    if (license.IsActive)
                    {
                        // The expiration date is available in the license.ExpirationDate property.
                        return(true);
                    }
                }
            }

            // The customer does not have a license to the subscription.
            return(false);
        }
        public async Task <bool> PostStoreLicense(string email, string username)
        {
            var newStoreLicense = new StoreLicense()
            {
                LicenseId = Guid.NewGuid(),
                StartDate = DateTime.Today,
                IsUsed    = false
            };

            _context.StoreLicenses.Add(newStoreLicense);
            await _context.SaveChangesAsync();

            if (_context.StoreLicenses.Where(l => l.LicenseId == newStoreLicense.LicenseId).FirstOrDefault() != null)
            {
                var senderEmail   = new MailAddress("*****@*****.**", "Quick Order");
                var receiverEmail = new MailAddress(email, username);

                var sub  = "Quick Order Lincense Code";
                var body = "<span>License Code:</span>" + newStoreLicense.LicenseId;
                var smtp = new SmtpClient
                {
                    Host                  = "smtp.gmail.com",
                    Port                  = 587,
                    EnableSsl             = true,
                    DeliveryMethod        = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials           = new NetworkCredential("*****@*****.**", "jp84704tt")
                };
                using (var mess = new MailMessage(senderEmail, receiverEmail)
                {
                    IsBodyHtml = true,
                    Subject = sub,
                    Body = body
                })
                {
                    smtp.Send(mess);
                }

                return(true);
            }
            else
            {
                return(false);
            }

            //return CreatedAtAction("GetStoreLicense", new { id = storeLicense.LicenseId }, storeLicense);
        }
        public async Task <IActionResult> NewLicense()
        {
            var cardResult = await cardDataStore.GetCardFromUser(LogUser.LoginUser.UserId, LogUser.Token.Token);

            if (cardResult.Count() > 0)
            {
                var subcriptionToken = await stripeServiceDS.CreateACustomerSubcription(LogUser.LoginUser.StripeUserId);

                if (!string.IsNullOrEmpty(subcriptionToken))
                {
                    var newStoreLicense = new StoreLicense()
                    {
                        LicenseId           = Guid.NewGuid(),
                        StartDate           = DateTime.Today,
                        LicenseHolderUserId = LogUser.LoginUser.UserId
                    };

                    //Lo insertamos a nuestra base de datos
                    var storelicenceresult = await storeLicenseDataStore.AddItemAsync(newStoreLicense);

                    if (storelicenceresult)
                    {
                        var subcription = new Library.Models.Subcription()
                        {
                            StripeCustomerId    = LogUser.LoginUser.StripeUserId,
                            StripeSubCriptionID = subcriptionToken,
                            StoreLicense        = newStoreLicense.LicenseId,
                            IsDisable           = false
                        };

                        var subcriptionResult = await subcriptionDataStore.AddItemAsync(subcription);

                        if (subcriptionResult)
                        {
                            var licenseReuslt = await storeLicenseDataStore.PostStoreLicense(LogUser.LoginUser.Email, LogUser.LoginUser.Name);

                            return(RedirectToAction("RegisterControl"));
                        }
                    }
                }
            }

            return(RedirectToAction("RegisterControl"));
        }
Пример #11
0
        //检查用户是否有订阅的许可证
        private async Task <bool> CheckIfUserHasSubscriptionAsync()
        {
            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            //检查客户是否具有订阅权限。
            foreach (var addOnLicense in appLicense.AddOnLicenses)
            {
                StoreLicense license = addOnLicense.Value;
                if (license.SkuStoreId.StartsWith(productID))
                {
                    if (license.IsActive)
                    {
                        // The expiration date is available in the license.ExpirationDate property.
                        return(true);
                        //客户有订阅的许可证。
                    }
                }
            }
            //客户没有订阅的许可证。
            return(false);
        }
Пример #12
0
        private async Task <bool> CheckIfUserHasSubscriptionAsync()
        {
            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            // Check if the customer has the rights to the subscription.
            foreach (var addOnLicense in appLicense.AddOnLicenses)
            {
                StoreLicense license = addOnLicense.Value;
                if (license.SkuStoreId.StartsWith(subscriptionStoreId))
                {
                    if (license.IsActive)
                    {
                        // The expiration date is available in the license.ExpirationDate property.
                        return(true);
                    }
                }
            }

            // The customer does not have a license to the subscription.
            return(false);
        }
        public async Task <bool> PutStoreLicense(StoreLicense storeLicense)
        {
            _context.Entry(storeLicense).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();

                return(true);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!StoreLicenseExists(storeLicense.LicenseId))
                {
                    return(false);
                }
                else
                {
                    throw;
                }
            }
        }
Пример #14
0
        public async Task <Response <List <AddOnItem> > > GetAllAddOns()
        {
            if (IsStoreContextTypePresent)
            {
                StoreContext storeContext             = StoreContext.GetDefault();
                Response <List <AddOnItem> > response = new Response <List <AddOnItem> >();
                string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" };
                StoreProductQueryResult queryResult = await storeContext.GetAssociatedStoreProductsAsync(productKinds);

                if (queryResult.ExtendedError != null)
                {
                    response.IsError = true;
                    response.Message = queryResult.ExtendedError.Message;
                    response.Error   = queryResult.ExtendedError;
                }
                else
                {
                    List <AddOnItem> ret = new List <AddOnItem>();
                    IReadOnlyDictionary <string, StoreLicense> licenses = await GetAddOnLicenses();

                    foreach (KeyValuePair <string, StoreProduct> item in queryResult.Products)
                    {
                        AddOnItem    addOn        = new AddOnItem(item.Value);
                        var          matchingPair = licenses.FirstOrDefault(p => p.Key.StartsWith(item.Key));
                        StoreLicense license      = matchingPair.Value;
                        addOn.IsActive   = license?.IsActive ?? false;
                        addOn.ExpiryDate = license?.ExpirationDate ?? default(DateTimeOffset);
                        ret.Add(addOn);
                    }
                    response.Content = ret;
                }
                return(response);
            }
            else
            {
                return(new Response <List <AddOnItem> >());
            }
        }
Пример #15
0
        public async Task <bool> GetAddOnLicenseInfo()
        {
            bool IsActive = false;

            var users = await User.FindAllAsync();

            StoreContext context = StoreContext.GetForUser(users[0]);

            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            System.Diagnostics.Debug.WriteLine(appLicense.AddOnLicenses.Count);

            foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses)
            {
                StoreLicense addOnLicense = item.Value;

                if (addOnLicense.SkuStoreId.ToLower().Contains("9pc587j41rs1"))
                {
                    PremiumFeaturesActivatedType = "Month";
                }
                else if (addOnLicense.SkuStoreId.ToLower().Contains("9pf5zlm4lprg"))
                {
                    PremiumFeaturesActivatedType = "Year";
                }
                else
                {
                    return(false);
                }

                PremiumFeaturesActivatedRemain = (addOnLicense.ExpirationDate - DateTime.Now).Days.ToString();

                IsActive = addOnLicense.IsActive;
            }

            return(IsActive);
        }
Пример #16
0
        public async void GetLicenseInfo()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
            }

            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            if (appLicense == null)
            {
                return;
            }

            foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses)
            {
                StoreLicense addOnLicense = item.Value;
                if (addOnLicense.IsActive)
                {
                    AdGrid.Visibility     = Visibility.Collapsed;
                    DrinkManager.IsAdFree = true;
                }
            }
        }
Пример #17
0
        public async Task <IActionResult> UserRegistration(UserViewModel userVm)
        {
            if (UserInfoNotNullOrEmpty(userVm))
            {
                if (userVm.Password == userVm.ConfirmPassword)
                {
                    var credentialExist = await userDataStore.CheckIfUsernameAndPasswordExist(userVm.Username, userVm.Password);

                    if (!credentialExist)
                    {
                        //Las credenciales de entrada del usuario
                        var userLogin = new Login()
                        {
                            LoginId  = Guid.NewGuid(),
                            Password = userVm.Password,
                            Username = userVm.Username
                        };

                        //Creamos el usuario
                        var newUser = new User()
                        {
                            UserId    = Guid.NewGuid(),
                            Email     = userVm.Email,
                            LoginId   = userLogin.LoginId,
                            Name      = userVm.Name,
                            UserLogin = userLogin,
                            Address   = userVm.Address
                        };


                        //Obtenemos datos de empleados necesarios para el registro en stripe
                        var optionsCustomers = new UserDTO
                        {
                            Name    = userVm.Name,
                            Email   = userVm.Email,
                            Phone   = userVm.Phone,
                            Address = userVm.Address,
                        };


                        //Creamos un nuevo usuario en stripe
                        var customerToken = await StripeServiceDS.CreateStripeCustomer(optionsCustomers);

                        //Le  insertamos la tarjeta al nuevo usuario de stripe
                        var cardservicetokenId = await StripeServiceDS.InsertStripeCardToCustomer(PaymentCard, customerToken);

                        //Creamos la subcripcion al usuario

                        var subcriptiontoken = await StripeServiceDS.CreateACustomerSubcription(customerToken);

                        //Verificamos que la informacion este correcta

                        if (!string.IsNullOrEmpty(subcriptiontoken))
                        {
                            //Le damos el id del nuevo customer de la cuenta de stripe.
                            newUser.StripeUserId = customerToken;



                            //Lo agregamos a la base de datos.
                            var addedUser = await userDataStore.AddItemAsync(newUser);

                            //Verificamos si el usuario se inserto a nuestra base de datos
                            if (addedUser)
                            {
                                //Verificamos si el token de la tarjeta insertada es correcta.
                                if (!string.IsNullOrEmpty(cardservicetokenId))
                                {
                                    //Agregamos la tarjeta a nuestra base de datos.
                                    var cardadded = cardDataStore.AddItemAsync(new PaymentCard()
                                    {
                                        UserId        = newUser.UserId,
                                        StripeCardId  = cardservicetokenId,
                                        CardNumber    = PaymentCard.CardNumber,
                                        Cvc           = PaymentCard.Cvc,
                                        Month         = PaymentCard.Month,
                                        Year          = PaymentCard.Year,
                                        HolderName    = PaymentCard.HolderName,
                                        PaymentCardId = Guid.NewGuid()
                                    });
                                }

                                //Creamos el lincense
                                var newStoreLicense = new StoreLicense()
                                {
                                    LicenseId           = Guid.NewGuid(),
                                    StartDate           = DateTime.Today,
                                    LicenseHolderUserId = newUser.UserId
                                };

                                //Lo insertamos a nuestra base de datos
                                var storelicenceresult = await storeLicenseDataStore.AddItemAsync(newStoreLicense);

                                //Verificamos el resultado
                                if (storelicenceresult)
                                {
                                    var subcription = new Subcription()
                                    {
                                        IsDisable           = false,
                                        StripeCustomerId    = customerToken,
                                        StripeSubCriptionID = subcriptiontoken,
                                        StoreLicense        = newStoreLicense.LicenseId
                                    };

                                    var result = SubcriptionDataStore.AddItemAsync(subcription);

                                    //Enviamos el email con el codio de la nueva licensia.
                                    SendStoreLicenceEmailCode(newUser.Email, newStoreLicense.LicenseId.ToString());
                                }
                                //Verificamos que los credenciales esten correctos.
                                var resultCredentials = userDataStore.CheckUserCredential(userLogin.Username, userLogin.Password);

                                //Validamos que el resultado no sea vacio
                                if (resultCredentials != null)
                                {
                                    //Le damos los credenciales al LogUser
                                    LogUser.LoginUser = resultCredentials;
                                }

                                //Luego de todo completado de manera correcta nos vamos a registrar una tienda.
                                return(RedirectToAction("RegisterStore", "Store"));
                            }
                        }
                        else
                        {
                            return(View());
                        }
                    }
                    else
                    {
                        ViewBag.ErrorMsg = "The creditals already exists.";
                        return(View());
                    }
                }
                else
                {
                    ViewBag.ErrorMsg = "The password and confirm pasword are different.";
                    return(View());
                }
            }


            return(View());
        }
Пример #18
0
        public async void GetLicenseInfo()
        {
            if (context == null)
            {
                context = StoreContext.GetDefault();
                // If your app is a desktop app that uses the Desktop Bridge, you
                // may need additional code to configure the StoreContext object.
                // For more info, see https://aka.ms/storecontext-for-desktop.
            }

            /*
             * StoreProductResult queryResult = await context.GetStoreProductForCurrentAppAsync();
             *
             * if (queryResult.Product != null)
             * {
             *  // The Store catalog returned an unexpected result.
             *  //textBlock.Text = "Something went wrong, and the product was not returned.";
             *  StoreProduct p = queryResult.Product;
             *  string desc = p.Description;
             *  foreach(StoreSku sku in p.Skus)
             *  {
             *      string s3 = sku.StoreId;
             *      string s2 = sku.Price.FormattedPrice;
             *      string s1 = sku.Title;
             *      string s = sku.Description;
             *  }
             *
             *  // Show additional error info if it is available.
             *  if (queryResult.ExtendedError != null)
             *  {
             *      //textBlock.Text += $"\nExtendedError: {queryResult.ExtendedError.Message}";
             *  }
             *
             * }
             *
             * GetProductInfo();
             *
             *
             * string[] productKinds = { "Durable", "Consumable", "UnmanagedConsumable" };
             * List<String> filterList = new List<string>(productKinds);
             * StoreProductQueryResult result = await context.GetAssociatedStoreProductsAsync(filterList);
             * foreach( KeyValuePair<string, StoreProduct> product in result.Products )
             * {
             *  string text = product.Key;
             *  StoreProduct prod = product.Value;
             *  string token = prod.InAppOfferToken;
             *  string storeid = prod.StoreId;
             * }*/

            //  workingProgressRing.IsActive = true;
            StoreAppLicense appLicense = await context.GetAppLicenseAsync();

            //  workingProgressRing.IsActive = false;

            if (appLicense == null)
            {
                // textBlock.Text = "An error occurred while retrieving the license.";
                return;
            }

            // Use members of the appLicense object to access license info...

            // Access the add on licenses for add-ons for this app.
            foreach (KeyValuePair <string, StoreLicense> item in appLicense.AddOnLicenses)
            {
                StoreLicense addOnLicense = item.Value;
                // Use members of the addOnLicense object to access license info
                // for the add-on...
                //addOnLicense.
                if (addOnLicense.IsActive)
                {
                    AdGrid.Visibility     = Visibility.Collapsed;
                    DrinkManager.IsAdFree = true;
                }
            }
        }