mirror of https://github.com/zulip/zulip.git
corporate: Make references to billing modality consistent.
The "send_invoice" and "charge_automatically" strings used by stripe for the `collection_method` are referred to both as the "billing method" and "billing modality" in the billing code. Because we send this as data to stripe as either `collection_method` or `billing_modality`, renames any references that are any form of "billing method".
This commit is contained in:
parent
42edb4416a
commit
0679bc044a
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -529,7 +529,7 @@ class AuditLogEventType(Enum):
|
|||
DISCOUNT_CHANGED = 4
|
||||
SPONSORSHIP_APPROVED = 5
|
||||
SPONSORSHIP_PENDING_STATUS_CHANGED = 6
|
||||
BILLING_METHOD_CHANGED = 7
|
||||
BILLING_MODALITY_CHANGED = 7
|
||||
CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN = 8
|
||||
CUSTOMER_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_automatically
|
||||
plan.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_APPROVED
|
||||
elif 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_CHANGED
|
||||
elif event_type is AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN:
|
||||
return RealmAuditLog.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN
|
||||
elif event_type is AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN:
|
||||
|
@ -2359,8 +2359,8 @@ class RemoteRealmBillingSession(BillingSession): # nocoverage
|
|||
return RemoteRealmAuditLog.REMOTE_SERVER_SPONSORSHIP_APPROVED
|
||||
elif 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_CHANGED
|
||||
else:
|
||||
raise BillingSessionAuditLogEventError(event_type)
|
||||
|
||||
|
@ -2632,8 +2632,8 @@ class RemoteServerBillingSession(BillingSession): # nocoverage
|
|||
return RemoteZulipServerAuditLog.REMOTE_SERVER_SPONSORSHIP_APPROVED
|
||||
elif 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_CHANGED
|
||||
else:
|
||||
raise BillingSessionAuditLogEventError(event_type)
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 None
|
||||
expected_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 None
|
||||
expected_extra_data = {"charge_automatically": plan.charge_automatically}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -187,7 +187,7 @@ tr.admin td:first-child {
|
|||
top: -40px;
|
||||
}
|
||||
|
||||
.billing-method-form {
|
||||
.billing-modality-form {
|
||||
position: relative;
|
||||
top: -30px;
|
||||
}
|
||||
|
|
|
@ -4776,7 +4776,7 @@ class AbstractRealmAuditLog(models.Model):
|
|||
REALM_ICON_SOURCE_CHANGED = 208
|
||||
REALM_DISCOUNT_CHANGED = 209
|
||||
REALM_SPONSORSHIP_APPROVED = 210
|
||||
REALM_BILLING_METHOD_CHANGED = 211
|
||||
REALM_BILLING_MODALITY_CHANGED = 211
|
||||
REALM_REACTIVATION_EMAIL_SENT = 212
|
||||
REALM_SPONSORSHIP_PENDING_STATUS_CHANGED = 213
|
||||
REALM_SUBDOMAIN_CHANGED = 214
|
||||
|
@ -4842,7 +4842,7 @@ class AbstractRealmAuditLog(models.Model):
|
|||
REMOTE_SERVER_PLAN_TYPE_CHANGED = 10204
|
||||
REMOTE_SERVER_DISCOUNT_CHANGED = 10209
|
||||
REMOTE_SERVER_SPONSORSHIP_APPROVED = 10210
|
||||
REMOTE_SERVER_BILLING_METHOD_CHANGED = 10211
|
||||
REMOTE_SERVER_BILLING_MODALITY_CHANGED = 10211
|
||||
REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED = 10213
|
||||
REMOTE_SERVER_CREATED = 10215
|
||||
|
||||
|
|
Loading…
Reference in New Issue