support: Implement setting a current plan end date for Cloud support.

Prep for implementing fixed-price plan offers in Cloud support view.
This commit is contained in:
Lauryn Menard
2024-11-22 17:07:33 +01:00
committed by Tim Abbott
parent 6376fb7fec
commit 89b5e850b2
4 changed files with 68 additions and 5 deletions

View File

@@ -1612,7 +1612,9 @@ class BillingSession(ABC):
"property": "next_invoice_date",
}
plan.next_invoice_date = new_end_date
# Currently, we send a reminder email 2 months before the end date.
# We send a reminder email 2 months before the end date of
# remote server and remote realm fixed-price plans so that
# billing support can follow-up about continuing service.
# Reset it when we are extending the end_date.
reminder_to_review_plan_email_sent_changed_extra_data = None
if (
@@ -1659,9 +1661,7 @@ class BillingSession(ABC):
)
return f"Current plan for {self.billing_entity_display_name} updated to end on {end_date_string}."
raise SupportRequestError(
f"No current plan for {self.billing_entity_display_name}."
) # nocoverage
raise SupportRequestError(f"No current plan for {self.billing_entity_display_name}.")
def generate_stripe_invoice(
self,

View File

@@ -1513,6 +1513,62 @@ class TestSupportEndpoint(ZulipTestCase):
)
self.assert_length(messages, 1)
def test_update_current_plan_end_date(self) -> None:
lear_realm = get_realm("lear")
customer = get_customer_by_realm(lear_realm)
assert customer is None
iago = self.example_user("iago")
self.login_user(iago)
result = self.client_post(
"/activity/support",
{
"realm_id": f"{lear_realm.id}",
"plan_end_date": "2020-01-01",
},
)
self.assert_in_success_response(
["Cannot update current plan for lear to end on 2020-01-01."],
result,
)
result = self.client_post(
"/activity/support",
{
"realm_id": f"{lear_realm.id}",
"plan_end_date": "2050-03-01",
},
)
self.assert_in_success_response(
["No current plan for lear."],
result,
)
customer = self.create_customer_and_plan(lear_realm, True)
assert customer is not None
current_plan = get_current_plan_by_customer(customer)
assert current_plan is not None
self.assertIsNone(current_plan.end_date)
next_invoice_date = current_plan.next_invoice_date
assert next_invoice_date is not None
result = self.client_post(
"/activity/support",
{
"realm_id": f"{lear_realm.id}",
"plan_end_date": "2050-03-01",
},
)
self.assert_in_success_response(
["Current plan for lear updated to end on 2050-03-01."],
result,
)
current_plan.refresh_from_db()
self.assertEqual(current_plan.end_date, datetime(2050, 3, 1, tzinfo=timezone.utc))
self.assertEqual(current_plan.next_invoice_date, next_invoice_date)
def test_approve_sponsorship_deactivated_realm(self) -> None:
support_admin = self.example_user("iago")
with self.settings(BILLING_ENABLED=True):

View File

@@ -419,6 +419,8 @@ def support(
query: Annotated[str | None, ApiParamConfig("q")] = None,
org_type: Json[NonNegativeInt] | None = None,
max_invites: Json[NonNegativeInt] | None = None,
plan_end_date: Annotated[str, AfterValidator(lambda x: check_date("plan_end_date", x))]
| None = None,
) -> HttpResponse:
from corporate.lib.stripe import (
RealmBillingSession,
@@ -482,6 +484,11 @@ def support(
)
if modify_plan == "upgrade_plan_tier":
support_view_request["new_plan_tier"] = CustomerPlan.TIER_CLOUD_PLUS
elif plan_end_date is not None:
support_view_request = SupportViewRequest(
support_type=SupportType.update_plan_end_date,
plan_end_date=plan_end_date,
)
elif plan_type is not None:
current_plan_type = realm.plan_type
do_change_realm_plan_type(realm, plan_type, acting_user=acting_user)

View File

@@ -9,7 +9,7 @@
<button type="submit" class="support-submit-button">Update</button>
</form>
{% if current_plan.status == current_plan.ACTIVE and remote_support_view %}
{% if current_plan.status == current_plan.ACTIVE %}
<form method="POST" class="support-form">
<b>Plan end date</b><br />
{{ csrf_input }}