Beispiel #1
0
        // 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());
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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);
                }
            }
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public ActionResult Subscribe(TestProject.Models.Subscribe subscribe, string confirmKey)
        {
            ChargifyConnect chargify = ChargifyTools.Chargify;
            string          plan     = subscribe.plan;
            bool            isCredit = subscribe.hasCreditCard || subscribe.creditcard.requireCredit;//ChargifyTools.RequireCreditCard(subscribe.plan);

            try
            {
                if (ChargifyTools.IsChargifyProduct(subscribe.plan))
                {
                    ViewBag.confirmKey = confirmKey;
                    ViewBag.plan       = subscribe.plan;
                    if (ValidatePassword(subscribe.password) == false)
                    {
                        //ViewBag.contactGenderId = new SelectList(db.contactGender.ToList(), "contactGenderId", "name");
                        ViewBag.Message = "Error password, you need a format that contains capital letters and numbers, example: Michael7.";
                        ViewBag.plan    = subscribe.plan;

                        return(View(subscribe));
                    }

                    userLogin user = new userLogin();
                    contact   cont = new contact();
                    tenant    tnt  = new tenant();
                    //----------------------------------------------------------------------------------------------------------------
                    //----------------------------------------------------------------------------------------------------------------
                    //----------------------------------------------------------------------------------------------------------------

                    tnt.tenantSubscriptionPlanId = (from pl in db.tenantSubscriptionPlan
                                                    where pl.code.ToLower().Equals(plan.ToLower())
                                                    select pl.tenantSubscriptionPlanId).FirstOrDefault();
                    tnt.active           = true;
                    tnt.allocatedUsers   = 1; //cantidad de usuarios asignados
                    tnt.billingRefNumber = Guid.NewGuid().ToString();
                    tnt.companyName      = subscribe.company;
                    tnt.companyURL       = "N/A";
                    tnt.database         = "TestProject";
                    tnt.tenantStatusId   = 2;
                    tnt.tenantSourceId   = 2;
                    if (isCredit)
                    {
                        tnt.tenentBillingTypeId = 1;
                    }
                    else
                    {
                        tnt.tenentBillingTypeId = 2;
                    }

                    /****** Valores quemados de campos auditoria*****/
                    tnt.updatedById    = 0;
                    tnt.createdById    = TntIdTestProject; // Id tenant TestProject
                    tnt.modifyDateTime = new DateTime(1900, 1, 1, 0, 0, 0);
                    tnt.insertDateTime = DateTime.Now;
                    /****** Valores quemados de campos auditoria*****/

                    db.tenant.Add(tnt);
                    db.SaveChanges();



                    var city = db.genCity
                               .Include(x => x.genState.genContry)
                               .SingleOrDefault(x => x.genCityId == Convert.ToInt32(subscribe.genCityId));
                    if (isCredit)
                    {
                        contactPhone phone = new contactPhone
                        {
                            active             = true,
                            number             = subscribe.phoneNumber,
                            contactId          = cont.contactId,
                            contactPhoneTypeId = 1,
                            tenantId           = tnt.tenantId,
                            updatedById        = 0,
                            createdById        = TntIdTestProject, // Id tenant TestProject
                            modifyDateTime     = new DateTime(1900, 1, 1, 0, 0, 0),
                            insertDateTime     = DateTime.Now
                        };

                        db.contactPhone.Add(phone);
                        db.SaveChanges();

                        cont.preferredBillAddressId = address.contactAddressId;
                        cont.preferredPhoneId       = phone.contactPhoneId;
                        db.Entry(cont).State        = EntityState.Modified;
                        db.SaveChanges();
                    }



                    /*** cosas de chargify!!!*/
                    CustomerAttributes customerInformation = new CustomerAttributes();
                    customerInformation.FirstName    = subscribe.firstName;
                    customerInformation.LastName     = subscribe.lastName;
                    customerInformation.Organization = subscribe.company;
                    customerInformation.Email        = subscribe.email;
                    // Create a new guid, this would be the Membership UserID if we were creating a new user simultaneously
                    customerInformation.SystemID = tnt.billingRefNumber;


                    ISubscription newSubscription = null;
                    string        productHandle   = plan;

                    if (isCredit)
                    {
                        CreditCardAttributes creditCardInfo = new CreditCardAttributes();

                        creditCardInfo.FullNumber      = subscribe.creditcard.creditCardNumber;
                        creditCardInfo.CVV             = subscribe.creditcard.cvv;
                        creditCardInfo.ExpirationMonth = subscribe.creditcard.ExpireMonth;
                        creditCardInfo.ExpirationYear  = subscribe.creditcard.ExpireYear;

                        creditCardInfo.BillingAddress = subscribe.street;
                        creditCardInfo.BillingCity    = city.City;//subscribe.city;
                        creditCardInfo.BillingState   = city.genState.State;
                        creditCardInfo.BillingZip     = subscribe.postalCode;
                        creditCardInfo.BillingCountry = city.genState.genContry.contry;

                        newSubscription = chargify.CreateSubscription(productHandle, customerInformation, creditCardInfo);
                    }
                    else
                    {
                        newSubscription = chargify.CreateSubscription(productHandle, customerInformation);
                    }
                }
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                       eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                           ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            catch (Exception e)
            {
                return(View(subscribe));
            }


            return(View(subscribe));
        }