Example #1
0
 protected void btnCancelMyAccount_Click(object sender, EventArgs e)
 {
     if (ChargifyProvider.DeleteCustomerSubscription(Chargify, OrganizationId, InstanceId))
     {
         InstanceProvider.UpdateInstance(UserContext.Current.Instance, CreditCardStatus.NotRegistered);
         Response.Redirect(ResourceProvider.AccountSettingsVirtualPath + "?st=cancel");
     }
     else
     {
         this.MasterPage.MessageType = NoticeMessageType.Error;
         this.MasterPage.Message     = "Your Credit Card Registration was not deleted!";
     }
 }
Example #2
0
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            m_Status = CreditCardRegistrationStatus.Ok;
            string      error = string.Empty;
            UserContext user  = UserContext.Current;

            StatusMessageBox.Visible     = true;
            StatusMessageBox.MessageType = NoticeMessageType.Error;

            if (!ChargifyProvider.RegisterCreditCard(ChargifyProvider.CreateChargify()
                                                     , user.OrganizationId, user.InstanceId, user.Organization.Name, user.Instance.Name, user.Email, user.FirstName, user.LastName
                                                     , NumberTextBox.Text, ExpirationMonthTextBox.Text, ExpirationYearTextBox.Text, 1
                                                     , out error))
            {
                if (NumberTextBox.Text.Contains("XXXX"))
                {
                    NumberTextBox.Text          = string.Empty;
                    ExpirationMonthTextBox.Text = string.Empty;
                    ExpirationYearTextBox.Text  = string.Empty;

                    StatusMessageBox.Description = Resources.CreditCardRegistrationControl_StatusMessageBox_Description;
                }

                StatusMessageBox.Message = error;

                m_Status = CreditCardRegistrationStatus.Error;

                if (UpdateClick != null)
                {
                    UpdateClick(this, e);
                }
            }
            else
            {
                InstanceProvider.UpdateInstance(user.Instance, CreditCardStatus.Registered);

                if (NumberTextBox.Text.Contains("XXXX"))
                {
                    m_Status = CreditCardRegistrationStatus.Reactivated;
                }

                if (UpdateClick != null)
                {
                    UpdateClick(this, e);
                }
                else
                {
                    Response.Redirect(Request.Path);
                }
            }
        }
Example #3
0
        private void InitBillingControls()
        {
            DateTime?_expDate = UserContext.Current.Organization.ExpirationTime;

            ISubscription _custSubscr = ChargifyProvider.GetCustomerSubscription(Chargify, OrganizationId, InstanceId);

            if (_custSubscr != null && _custSubscr.CreditCard != null)
            {
                _expDate = _custSubscr.CurrentPeriodEndsAt;
                if (!IsPostBack)
                {
                    SettingCollection paidSettings = SettingProvider.GetAllPricedSettings(OrganizationId, InstanceId);
                    ChargifyProvider.UpdateSubscriptionAllocations(Chargify, _custSubscr.SubscriptionID, UserContext.Current.Instance, paidSettings, paidSettings);
                }
                TotalAmount    = m_TotalSum;
                SubscriptionId = _custSubscr.SubscriptionID;
                lCCStatus.Text = "Credit Card Registered and " + _custSubscr.State.ToString() + ".";
                TimeSpan _dateDiff = (TimeSpan)(_expDate - DateTime.UtcNow);
                if (_expDate.HasValue)
                {
                    smallNextBillDate.Visible   = true;
                    smallNextBillDate.InnerText = "Next billed on " + _expDate.Value.ToString("dd-MMM-yyyy");
                }
            }
            else
            {
                lCCStatus.Text = "No Credit Card on File.";
                if (!IsPostBack)
                {
                    DisablePurchaseButtons();
                }
            }
            if (_custSubscr != null && _custSubscr.CreditCard != null)
            {
                System.Collections.Generic.List <TransactionType> transTypes = new List <TransactionType>();
                transTypes.Add(TransactionType.Payment);
                System.Collections.Generic.IDictionary <int, ITransaction> trans = Chargify.GetTransactionsForSubscription(_custSubscr.SubscriptionID, 1, 25, transTypes);
                if (trans != null && trans.Count > 0)
                {
                    divPaymentHistoryHeader.Visible = true;
                    cgvTransactList.Visible         = true;
                    cgvTransactList.DataSource      = trans.Values;
                    cgvTransactList.DataBind();
                }
            }
        }
