コード例 #1
0
        public SubscriptionPlans GetPlanDetails(Hashtable subscriptionCriteria)
        {
            DBUtility objUtility = new DBUtility();

            _cmd = new SqlCommand();
            var _db  = new DBUtility();
            var temp = new SubscriptionPlans();
            var _dt  = new DataTable();

            _cmd.CommandType = CommandType.StoredProcedure;
            _cmd.CommandText = "GP_SP_GetPlanDetails";

            _cmd.Parameters.AddWithValue("@ID", Convert.ToInt64(subscriptionCriteria["ID"]));

            _dt = _db.FillDataTable(_cmd, _dt);
            if (_dt.Rows.Count > 0)
            {
                foreach (DataRow dr in _dt.Rows)
                {
                    temp.SubscriptionPlanID = Convert.ToString(dr["SubscriptionPlanID"]);
                    temp.Amount             = Convert.ToDouble(dr["Amount"]);
                }
            }
            return(temp);
        }
コード例 #2
0
        public ActionResult Plans()
        {
            var CurrentPlanId = this._subscription.Find(x => x.UserId == UserId).OrderByDescending(x => x.Id).FirstOrDefault().PlanId;
            var data          = this._plans.FindAll()
                                .Select(x => {
                var plans = new SubscriptionPlans()
                {
                    Id               = x.PlanId,
                    PlanName         = x.PlanName,
                    Amount           = x.Cost,
                    DaysValid        = x.DaysValid.ToString(),
                    SupportType      = x.Support,
                    TestAccessbility = x.TestsAccessibility,
                    IsActive         = x.PlanId == CurrentPlanId? true : false
                };
                return(plans);
            });

            return(View(data.ToList()));
        }
コード例 #3
0
        public async Task <ActionResult> Charge(SubscriptionModel model)
        {
            var    subscriptionBA   = new Subscription();
            var    serialization    = new Serialization();
            var    status           = false;
            var    HashCriteria     = new Hashtable();
            var    actualCriteria   = string.Empty;
            var    HashCriteriaPlan = new Hashtable();
            string actualCriteriaPlan;

            string userID = Convert.ToString(SessionController.UserSession.UserId);

            SubscriptionModel subscriptionModel = new SubscriptionModel();

            subscriptionModel.CardType            = GetPaymentCardType();
            subscriptionModel.ExpirationYearList  = GetExpirationYear();
            subscriptionModel.ExpirationMonthList = GetExpirationMonth();

            if (model.RoleID == 2)
            {
                ViewBag.SubscriptionTitle = "Find unlimited investment opportunities for $399 per month.";
            }
            else if (model.RoleID == 3)
            {
                ViewBag.SubscriptionTitle = "List unlimited investment opportunities for $399 per month.";
            }

            if (model.Token != null)
            {
                ModelState.Remove("State");
                ModelState.Remove("BillingAddress");
                ModelState.Remove("Zip");
                ModelState.Remove("SecurityCode");

                if (!ModelState.IsValid)
                {
                    return(PartialView("_PaymentSubscriptionPopup", subscriptionModel));
                }
                //Check if the user is already a custome ron stripe or not?
                var customer_ID = Convert.ToString(SessionController.UserSession.CustomerID);
                if (customer_ID != null && customer_ID != "")
                {
                    model.CustomerID = customer_ID;
                }
                else
                {
                    // 1. Create customer in stripe
                    var customerID = await CreateCustomer(model.Token);

                    model.CustomerID = customerID;
                }
                // 2. Get the plans from the Plans table
                HashCriteriaPlan.Add("CycleInMonth", 1);
                actualCriteriaPlan = serialization.SerializeBinary((object)HashCriteriaPlan);

                var result = subscriptionBA.GetPlanDetails(actualCriteriaPlan);
                SubscriptionPlans subscriptionPlans = (SubscriptionPlans)(serialization.DeSerializeBinary(Convert.ToString(result)));

                var planID = subscriptionPlans.ID;
                var subscription_PlanID = subscriptionPlans.SubscriptionPlanID;
                var amount = subscriptionPlans.Amount;

                // 3. subscription aginst that plan
                var subscriptionService = new StripeSubscriptionService();
                StripeSubscription stripeSubscription = subscriptionService.Create(model.CustomerID, subscription_PlanID);

                //4. Make the payment
                model.Amount = amount;

                var chargeId = await ProcessPayment(model);

                if (chargeId != null)
                {
                    DateTime billingDate = DateTime.Now;

                    // 5. Save detals in the subscription table with amount and token of charge
                    HashCriteria.Add("Token", model.Token);
                    HashCriteria.Add("UserID", userID);
                    HashCriteria.Add("Amount", model.Amount);
                    HashCriteria.Add("BillingDate", Convert.ToString(billingDate.ToString("dd/MM/yyyy")));
                    HashCriteria.Add("CustomerID", model.CustomerID);
                    HashCriteria.Add("PlanID", planID);
                    HashCriteria.Add("SubscriptionID", stripeSubscription.Id);
                    HashCriteria.Add("ChargeID", chargeId);

                    actualCriteria = serialization.SerializeBinary((object)HashCriteria);

                    var  subscriptionstatus = subscriptionBA.SaveSubscriptionData(actualCriteria);
                    long subscriptionID     = Convert.ToInt64(serialization.DeSerializeBinary(Convert.ToString(subscriptionstatus)));

                    if (subscriptionID > 0)
                    {
                        // 6. Update the user role as Investor/Broker
                        status = UpdateUserRole(model.RoleID);
                        //Make the user flag as paid
                        SessionController.UserSession.IsPaid = true;

                        //initialize userAuthModel
                        LoginController loginController = new LoginController();
                        var             loginBA         = new Login();
                        LoginModel      loginModel      = new LoginModel();
                        HashCriteria.Add("UserName", SessionController.UserSession.EmailAddress);
                        actualCriteria = serialization.SerializeBinary((object)HashCriteria);
                        var rec = loginBA.ValidateLogin(actualCriteria);
                        var loginModelDetails = (LoginModel)(serialization.DeSerializeBinary(Convert.ToString(rec)));

                        AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie);

                        var userSession = loginController.Authenticate(loginModelDetails);
                        if (userSession != null)
                        {
                            var identity = new ClaimsIdentity(AuthenticationHelper.CreateClaim(userSession,
                                                                                               userSession.UserRole),
                                                              DefaultAuthenticationTypes.ApplicationCookie
                                                              );
                            AuthenticationManager.SignIn(new AuthenticationProperties()
                            {
                                AllowRefresh = true,
                                IsPersistent = true,
                                ExpiresUtc   = DateTime.UtcNow.AddHours(1)
                            }, identity);
                        }

                        if (model.RoleID == 2)
                        {
                            return(RedirectToAction("Investor", "Dashboard"));
                        }
                        if (model.RoleID == 3)
                        {
                            return(RedirectToAction("Broker", "Dashboard"));
                        }
                    }
                }
            }
            return(PartialView("_PaymentSubscriptionPopup", subscriptionModel));
        }