corporate: Move attach_realm_discount to BillingSession class.

This moves the logic for `attach_realm_discount`, which is used in
the support view, to be in the BillingSession class.

Updates the function name to be `attach_discount_to_customer` so
that the context is generalized vs realm specific.

Updates RealmBillingSession implementation to account for actions
that are initiated by a support admin user.

Also moves the helper function `get_discount_for_realm` that is
only used in support views to `corporate/lib/support.py`.
This commit is contained in:
Lauryn Menard
2023-10-31 19:22:55 +01:00
committed by Tim Abbott
parent 63abf063b7
commit ee19a9c274
4 changed files with 152 additions and 124 deletions

View File

@@ -54,10 +54,8 @@ if settings.ZILENCER_ENABLED:
if settings.BILLING_ENABLED:
from corporate.lib.stripe import approve_sponsorship as do_approve_sponsorship
from corporate.lib.stripe import (
attach_discount_to_realm,
downgrade_at_the_end_of_billing_cycle,
downgrade_now_without_creating_additional_invoices,
get_discount_for_realm,
get_latest_seat_count,
make_end_of_cycle_updates_if_needed,
switch_realm_from_standard_to_plus_plan,
@@ -65,6 +63,7 @@ if settings.BILLING_ENABLED:
update_sponsorship_status,
void_all_open_invoices,
)
from corporate.lib.support import attach_discount_to_realm, get_discount_for_realm
from corporate.models import (
Customer,
CustomerPlan,