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); } } }
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(); }
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); }