public ActionResult UserActivation(String ActivationCode) { string result = ""; var userInfo = new UpdateUserInfo(); if (!String.IsNullOrEmpty(ActivationCode)) { var dr = userregistrationData.AccountConfirmation(ActivationCode); if (dr != null) { result = "true"; String StripeCustmId = Convert.ToString(dr["stp_custId"]); var customerOptions = new StripeCustomerCreateOptions { Email = Convert.ToString(dr["Email"]), Description = Convert.ToString(dr["name"]), }; var customerDetails = StripeHelper.AddCustomer(customerOptions, StripeCustmId); if (customerDetails != null) { var planId = (int)Statics.StripePlans.Trial; var subscription = StripeHelper.Subscription(customerDetails.Id, new StripeSubscriptionCreateOptions { PlanId = planId.ToString() }, out result); if (String.IsNullOrEmpty(result)) { userInfo.CustId = customerDetails.Id; userInfo.UserId = Convert.ToInt32(dr["id"]); userInfo.PlanId = planId; userInfo.PlanStartDate = Convert.ToDateTime(subscription.CurrentPeriodStart).ToString(); userInfo.TrialEndDate = subscription.TrialEnd.ToString(); userInfo.Amount = subscription.StripePlan.Amount.ToString(); userInfo.PlanEndDate = Convert.ToDateTime(subscription.CurrentPeriodEnd).ToString(); AccountData.UpdateStripeData(userInfo); } else { result = "Subscription error, please contact Administrator"; } } } else { result = "false"; } } ViewBag.Confirmation = result; return(View("Login")); }
public static void RenewPlan() { int UserId = 0; try { var subs = ServicesData.GetSubscribers(); int plan; if (subs.Rows.Count > 0) { foreach (DataRow row in subs.Rows) { String msg = ""; String CustomerId = row["stp_custId"].ToString(); String CardId = row["stp_cardId"].ToString(); UserId = Convert.ToInt32(row["MppUserID"]); if (!String.IsNullOrWhiteSpace(CustomerId) && !String.IsNullOrWhiteSpace(CardId)) { var profile = APIData.GetUserProfileForSkuData(UserId); if (profile.Rows.Count > 0) { DataRow dr = profile.Rows[0]; String ProfileId = Convert.ToString(dr["ProfileId"]); DateTime LastUpdatedOn = Convert.ToDateTime(dr["AccessTokenUpdatedOn"]); var Auth = new AuthorizationModel() { access_token = Convert.ToString(dr["AccessToken"]), refresh_token = Convert.ToString(dr["RefreshToken"]), token_type = Convert.ToString(dr["TokenType"]), expires_in = Convert.ToInt32(dr["TokenExpiresIn"]) }; var reportApi = new ReportsAPI(); var skuCount = AccountData.UserSkuCount(UserId); if (String.IsNullOrWhiteSpace(msg)) { if (skuCount > 250) { plan = GetCustomPlan(skuCount); } else { plan = GetPlanBySku(skuCount); } var subsPlan = new StripeSubscription(); var subService = StripeHelper.GetSubscription(CustomerId); if (subService != null) { subsPlan = StripeHelper.UpdateSubscription(CustomerId, subService.Id, new Stripe.StripeSubscriptionUpdateOptions { PlanId = plan.ToString(), Prorate = false }, out msg); } else { subsPlan = StripeHelper.Subscription(CustomerId, new Stripe.StripeSubscriptionCreateOptions { PlanId = plan.ToString() }, out msg); } if (String.IsNullOrWhiteSpace(msg)) { UpdateUserInfo userInfo = new UpdateUserInfo { Amount = ((double)(subsPlan.StripePlan.Amount) / 100).ToString(), CardId = CardId, CustId = CustomerId, UserId = UserId, PlanId = plan, EndedAt = subsPlan.CurrentPeriodEnd.ToString(), PlanStartDate = subsPlan.CurrentPeriodStart.ToString(), PlanEndDate = subsPlan.CurrentPeriodEnd.ToString(), TrialEndDate = row["TrailEndDate"].ToString() }; ServicesData.UpdateStripeData(userInfo); } else { LogAPI.WriteLog("RenewPlan - " + msg, UserId.ToString()); } } else { LogAPI.WriteLog("RenewPlan - " + msg, UserId.ToString()); } } } } } } catch (Exception ex) { LogAPI.WriteLog("RenewPlan - " + ex.Message, UserId.ToString()); } }
public static string SubscribePlan(String CustomerId, String CardId) { int plan; String msg = ""; try { Int32 UserId = SessionData.UserID; DateTime Trialdate = SessionData.TrialEndOn; if (!String.IsNullOrWhiteSpace(CardId)) { var profile = APIData.GetUserProfileForSkuData(UserId); if (profile.Rows.Count > 0) { DataRow dr = profile.Rows[0]; String ProfileId = Convert.ToString(dr["ProfileId"]); DateTime LastUpdatedOn = Convert.ToDateTime(dr["AccessTokenUpdatedOn"]); var Auth = new AuthorizationModel() { access_token = Convert.ToString(dr["AccessToken"]), refresh_token = Convert.ToString(dr["RefreshToken"]), token_type = Convert.ToString(dr["TokenType"]), expires_in = Convert.ToInt32(dr["TokenExpiresIn"]) }; var reportApi = new ReportsAPI(); var skuCount = AccountData.UserSkuCount(UserId); if (String.IsNullOrWhiteSpace(msg)) { var subsPlan = new StripeSubscription(); if (skuCount > 250) { plan = GetCustomPlan(skuCount); } else { plan = GetPlanBySku(skuCount); } var subService = StripeHelper.GetSubscription(CustomerId); if (subService != null) { subsPlan = StripeHelper.UpdateSubscription(CustomerId, subService.Id, new Stripe.StripeSubscriptionUpdateOptions { PlanId = plan.ToString(), Prorate = false }, out msg); } else { subsPlan = StripeHelper.Subscription(CustomerId, new Stripe.StripeSubscriptionCreateOptions { PlanId = plan.ToString() }, out msg); } if (String.IsNullOrWhiteSpace(msg)) { UpdateUserInfo userInfo = new UpdateUserInfo { Amount = ((double)(subsPlan.StripePlan.Amount) / 100).ToString(), CardId = CardId, CustId = CustomerId, UserId = UserId, PlanId = plan, EndedAt = subsPlan.CurrentPeriodEnd.ToString(), PlanStartDate = subsPlan.CurrentPeriodStart.ToString(), PlanEndDate = subsPlan.CurrentPeriodEnd.ToString(), TrialEndDate = Trialdate.ToString() }; msg = AccountData.UpdateStripeData(userInfo); if (msg == "") { SessionData.PlanID = plan; } } else { LogAPI.WriteLog("SubscribePlan - " + msg, SessionData.SellerName); } } } else { msg = Constant.PROFILE_NOTFOUND; } } } catch (Exception ex) { msg = ex.Message; LogFile.WriteLog("SubscribePlan - " + msg, SessionData.SellerName); } return(msg); }