// GET: Subscription public ActionResult ReactivationInstructions() { tenant tenant = (tenant)TempData["tenant"]; ViewBag.Message = (string)TempData["Message"]; bool hasPaymentInfo = false; if (tenant == null) { //TempData["Message"] = "Your user is not a customer"; return(RedirectToAction("Login", "Home", new { area = "" })); } ChargifyConnect chargify = ChargifyTools.Chargify; ISubscription subscription = ChargifyTools.getSubscription(tenant.billingRefNumber); if (subscription == null) { TempData["Message"] = "Your user is not a customer"; return(RedirectToAction("Login", "Home", new { area = "" })); } if (subscription.PaymentProfile != null) { hasPaymentInfo = true; } ViewBag.hasPaymentInfo = hasPaymentInfo; ViewBag.tenantId = tenant.tenantId; ViewBag.paymentUrl = chargify.GetPrettySubscriptionUpdateURL("", "", subscription.SubscriptionID); return(View()); }
public ActionResult Reactivation(int tenantId) { if (tenantId <= 0) { return(RedirectToAction("Login", "Home", new { area = "" })); } tenant tenant = db.tenant.Find(tenantId); if (tenant == null) { return(RedirectToAction("Login", "Home", new { area = "" })); } ChargifyConnect chargify = ChargifyTools.Chargify; ISubscription currentSubscription = ChargifyTools.getSubscription(tenant.billingRefNumber); if (currentSubscription == null) { return(RedirectToAction("Login", "Home", new { area = "" })); } if (currentSubscription.PaymentProfile != null) { try { ISubscription reactivatedSubscription = chargify.ReactivateSubscription(currentSubscription.SubscriptionID); if (reactivatedSubscription.State == SubscriptionState.Active) { TempData["Message"] = "Your subscription has been successfully reactivated.\n please login again"; return(RedirectToAction("Login", "Home", new { area = "" })); } else { TempData["Message"] = "Your subscription couldn't be activated.\n Follow the instructions and try again"; TempData["tenant"] = tenant; //return RedirectToAction("Login", "Home", new { area = "" }); return(RedirectToAction("ReactivationInstructions")); } } catch (Exception) { TempData["Message"] = "Your subscription couldn't be activated.\n Follow the instructions and try again"; TempData["tenant"] = tenant; //return RedirectToAction("Login", "Home", new { area = "" }); return(RedirectToAction("ReactivationInstructions")); } } else { TempData["Message"] = "You haven't set your payment information.\n Follow the instructions and try again"; TempData["tenant"] = tenant; return(RedirectToAction("ReactivationInstructions", tenant)); } return(View()); }
public void AddusersBilling(int count) { Sqrely_Identity identity = clsCommon.getIdentity(); if (count > 0) { try { ChargifyConnect Chargify = clsCommon.Chargify; // Load the customer information for the current user //ICustomer customer = Chargify.Find<Customer>(clsCommon.getCurrentUserBillingRefNumber()); // Alternate syntax // Dim customer As ICustomer = Chargify.LoadCustomer(clsCommon.getCurrentUserBillingRefNumber()) tenant currentenant = db.tenant.Find(identity.tenatId); ISubscription currentSubscription = ChargifyTools.getSubscription(currentenant.billingRefNumber); if (currentSubscription != null) { int componentID = clsCommon.getComponentId(currentSubscription.Product.Handle); if (componentID > 0) { //Update the amount allocated //Dim info As IComponentAttributes = Chargify.UpdateComponentAllocationForSubscription(currentSubscription.SubscriptionID, componentID, (CInt(noUsersTb.Text) - 1)) //Dim info As IComponentAttributes = Chargify.UpdateComponentAllocationForSubscription(currentSubscription.SubscriptionID, componentID, newQuantity) //Chargify.CreateComponentAllocation(currentSubscription.SubscriptionID, componentID, count, "New Users", ComponentUpgradeProrationScheme.No_Prorate, ComponentDowngradeProrationScheme.No_Prorate); if (currentSubscription.State == SubscriptionState.Trialing) { Chargify.CreateComponentAllocation(currentSubscription.SubscriptionID, componentID, count, "New Users", ComponentUpgradeProrationScheme.No_Prorate, ComponentDowngradeProrationScheme.No_Prorate); } else { Chargify.CreateComponentAllocation(currentSubscription.SubscriptionID, componentID, count, "New Users", ComponentUpgradeProrationScheme.Prorate_Attempt_Capture, ComponentDowngradeProrationScheme.Prorate); } } //Dim sqltext As String = "UPDATE tenant SET modifyDateTime=getdate(), " & //" allocatedUsers = @allocatedUsers " & //" WHERE billingRefNumber = @billingRefNumber" //ApplicationBlocks.SqlHelper.ExecuteNonQuery(clsCommon.connString, // System.Data.CommandType.Text, sqltext, // New System.Data.SqlClient.SqlParameter("@allocatedUsers", noUsersTb.Text), // New System.Data.SqlClient.SqlParameter("@billingRefNumber", currentSubscription.Customer.SystemID)) //tenant tenant = default(tenant); //tenant = (from t in db.tenantwhere t.billingRefNumber.Equals(currentSubscription.Customer.SystemID)).FirstOrDefault(); currentenant.allocatedUsers = count + 1; //Dim identity As SQRely_Admin.SqrelySecurity.Sqrely_Identity //identity = HttpContext.Current.User.Identity currentenant.updatedById = identity.Id; currentenant.modifyDateTime = DateTime.Now; db.Entry(currentenant).State = EntityState.Modified; db.SaveChanges(); //LoadSubscriptionInfo(); //usageResultLtr.Text = string.Format("Current Allocated users ({0}).", noUsersTb.Text); //If newAddedUsers > 0 Then // ' Charge Existing Users on new account // Dim amount As Decimal = newAddedUsers * currentSubscription.ProductPrice // Chargify.CreateCharge(currentSubscription.SubscriptionID, amount, String.Format("New Users Added: {0}", newAddedUsers.ToString()), True) //End If //' Get the amount allocated //Dim newInfo As IComponentAttributes = Chargify.GetComponentInfoForSubscription(currentSubscription.SubscriptionID, componentID) //If newInfo IsNot Nothing Then // ' Charged OK // Me.usageResultLtr.Text = String.Format("Current additional users ({0}).", noUsersTb.Text) // ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "highlight", "HighlightResult();", True) //Else // ' Not OK // Me.usageResultLtr.Text = String.Format("Error. ({0})", DateTime.Now.ToString()) // ScriptManager.RegisterStartupScript(Me.Page, GetType(Page), "highlight", "HighlightResult();", True) //End If } } catch (Exception ex) { //ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "error", "alert('" + ex.Message + "');", true); } } }
public JsonResult GetInfoClient() { var result = Json("", JsonRequestBehavior.AllowGet); int currentuser = clsCommon.getIdentity().Id; int tenantid = clsCommon.getIdentity().tenatId; tenant ctenant = (from t in db.tenant where t.tenantId == tenantid select t).FirstOrDefault(); ChargifyConnect chargify = clsCommon.Chargify; int usercount = 1; bool validpaid = false; ISubscription currentSubscription = ChargifyTools.getSubscription(ctenant.billingRefNumber); if (currentSubscription != null) { int componentId = clsCommon.getComponentId(currentSubscription.Product.Handle); if (currentSubscription.State == SubscriptionState.Active) { if (componentId > 0) { IComponentAttributes newInfo = chargify.GetComponentInfoForSubscription(currentSubscription.SubscriptionID, componentId); usercount = Convert.ToInt32(newInfo.AllocatedQuantity + 1); } } validpaid = true; } List <userLogin> users = (from u in db.userLogin where u.tenantId == tenantid && u.active == true select u).ToList(); var tenantinfo = (from obj in db.vw_Tenant where obj.tenantId == tenantid select new { paid = validpaid, Companyname = obj.companyName, AllocatedUsers = obj.allocatedUsers, address = obj.Address, owneremail = obj.email, codigoarea = obj.countryCode, phone = obj.number, ownerurl = obj.companyURL, //userscount = (from u in db.userLogin // join ct in db.contact // on u.contactId // equals ct.contactId // where u.tenantId == tenantid && u.active == true // select new // { // name = ct.name, // alias = u.userName, // email = ct.email // }).ToList(), tenantconfigs = (from obj2 in db.genConfigName where obj2.genConfigNameGroupId == 1 && obj2.active == true orderby obj2.code ascending select new { configNameid = obj2.genConfigNameId, parameter = "", active = obj2.active, code = obj2.code }).ToList(), settconfigs = (from obj3 in db.genConfigName where obj3.genConfigNameGroupId == 2 && obj3.active == true orderby obj3.code ascending select new { configNameid = obj3.genConfigNameId, parameter = "", active = obj3.active, code = obj3.code }).ToList(), languanges = (from obj4 in db.genLanguage select new { obj4.name }).ToList(), currencies = (from obj5 in db.genCurrency select new { obj5.name, code = obj5.code }).ToList(), regions = (from obj6 in db.genRegion select new { obj6.name }).ToList(), Timezones = (from obj7 in db.genTimezone select new { obj7.timeZone }).ToList(), defaultconfigs = (from dcn in db.genConfigName join dc in db.genConfig on dcn.genConfigNameId equals dc.genConfigNameId where dc.tenantId == tenantid && dcn.genConfigNameGroupId == 1 && dcn.active == true orderby dcn.code ascending select new { dcn.code, dc.parameter }).ToList(), settdefaultconfigs = (from dcn in db.genConfigName join dc in db.genConfig on dcn.genConfigNameId equals dc.genConfigNameId where dc.tenantId == tenantid && dcn.genConfigNameGroupId == 2 && dcn.active == true orderby dcn.code ascending select new { dcn.code, dc.parameter }).ToList(), userroles = (from urol in db.userLoginRole where (urol.userLoginRoleId != 1 && urol.userLoginRoleId != 2)select new { name = urol.name, id = urol.userLoginRoleId }).ToList() }).FirstOrDefault(); if (tenantinfo != null) { result = Json(tenantinfo, JsonRequestBehavior.AllowGet); } return(result); }