Example #4
0
        protected override void EditForm_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
        {
            base.EditForm_ItemUpdated(sender, e);

            if (e == null)
            {
                return;
            }

            if (e.Exception != null)
            {
                return;
            }

            if (m_UserContext.IsFrameworkAdministrator)
            {
                ComboBox cmb = EditForm.FindControl("cmbBillingPlan") as ComboBox;
                int      val = 0;
                if (cmb != null && int.TryParse(cmb.SelectedValue, out val))
                {
                    Guid     instId = (Guid)EditForm.DataKey[0];
                    Instance inst   = m_UserContext.Instance;
                    if (inst == null || inst.InstanceId != instId)
                    {
                        inst = InstanceProvider.GetInstance(instId);
                    }
                    if (inst.BillingPlan != BillingPlan.Custom && val == 1)
                    {
                        InstanceProvider.UpdateInstance(inst, BillingPlan.Custom);
                    }
                    else if (inst.BillingPlan == BillingPlan.Custom && val == 0)
                    {
                        ChargifyNET.ChargifyConnect _chargify   = ChargifyProvider.CreateChargify();
                        ChargifyNET.ISubscription   _custSubscr = ChargifyProvider.GetCustomerSubscription(_chargify, inst.OrganizationId, inst.InstanceId);
                        SettingCollection           settings    = SettingProvider.GetAllPricedSettings(inst.OrganizationId, inst.InstanceId);
                        ChargifyProvider.UpdateSubscriptionAllocations(_chargify, _custSubscr != null ? _custSubscr.SubscriptionID : 0, inst, settings, settings);
                    }
                }
            }

            this.Redirect();
        }
Example #5
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            EnsureActiveInstance();
            Repeater1.DataSource = this.PaidSettings;
            Repeater1.DataBind();

            this.MasterPage.VisibleBreadcrumbs = false;

            if (IsPostBack)
            {
                return;
            }

            if (!ChargifyEnabled || CurrentBillingPlan == BillingPlan.Custom)
            {
                ccrControl.Visible = false;
            }

            this.List_DataBind();

            if (CurrentBillingPlan == BillingPlan.Custom || !ChargifyEnabled)
            {
                return;
            }

            lblTraining1HourPrice.Style.Add(HtmlTextWriterStyle.TextAlign, "right");
            lblTraining3HoursPrice.Style.Add(HtmlTextWriterStyle.TextAlign, "right");
            lblTraining8HoursPrice.Style.Add(HtmlTextWriterStyle.TextAlign, "right");

            if (Request.QueryString["st"] == "ok")
            {
                this.MasterPage.MessageType = NoticeMessageType.Success;
                this.MasterPage.Message     = "Thank You. Your Credit Card Registered Successfully!";
                if (!string.IsNullOrEmpty(Request.QueryString["msg"]))
                {
                    this.MasterPage.Message += Request.QueryString["msg"];
                }
            }
            else if (Request.QueryString["st"] == "cancel")
            {
                this.MasterPage.MessageType = NoticeMessageType.Success;
                this.MasterPage.Message     = "Your Credit Card registration was Removed Successfully!";
            }
            else if (Request.QueryString["st"] == "reactivated")
            {
                this.MasterPage.MessageType = NoticeMessageType.Success;
                this.MasterPage.Message     = "Your Credit Card registration was Reactivated Successfully!";
            }

            SettingCollection settings = this.PaidSettings;

            if (settings["Training1Hour"] != null)
            {
                lblTraining1HourPrice.Text = settings["Training1Hour"].Price.ToString("$0.00");
            }
            if (settings["Training3Hours"] != null)
            {
                lblTraining3HoursPrice.Text = settings["Training3Hours"].Price.ToString("$0.00");
            }
            if (settings["Training8Hours"] != null)
            {
                lblTraining8HoursPrice.Text = settings["Training8Hours"].Price.ToString("$0.00");
            }

            ISubscription _subscription = ChargifyProvider.GetCustomerSubscription(Chargify, OrganizationId, InstanceId);

            if (_subscription != null)
            {
                ICreditCardView _cc = _subscription.CreditCard;
                if (_cc != null)
                {
                    ccrControl.SetCreditCardInformation(_cc.FullNumber, _cc.ExpirationMonth.ToString(), _cc.ExpirationYear.ToString().Length > 2 ? _cc.ExpirationYear.ToString().Substring(2) : _cc.ExpirationYear.ToString());
                    IsNewSubscription = false;
                }
                divCancelAccountHeader.Visible = _cc != null && _subscription.State != SubscriptionState.Canceled;
                divCancelAccount.Visible       = divCancelAccountHeader.Visible;
            }
            else
            {
                IsNewSubscription = true;
            }
        }
