예제 #1
0
        public JsonResult UpdateUserEmail(EmailViewModel model)
        {
            String FirstName = HttpContext.User.Identity.Name;
            String Email     = model.Email.Trim();
            String msg       = "";

            if (!String.IsNullOrWhiteSpace(Email))
            {
                if (!String.IsNullOrWhiteSpace(SessionData.StripeCustId))
                {
                    msg = pdata.UpdateUserProfile(SessionData.UserID, Email);
                    if (msg == "")
                    {
                        var customerOptions = new StripeCustomerUpdateOptions
                        {
                            Email = Email
                        };
                        StripeHelper.UpdateCustomer(SessionData.StripeCustId, customerOptions);
                        SessionData.Email = Email;
                        var res = dashboardData.GetAlertData(SessionData.UserID);
                        SessionData.AlertCount = res.Count;
                        String _url         = "Settings/UpdateUserEmail";
                        String emailConfirm = ealert.SendActivationEmail(SessionData.UserID, FirstName, SessionData.LastName, Email, _url, AccounType.MppUser);
                        msg += emailConfirm;
                    }
                }
                else
                {
                    msg = Constant.STRIPE_ID_NOTFOUND;
                }
            }
            else
            {
                msg = Constant.EMAIL_NOTFOUND;
            }
            return(new JsonResult()
            {
                Data = msg, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
예제 #2
0
        //Billing
        public ActionResult CreateStripeCustomer(string token)
        {
            var          email           = Session["Email"].ToString();
            var          subscription    = new StripeSubscription();
            var          customerDetails = new StripeCustomer();
            var          userInfo        = new UpdateUserInfo();
            string       msg             = "";
            var          cardStatus      = 0;
            DataTable    userData;
            StripeCharge charge = null;

            try
            {
                if (token != null)
                {
                    var ds = new AccountData().ValidateEmailAndGetUserinfo(email);
                    userData = ds.Tables[0];
                    var custID = Convert.ToString(userData.Rows[0]["stp_custId"]);
                    if (userData.Rows.Count > 0 && !string.IsNullOrWhiteSpace(custID))                                 //update
                    {
                        var customerUpdateOptions = new StripeCustomerUpdateOptions
                        {
                            Email       = email,
                            Description = Session["FirstName"] + " " + Session["LastName"],
                            SourceToken = token
                        };

                        //updated customer
                        customerDetails = StripeHelper.UpdateCustomer(custID, customerUpdateOptions);

                        //add a test charge for $1
                        var makeTestCharge = new StripeChargeCreateOptions
                        {
                            CustomerId  = customerDetails.Id,
                            Amount      = 100,
                            Currency    = "usd",
                            Description = "Card verification charge",
                            SourceTokenOrExistingSourceId = customerDetails.DefaultSourceId
                        };
                        charge = StripeHelper.MakePayment(makeTestCharge);
                        if (charge != null)
                        {
                            var refund = StripeHelper.RefundCharge(charge.Id);
                            cardStatus      = 1;
                            userInfo.CustId = customerDetails.Id;
                            userInfo.CardId = customerDetails.DefaultSourceId;
                            userInfo.UserId = Convert.ToInt32(Session["UserID"]);
                            AccountData.UpdateStripeCardData(userInfo);
                            if ((SessionData.PlanID == 1 && SessionData.TrialEndOn < DateTime.Now) || SessionData.PlanStatus == 0) //When trail was expired || Unsubscribed and adding a card since payments are not succesfull
                            {
                                msg = StripeServices.SubscribePlan(SessionData.StripeCustId, userInfo.CardId);
                            }
                            if (String.IsNullOrWhiteSpace(msg))
                            {
                                SessionData.PlanStatus   = 1; //Default subscription
                                SessionData.StripeCustId = customerDetails.Id;
                                SessionData.StripeCardId = customerDetails.DefaultSourceId;
                            }
                        }
                        else
                        {
                            StripeHelper.DeleteCard(customerDetails.DefaultSourceId, custID);
                            cardStatus = 0;
                        }
                    }
                    customerDetails = StripeHelper.GetStripeCustomer(customerDetails.Id);
                }

                var respo = new { Status = cardStatus, Message = msg, CustomerDetails = customerDetails };
                return(Json(respo, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                LogFile.WriteLog("CreateCustomer - " + ex.Message.ToString());
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
        }