Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
corporate: Make references to billing modality consistent.
Lauryn Menard0679bc044a11
diff --git a/analytics/tests/test_support_views.py b/analytics/tests/test_support_views.pyindex a08f4dbc3b9..67409eef9f3 100644--- a/analytics/tests/test_support_views.py+++ b/analytics/tests/test_support_views.py@@ -434,8 +434,8 @@ class TestSupportEndpoint(ZulipTestCase):result,)- @mock.patch("analytics.views.support.update_realm_billing_method")- def test_change_billing_method(self, m: mock.Mock) -> None:+ @mock.patch("analytics.views.support.update_realm_billing_modality")+ def test_change_billing_modality(self, m: mock.Mock) -> None:cordelia = self.example_user("cordelia")self.login_user(cordelia)@@ -450,21 +450,22 @@ class TestSupportEndpoint(ZulipTestCase):result = self.client_post("/activity/support",- {"realm_id": f"{iago.realm_id}", "billing_method": "charge_automatically"},+ {"realm_id": f"{iago.realm_id}", "billing_modality": "charge_automatically"},)m.assert_called_once_with(get_realm("zulip"), charge_automatically=True, acting_user=iago)self.assert_in_success_response(- ["Billing method of zulip updated to charge automatically"], result+ ["Billing collection method of zulip updated to charge automatically"], result)m.reset_mock()result = self.client_post(- "/activity/support", {"realm_id": f"{iago.realm_id}", "billing_method": "send_invoice"}+ "/activity/support",+ {"realm_id": f"{iago.realm_id}", "billing_modality": "send_invoice"},)m.assert_called_once_with(get_realm("zulip"), charge_automatically=False, acting_user=iago)self.assert_in_success_response(- ["Billing method of zulip updated to pay by invoice"], result+ ["Billing collection method of zulip updated to send invoice"], result)def test_change_realm_plan_type(self) -> None:diff --git a/analytics/views/support.py b/analytics/views/support.pyindex 7225a768b80..b1d8d99c414 100644--- a/analytics/views/support.py+++ b/analytics/views/support.py@@ -63,7 +63,7 @@ if settings.BILLING_ENABLED:attach_discount_to_realm,get_discount_for_realm,switch_realm_from_standard_to_plus_plan,- update_realm_billing_method,+ update_realm_billing_modality,update_realm_sponsorship_status,)from corporate.models import (@@ -141,7 +141,7 @@ VALID_STATUS_VALUES = ["deactivated",]-VALID_BILLING_METHODS = [+VALID_BILLING_MODALITY_VALUES = ["send_invoice","charge_automatically",]@@ -164,8 +164,8 @@ def support(discount: Optional[Decimal] = REQ(default=None, converter=to_decimal),new_subdomain: Optional[str] = REQ(default=None),status: Optional[str] = REQ(default=None, str_validator=check_string_in(VALID_STATUS_VALUES)),- billing_method: Optional[str] = REQ(- default=None, str_validator=check_string_in(VALID_BILLING_METHODS)+ billing_modality: Optional[str] = REQ(+ default=None, str_validator=check_string_in(VALID_BILLING_MODALITY_VALUES)),sponsorship_pending: Optional[bool] = REQ(default=None, json_validator=check_bool),approve_sponsorship: bool = REQ(default=False, json_validator=check_bool),@@ -236,21 +236,21 @@ def support(elif status == "deactivated":do_deactivate_realm(realm, acting_user=acting_user)context["success_message"] = f"{realm.string_id} deactivated."- elif billing_method is not None:- if billing_method == "send_invoice":- update_realm_billing_method(+ elif billing_modality is not None:+ if billing_modality == "send_invoice":+ update_realm_billing_modality(realm, charge_automatically=False, acting_user=acting_user)context["success_message"- ] = f"Billing method of {realm.string_id} updated to pay by invoice."- elif billing_method == "charge_automatically":- update_realm_billing_method(+ ] = f"Billing collection method of {realm.string_id} updated to send invoice."+ elif billing_modality == "charge_automatically":+ update_realm_billing_modality(realm, charge_automatically=True, acting_user=acting_user)context["success_message"- ] = f"Billing method of {realm.string_id} updated to charge automatically."+ ] = f"Billing collection method of {realm.string_id} updated to charge automatically."elif sponsorship_pending is not None:if sponsorship_pending:update_realm_sponsorship_status(realm, True, acting_user=acting_user)diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 4c97416aade..4cc5803353b 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -529,7 +529,7 @@ class AuditLogEventType(Enum):DISCOUNT_CHANGED = 4SPONSORSHIP_APPROVED = 5SPONSORSHIP_PENDING_STATUS_CHANGED = 6- BILLING_METHOD_CHANGED = 7+ BILLING_MODALITY_CHANGED = 7CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN = 8CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN = 9@@ -902,7 +902,7 @@ class BillingSession(ABC):extra_data={"sponsorship_pending": sponsorship_pending},)- def update_billing_method_of_current_plan(self, charge_automatically: bool) -> None:+ def update_billing_modality_of_current_plan(self, charge_automatically: bool) -> None:customer = self.get_customer()if customer is not None:plan = get_current_plan_by_customer(customer)@@ -910,7 +910,7 @@ class BillingSession(ABC):plan.charge_automatically = charge_automaticallyplan.save(update_fields=["charge_automatically"])self.write_to_audit_log(- event_type=AuditLogEventType.BILLING_METHOD_CHANGED,+ event_type=AuditLogEventType.BILLING_MODALITY_CHANGED,event_time=timezone_now(),extra_data={"charge_automatically": charge_automatically},)@@ -2049,8 +2049,8 @@ class RealmBillingSession(BillingSession):return RealmAuditLog.REALM_SPONSORSHIP_APPROVEDelif event_type is AuditLogEventType.SPONSORSHIP_PENDING_STATUS_CHANGED:return RealmAuditLog.REALM_SPONSORSHIP_PENDING_STATUS_CHANGED- elif event_type is AuditLogEventType.BILLING_METHOD_CHANGED:- return RealmAuditLog.REALM_BILLING_METHOD_CHANGED+ elif event_type is AuditLogEventType.BILLING_MODALITY_CHANGED:+ return RealmAuditLog.REALM_BILLING_MODALITY_CHANGEDelif event_type is AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN:return RealmAuditLog.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLANelif event_type is AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN:@@ -2359,8 +2359,8 @@ class RemoteRealmBillingSession(BillingSession): # nocoveragereturn RemoteRealmAuditLog.REMOTE_SERVER_SPONSORSHIP_APPROVEDelif event_type is AuditLogEventType.SPONSORSHIP_PENDING_STATUS_CHANGED:return RemoteRealmAuditLog.REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED- elif event_type is AuditLogEventType.BILLING_METHOD_CHANGED:- return RemoteRealmAuditLog.REMOTE_SERVER_BILLING_METHOD_CHANGED+ elif event_type is AuditLogEventType.BILLING_MODALITY_CHANGED:+ return RemoteRealmAuditLog.REMOTE_SERVER_BILLING_MODALITY_CHANGEDelse:raise BillingSessionAuditLogEventError(event_type)@@ -2632,8 +2632,8 @@ class RemoteServerBillingSession(BillingSession): # nocoveragereturn RemoteZulipServerAuditLog.REMOTE_SERVER_SPONSORSHIP_APPROVEDelif event_type is AuditLogEventType.SPONSORSHIP_PENDING_STATUS_CHANGED:return RemoteZulipServerAuditLog.REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED- elif event_type is AuditLogEventType.BILLING_METHOD_CHANGED:- return RemoteZulipServerAuditLog.REMOTE_SERVER_BILLING_METHOD_CHANGED+ elif event_type is AuditLogEventType.BILLING_MODALITY_CHANGED:+ return RemoteZulipServerAuditLog.REMOTE_SERVER_BILLING_MODALITY_CHANGEDelse:raise BillingSessionAuditLogEventError(event_type)diff --git a/corporate/lib/support.py b/corporate/lib/support.pyindex 401b20dc08d..bbccaa5471e 100644--- a/corporate/lib/support.py+++ b/corporate/lib/support.py@@ -43,11 +43,11 @@ def update_realm_sponsorship_status(billing_session.update_customer_sponsorship_status(sponsorship_pending)-def update_realm_billing_method(+def update_realm_billing_modality(realm: Realm, charge_automatically: bool, *, acting_user: UserProfile) -> None:billing_session = RealmBillingSession(acting_user, realm, support_session=True)- billing_session.update_billing_method_of_current_plan(charge_automatically)+ billing_session.update_billing_modality_of_current_plan(charge_automatically)def switch_realm_from_standard_to_plus_plan(realm: Realm) -> None:diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex fa8c97ae499..1c5d32fe260 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -79,7 +79,7 @@ from corporate.lib.support import (attach_discount_to_realm,get_discount_for_realm,switch_realm_from_standard_to_plus_plan,- update_realm_billing_method,+ update_realm_billing_modality,update_realm_sponsorship_status,)from corporate.models import (@@ -5234,7 +5234,7 @@ class TestSupportBillingHelpers(StripeTestCase):self.assertEqual(realm_audit_log.extra_data, expected_extra_data)self.assertEqual(realm_audit_log.acting_user, iago)- def test_update_realm_billing_method(self) -> None:+ def test_update_realm_billing_modality(self) -> None:realm = get_realm("zulip")customer = Customer.objects.create(realm=realm, stripe_customer_id="cus_12345")plan = CustomerPlan.objects.create(@@ -5247,22 +5247,22 @@ class TestSupportBillingHelpers(StripeTestCase):self.assertEqual(plan.charge_automatically, False)iago = self.example_user("iago")- update_realm_billing_method(realm, True, acting_user=iago)+ update_realm_billing_modality(realm, True, acting_user=iago)plan.refresh_from_db()self.assertEqual(plan.charge_automatically, True)realm_audit_log = RealmAuditLog.objects.filter(- event_type=RealmAuditLog.REALM_BILLING_METHOD_CHANGED+ event_type=RealmAuditLog.REALM_BILLING_MODALITY_CHANGED).last()assert realm_audit_log is not Noneexpected_extra_data = {"charge_automatically": plan.charge_automatically}self.assertEqual(realm_audit_log.acting_user, iago)self.assertEqual(realm_audit_log.extra_data, expected_extra_data)- update_realm_billing_method(realm, False, acting_user=iago)+ update_realm_billing_modality(realm, False, acting_user=iago)plan.refresh_from_db()self.assertEqual(plan.charge_automatically, False)realm_audit_log = RealmAuditLog.objects.filter(- event_type=RealmAuditLog.REALM_BILLING_METHOD_CHANGED+ event_type=RealmAuditLog.REALM_BILLING_MODALITY_CHANGED).last()assert realm_audit_log is not Noneexpected_extra_data = {"charge_automatically": plan.charge_automatically}diff --git a/templates/analytics/realm_details.html b/templates/analytics/realm_details.htmlindex d7e6e81abd7..1114e7f4f8c 100644--- a/templates/analytics/realm_details.html+++ b/templates/analytics/realm_details.html@@ -123,12 +123,12 @@<b>Next invoice date</b>: {{ plan_data[realm.id].current_plan.next_invoice_date.strftime('%d %B %Y') }}<br /></div>-<form method="POST" class="billing-method-form">+<form method="POST" class="billing-modality-form"><br />- <b>Billing method</b><br />+ <b>Billing collection method</b><br />{{ csrf_input }}<input type="hidden" name="realm_id" value="{{ realm.id }}" />- <select name="billing_method" class="billing-method-select" required>+ <select name="billing_modality" class="billing-modality-select" required><option value="charge_automatically" {% if plan_data[realm.id].current_plan.charge_automatically %}selected{% endif %}>Charge automatically</option><option value="send_invoice" {% if not plan_data[realm.id].current_plan.charge_automatically %}selected{% endif %}>Pay by invoice</option></select>diff --git a/web/styles/portico/activity.css b/web/styles/portico/activity.cssindex 5e515ae5750..f04bf7a8ba7 100644--- a/web/styles/portico/activity.css+++ b/web/styles/portico/activity.css@@ -187,7 +187,7 @@ tr.admin td:first-child {top: -40px;}-.billing-method-form {+.billing-modality-form {position: relative;top: -30px;}diff --git a/zerver/models.py b/zerver/models.pyindex 4ecbea3ed70..09dd7c6d72d 100644--- a/zerver/models.py+++ b/zerver/models.py@@ -4776,7 +4776,7 @@ class AbstractRealmAuditLog(models.Model):REALM_ICON_SOURCE_CHANGED = 208REALM_DISCOUNT_CHANGED = 209REALM_SPONSORSHIP_APPROVED = 210- REALM_BILLING_METHOD_CHANGED = 211+ REALM_BILLING_MODALITY_CHANGED = 211REALM_REACTIVATION_EMAIL_SENT = 212REALM_SPONSORSHIP_PENDING_STATUS_CHANGED = 213REALM_SUBDOMAIN_CHANGED = 214@@ -4842,7 +4842,7 @@ class AbstractRealmAuditLog(models.Model):REMOTE_SERVER_PLAN_TYPE_CHANGED = 10204REMOTE_SERVER_DISCOUNT_CHANGED = 10209REMOTE_SERVER_SPONSORSHIP_APPROVED = 10210- REMOTE_SERVER_BILLING_METHOD_CHANGED = 10211+ REMOTE_SERVER_BILLING_MODALITY_CHANGED = 10211REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED = 10213REMOTE_SERVER_CREATED = 10215