Example #6
0
        public static int UpdateChargifyAllocations()
        {
            if (!Micajah.Common.Configuration.FrameworkConfiguration.Current.WebApplication.Integration.Chargify.Enabled)
            {
                throw new InvalidOperationException("Chargify integration is not enabled in the application configuration file.");
            }

            ChargifyConnect _chargify = ChargifyProvider.CreateChargify();

            if (_chargify == null)
            {
                throw new InvalidOperationException("No Chargify configuration settings found.");
            }

            DateTime?lastUpdatedAt = CounterSettingProvider.GetDateTimeMark(1);

            int updatedCount             = 0;
            OrganizationCollection _orgs = OrganizationProvider.GetOrganizations(false, false);

            foreach (Organization _org in _orgs)
            {
                InstanceCollection _insts = InstanceProvider.GetInstances(_org.OrganizationId, false);

                foreach (Instance _inst in _insts)
                {
                    if (_inst.BillingPlan == BillingPlan.Custom)
                    {
                        continue;
                    }

                    SettingCollection modifiedSettings = CounterSettingProvider.GetLastModifiedPaidSettings(_org.OrganizationId, _inst.InstanceId, lastUpdatedAt);
                    if (modifiedSettings.Count == 0)
                    {
                        continue;
                    }

                    SettingCollection paidSettings = lastUpdatedAt.HasValue ? CounterSettingProvider.GetCalculatedPaidSettings(_org.OrganizationId, _inst.InstanceId) : modifiedSettings;

                    ISubscription _custSubscr = ChargifyProvider.GetCustomerSubscription(_chargify, _org.OrganizationId, _inst.InstanceId);
                    ChargifyProvider.UpdateSubscriptionAllocations(_chargify, _custSubscr != null ? _custSubscr.SubscriptionID : 0, _inst, modifiedSettings, paidSettings);

                    if (_custSubscr != null)
                    {
                        updatedCount++;
                    }
                    if (_custSubscr == null && _inst.CreditCardStatus != CreditCardStatus.NotRegistered)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.NotRegistered);
                    }
                    else if (_custSubscr != null && _custSubscr.State == SubscriptionState.Expired && _inst.CreditCardStatus != CreditCardStatus.Expired)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.Expired);
                    }
                    else if (_custSubscr != null && _custSubscr.State == SubscriptionState.Active && _inst.CreditCardStatus != CreditCardStatus.Registered)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.Registered);
                    }
                    else if (_custSubscr != null && _custSubscr.State != SubscriptionState.Active && _custSubscr.State != SubscriptionState.Expired && _inst.CreditCardStatus != CreditCardStatus.Declined)
                    {
                        InstanceProvider.UpdateInstance(_inst, CreditCardStatus.Declined);
                    }
                }
            }

            CounterSettingProvider.SetDateTimeMark(1);

            return(updatedCount);
        }