stripe: Add required plan tier for cloud realms on support page.

This commit is contained in:
Aman Agrawal 2024-04-29 09:58:15 +00:00 committed by Tim Abbott
parent 7e87287803
commit 04638ffaee
4 changed files with 40 additions and 14 deletions

View File

@ -296,6 +296,21 @@ def get_realm_plan_type_options() -> List[SupportSelectOption]:
return plan_types
def get_realm_plan_type_options_for_discount() -> List[SupportSelectOption]:
plan_types = [
SupportSelectOption("None", 0),
SupportSelectOption(
CustomerPlan.name_from_tier(CustomerPlan.TIER_CLOUD_STANDARD),
CustomerPlan.TIER_CLOUD_STANDARD,
),
SupportSelectOption(
CustomerPlan.name_from_tier(CustomerPlan.TIER_CLOUD_PLUS),
CustomerPlan.TIER_CLOUD_PLUS,
),
]
return plan_types
VALID_MODIFY_PLAN_METHODS = [
"downgrade_at_billing_cycle_end",
"downgrade_now_without_additional_licenses",
@ -321,6 +336,8 @@ def support(
realm_id: Optional[int] = REQ(default=None, converter=to_non_negative_int),
plan_type: Optional[int] = REQ(default=None, converter=to_non_negative_int),
discount: Optional[Decimal] = REQ(default=None, converter=to_decimal),
minimum_licenses: Optional[int] = REQ(default=None, converter=to_non_negative_int),
required_plan_tier: Optional[int] = REQ(default=None, converter=to_non_negative_int),
new_subdomain: Optional[str] = REQ(default=None),
status: Optional[str] = REQ(default=None, str_validator=check_string_in(VALID_STATUS_VALUES)),
billing_modality: Optional[str] = REQ(
@ -370,6 +387,16 @@ def support(
support_type=SupportType.attach_discount,
discount=discount,
)
elif minimum_licenses is not None:
support_view_request = SupportViewRequest(
support_type=SupportType.update_minimum_licenses,
minimum_licenses=minimum_licenses,
)
elif required_plan_tier is not None:
support_view_request = SupportViewRequest(
support_type=SupportType.update_required_plan_tier,
required_plan_tier=required_plan_tier,
)
elif billing_modality is not None:
support_view_request = SupportViewRequest(
support_type=SupportType.update_billing_modality,
@ -537,6 +564,7 @@ def support(
context["realm_icon_url"] = realm_icon_url
context["Confirmation"] = Confirmation
context["REALM_PLAN_TYPES"] = get_realm_plan_type_options()
context["REALM_PLAN_TYPES_FOR_DISCOUNT"] = get_realm_plan_type_options_for_discount()
context["ORGANIZATION_TYPES"] = sorted(
Realm.ORG_TYPES.values(), key=lambda d: d["display_order"]
)

View File

@ -103,18 +103,13 @@
</form>
{% endif %}
<form method="POST" class="support-discount-form support-form">
<b>Discount (use 85 for nonprofits)</b>:<br />
{{ csrf_input }}
<input type="hidden" name="realm_id" value="{{ realm.id }}" />
{% if realm_support_data[realm.id].plan_data.current_plan and realm_support_data[realm.id].plan_data.current_plan.fixed_price %}
<input type="number" name="discount" value="{{ format_discount(realm_support_data[realm.id].sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" disabled />
<button type="submit" class="support-submit-button" disabled>Update</button>
{% else %}
<input type="number" name="discount" value="{{ format_discount(realm_support_data[realm.id].sponsorship_data.default_discount) }}" step="0.01" min="0" max="99.99" required />
<button type="submit" class="support-submit-button">Update</button>
{% endif %}
</form>
{% with %}
{% set sponsorship_data = realm_support_data[realm.id].sponsorship_data %}
{% set PLAN_TYPES = REALM_PLAN_TYPES_FOR_DISCOUNT %}
{% set remote_id = realm.id %}
{% set remote_type = "realm_id" %}
{% include 'corporate/support/sponsorship_discount_forms.html' %}
{% endwith %}
{% if realm_support_data[realm.id].sponsorship_data.sponsorship_pending %}
{% with %}

View File

@ -4,7 +4,7 @@
{{ csrf_input }}
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
<select name="required_plan_tier">
{% for plan_tier in REMOTE_PLAN_TIERS %}
{% for plan_tier in PLAN_TYPES %}
{% if sponsorship_data.required_plan_tier == plan_tier.value %}
<option value="{{ plan_tier.value }}" selected>{{ plan_tier.name }}</option>
{% else %}

View File

@ -20,7 +20,10 @@
</form>
{% endif %}
{% include 'corporate/support/sponsorship_discount_forms.html' %}
{% with %}
{% set PLAN_TYPES = REMOTE_PLAN_TIERS %}
{% include 'corporate/support/sponsorship_discount_forms.html' %}
{% endwith %}
{% if sponsorship_data.sponsorship_pending %}
{% with %}