billing: Note applied discount on upgrade and billing pages.

Fixes #27526
This commit is contained in:
Aman Agrawal 2023-11-23 17:05:06 +00:00 committed by Tim Abbott
parent 07d29126fd
commit 95f5d8bdb8
4 changed files with 28 additions and 0 deletions

View File

@ -99,6 +99,19 @@ def format_money(cents: float) -> str:
return f"{dollars:.{precision}f}"
def format_discount_percentage(discount: Optional[Decimal]) -> Optional[str]:
if type(discount) is not Decimal:
return None
# Even though it looks like /activity/support only finds integers valid,
# this will look good for any custom discounts that we apply.
if discount * 100 % 100 == 0:
precision = 0
else:
precision = 2 # nocoverage
return f"{discount:.{precision}f}"
def get_latest_seat_count(realm: Realm) -> int:
return get_seat_count(realm, extra_non_guests_count=0, extra_guests_count=0)
@ -1215,6 +1228,7 @@ class BillingSession(ABC):
"fixed_price": fixed_price,
"price_per_license": price_per_license,
"is_sponsorship_pending": customer.sponsorship_pending,
"discount_percent": format_discount_percentage(customer.default_discount),
}
return context
@ -1256,6 +1270,7 @@ class BillingSession(ABC):
"monthly_price": get_price_per_license(tier, CustomerPlan.MONTHLY, percent_off),
},
"manual_license_management": initial_upgrade_request.manual_license_management,
"discount_percent": format_discount_percentage(percent_off),
}
# Check if user was successful in adding a card and we are rendering the page again.

View File

@ -169,6 +169,11 @@
{% else %}
{{ "1 month" if billing_frequency == "Monthly" else "12 months" }}
{% endif %})
{% if discount_percent %}
<br />
<i class="billing-page-discount">(includes {{ discount_percent }}% discount)</i>
{% endif %}
{% endif %}
{% endif %}
{% else %}

View File

@ -87,6 +87,9 @@
{{ 'user' if seat_count == 1 else 'users' }}
</span> x
<span class="due-today-duration"></span>
{% if discount_percent %}
<i class="billing-page-discount">(includes {{ discount_percent }}% discount)</i>
{% endif %}
<h1>$<span class="due-today-price"></span></h1>
</div>
</div>

View File

@ -647,3 +647,8 @@ input[name="licenses"] {
#sponsorship-form #sponsorship-button {
width: 100%;
}
.billing-page-discount {
opacity: 0.8;
font-weight: 400;
}