public StripeCardServiceTest()
        {
            this.service = new StripeCardService();

            this.createOptions = new StripeCardCreateOptions()
            {
                SourceToken = "tok_123",
            };

            this.updateOptions = new StripeCardUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new StripeCardListOptions()
            {
                Limit = 1,
            };
        }
Ejemplo n.º 2
0
        public ActionResult UpdateUserDetails(UserProfileEditModel userProfileModel)
        {
            if (ModelState.ContainsKey("SubscriptionModel.CardNumber"))
            {
                ModelState["SubscriptionModel.CardNumber"].Errors.Clear();
            }

            var serialization          = new Serialization();
            var userRegistration       = new UserRegistration();
            var objUserProfileDetails  = new List <UserProfileEditModel>();
            var userProfileEditModel   = new UserProfileEditModel();
            var subscriptionController = new SubscriptionController();
            var subscriptionModel      = userProfileModel.SubscriptionModel; //new SubscriptionModel();
            var HashCriteria           = new Hashtable();
            var HashCriteriaPassword   = new Hashtable();
            var actualCriteria         = string.Empty;
            var actualCriteriaPassword = string.Empty;
            var passwordIfCorrect      = false;

            HashCriteria.Add("ID", userProfileModel.ID);
            HashCriteria.Add("Name", userProfileModel.Name);
            HashCriteria.Add("Address", userProfileModel.Address);
            HashCriteria.Add("City", userProfileModel.City);
            HashCriteria.Add("StateName", userProfileModel.StateName);
            HashCriteria.Add("ZipCode", userProfileModel.ZipCode);
            HashCriteria.Add("CompanyName", userProfileModel.CompanyName);
            HashCriteria.Add("LicenceNumber", userProfileModel.LicenceNumber);
            HashCriteria.Add("PhoneNumber", userProfileModel.PhoneNumber);
            HashCriteria.Add("UserID", userID);
            userProfileEditModel.ProfileImage = userProfileModel.ProfileImage;
            userProfileEditModel.PhoneNumber  = userProfileModel.PhoneNumber;
            userProfileEditModel.Email        = userProfileModel.Email;
            userProfileEditModel.CompanyName  = userProfileModel.CompanyName;

            if (subscriptionModel != null)
            {
                subscriptionModel.ExpirationYearList  = new List <ExpirationYear>();
                subscriptionModel.CardType            = new List <PaymentCardTypes>();
                subscriptionModel.ExpirationMonthList = new List <ExpirationMonth>();
                subscriptionModel.ExpirationYearList  = subscriptionController.GetExpirationYear();
                subscriptionModel.CardType            = subscriptionController.GetPaymentCardType();
                subscriptionModel.ExpirationMonthList = subscriptionController.GetExpirationMonth();
            }

            userProfileEditModel.SubscriptionModel = subscriptionModel;
            ModelState.Remove("SecurityCode");

            if (string.IsNullOrWhiteSpace(userProfileModel.CurrentPassword) && !string.IsNullOrWhiteSpace(userProfileModel.Password) && !string.IsNullOrWhiteSpace(userProfileModel.ConfirmPassword))
            {
                ModelState.AddModelError("CurrentPassword", "Please Enter valid current password");
                return(View("UserProfile", userProfileModel));
            }

            if (ModelState.IsValid)
            {
                if (SessionController.UserSession.RoleType == "Admin")
                {
                    actualCriteria = serialization.SerializeBinary((object)HashCriteria);
                    var  result        = userRegistration.UpdateUserProfile(actualCriteria);
                    long updatedUserID = Convert.ToInt64(serialization.DeSerializeBinary(Convert.ToString(result)));
                    SaveProfileImage(userProfileModel.ID);
                    TempData["UserSuccess"] = "User details has been modified successfully..!";
                    return(View("UserProfile", userProfileModel));
                }
                //Check if entered password is exists or not
                HashCriteriaPassword.Add("UserID", userProfileModel.ID);
                actualCriteriaPassword = serialization.SerializeBinary((object)HashCriteriaPassword);
                var userResult = userRegistration.GetUserSpecificDetails(actualCriteriaPassword);
                objUserProfileDetails = (List <UserProfileEditModel>)(serialization.DeSerializeBinary(Convert.ToString(userResult)));
                var  UserProfileDetails = objUserProfileDetails.FirstOrDefault();
                bool isValidPassword    = false;
                if (!string.IsNullOrWhiteSpace(userProfileModel.CurrentPassword))
                {
                    isValidPassword = CipherTool.Verify(userProfileModel.CurrentPassword, Convert.ToString(UserProfileDetails.Password));
                }

                passwordIfCorrect = true;
                if (passwordIfCorrect)
                {
                    if (isValidPassword)
                    {
                        string newPassword = CipherTool.Encrypt(Convert.ToString(userProfileModel.Password));
                        HashCriteria.Add("Password", newPassword);
                    }

                    if (!string.IsNullOrWhiteSpace(userProfileModel.CurrentPassword) && !isValidPassword)
                    {
                        ModelState.AddModelError("CurrentPassword", "Current password is not correct, Please Enter valid current password");
                        return(View("UserProfile", userProfileModel));
                    }

                    actualCriteria = serialization.SerializeBinary((object)HashCriteria);
                    var result = userRegistration.UpdateUserProfile(actualCriteria);
                    SaveProfileImage(Convert.ToInt64(userProfileModel.ID));   // user id
                    int year = 0;
                    if (userProfileModel.SubscriptionModel != null)
                    {
                        if (userProfileModel.SubscriptionModel.ExpirationYear != 0)
                        {
                            var selectedItem = subscriptionModel.ExpirationYearList.Find(p => p.ID == userProfileModel.SubscriptionModel.ExpirationYear);
                            year = Convert.ToInt32(selectedItem.Year);
                        }
                    }

                    //Update the user Credit card details
                    string customerID = Convert.ToString(SessionController.UserSession.CustomerID);
                    if (customerID != null && customerID != "" && (SessionController.UserSession.IsPaid = true))
                    {
                        try
                        {
                            var            customerService = new StripeCustomerService();
                            StripeCustomer stripeCustomer  = customerService.Get(customerID);
                            var            myCard          = new StripeCardUpdateOptions();
                            if (userProfileModel.SubscriptionModel.NameOnCard != null)
                            {
                                myCard.Name = userProfileModel.SubscriptionModel.NameOnCard;
                            }
                            myCard.ExpirationYear  = year;
                            myCard.ExpirationMonth = userProfileModel.SubscriptionModel.ExpirationMonth;
                            myCard.AddressState    = userProfileModel.SubscriptionModel.State;
                            myCard.AddressCity     = userProfileModel.SubscriptionModel.City;
                            myCard.AddressZip      = userProfileModel.SubscriptionModel.Zip;
                            myCard.AddressLine1    = userProfileModel.SubscriptionModel.BillingAddress;
                            var        cardService = new StripeCardService();
                            StripeCard stripeCard  = cardService.Update(customerID, stripeCustomer.DefaultSourceId, myCard); // optional isRecipient
                        }
                        catch (Exception ex)
                        {
                            ModelState.AddModelError("", ex.Message);
                            return(View("UserProfile", userProfileModel));
                        }
                    }
                    TempData["UserSuccess"] = "User details has been modified successfully..!";
                    return(RedirectToAction("UserProfile", new
                    {
                        passwordIfCorrect = passwordIfCorrect
                    }));
                }
                else
                {
                    passwordIfCorrect = false;
                }
            }

            return(View("UserProfile", userProfileModel));
        }