stripe: Rename get_remote_server_legacy_plan.

Renames get_remote_server_legacy_plan to
get_complimentary_access_plan, as well as
associated variable names.
This commit is contained in:
Lauryn Menard
2024-12-13 14:31:35 +01:00
committed by Tim Abbott
parent 20352aff9e
commit 7a0626aede
3 changed files with 23 additions and 18 deletions

View File

@@ -1039,24 +1039,29 @@ class BillingSession(ABC):
return True return True
return False return False
def get_remote_server_legacy_plan( def get_complimentary_access_plan(
self, customer: Customer | None, status: int = CustomerPlan.ACTIVE self, customer: Customer | None, status: int = CustomerPlan.ACTIVE
) -> CustomerPlan | None: ) -> CustomerPlan | None:
# status = CustomerPlan.ACTIVE means that the legacy plan is not scheduled for an upgrade.
# status = CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END means that the legacy plan is scheduled for an upgrade.
if customer is None: if customer is None:
return None return None
plan_tier = CustomerPlan.TIER_SELF_HOSTED_LEGACY
if isinstance(self, RealmBillingSession):
# TODO implement a complimentary access plan/tier for Zulip Cloud.
return None
# status = CustomerPlan.ACTIVE means the plan is not scheduled for an upgrade.
# status = CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END means the plan is scheduled for an upgrade.
return CustomerPlan.objects.filter( return CustomerPlan.objects.filter(
customer=customer, customer=customer,
tier=CustomerPlan.TIER_SELF_HOSTED_LEGACY, tier=plan_tier,
status=status, status=status,
).first() ).first()
def get_formatted_complimentary_access_plan_end_date( def get_formatted_complimentary_access_plan_end_date(
self, customer: Customer | None, status: int = CustomerPlan.ACTIVE self, customer: Customer | None, status: int = CustomerPlan.ACTIVE
) -> str | None: # nocoverage ) -> str | None: # nocoverage
complimentary_access_plan = self.get_remote_server_legacy_plan(customer, status) complimentary_access_plan = self.get_complimentary_access_plan(customer, status)
if complimentary_access_plan is None: if complimentary_access_plan is None:
return None return None
@@ -1064,7 +1069,7 @@ class BillingSession(ABC):
return complimentary_access_plan.end_date.strftime("%B %d, %Y") return complimentary_access_plan.end_date.strftime("%B %d, %Y")
def get_complimentary_access_next_plan(self, customer: Customer) -> CustomerPlan | None: def get_complimentary_access_next_plan(self, customer: Customer) -> CustomerPlan | None:
complimentary_access_plan = self.get_remote_server_legacy_plan( complimentary_access_plan = self.get_complimentary_access_plan(
customer, CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END customer, CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END
) )
if complimentary_access_plan is None: if complimentary_access_plan is None:
@@ -2082,9 +2087,9 @@ class BillingSession(ABC):
# Free trial is not available for existing customers. # Free trial is not available for existing customers.
free_trial = False free_trial = False
remote_server_legacy_plan = self.get_remote_server_legacy_plan(customer) complimentary_access_plan = self.get_complimentary_access_plan(customer)
should_schedule_upgrade_for_legacy_remote_server = ( should_schedule_upgrade_for_legacy_remote_server = (
remote_server_legacy_plan is not None complimentary_access_plan is not None
and upgrade_request.remote_server_plan_start_date == "billing_cycle_end_date" and upgrade_request.remote_server_plan_start_date == "billing_cycle_end_date"
) )
# Directly upgrade free trial orgs or invoice payment orgs to standard plan. # Directly upgrade free trial orgs or invoice payment orgs to standard plan.
@@ -2096,7 +2101,7 @@ class BillingSession(ABC):
billing_schedule, billing_schedule,
charge_automatically, charge_automatically,
free_trial, free_trial,
remote_server_legacy_plan, complimentary_access_plan,
should_schedule_upgrade_for_legacy_remote_server, should_schedule_upgrade_for_legacy_remote_server,
) )
data["organization_upgrade_successful"] = True data["organization_upgrade_successful"] = True

View File

@@ -142,7 +142,7 @@ def handle_invoice_paid_event(stripe_invoice: stripe.Invoice, invoice: Invoice)
and configured_fixed_price_plan.sent_invoice_id == invoice.stripe_invoice_id and configured_fixed_price_plan.sent_invoice_id == invoice.stripe_invoice_id
): ):
billing_session = get_billing_session_for_stripe_webhook(customer, user_id=None) billing_session = get_billing_session_for_stripe_webhook(customer, user_id=None)
remote_server_legacy_plan = billing_session.get_remote_server_legacy_plan(customer) complimentary_access_plan = billing_session.get_complimentary_access_plan(customer)
assert customer.required_plan_tier is not None assert customer.required_plan_tier is not None
billing_session.process_initial_upgrade( billing_session.process_initial_upgrade(
plan_tier=customer.required_plan_tier, plan_tier=customer.required_plan_tier,
@@ -153,7 +153,7 @@ def handle_invoice_paid_event(stripe_invoice: stripe.Invoice, invoice: Invoice)
billing_schedule=CustomerPlan.BILLING_SCHEDULE_ANNUAL, billing_schedule=CustomerPlan.BILLING_SCHEDULE_ANNUAL,
charge_automatically=False, charge_automatically=False,
free_trial=False, free_trial=False,
remote_server_legacy_plan=remote_server_legacy_plan, remote_server_legacy_plan=complimentary_access_plan,
stripe_invoice_paid=True, stripe_invoice_paid=True,
) )
else: else:
@@ -168,7 +168,7 @@ def handle_invoice_paid_event(stripe_invoice: stripe.Invoice, invoice: Invoice)
return return
billing_session = get_billing_session_for_stripe_webhook(customer, metadata.get("user_id")) billing_session = get_billing_session_for_stripe_webhook(customer, metadata.get("user_id"))
remote_server_legacy_plan = billing_session.get_remote_server_legacy_plan(customer) complimentary_access_plan = billing_session.get_complimentary_access_plan(customer)
billing_schedule = int(metadata["billing_schedule"]) billing_schedule = int(metadata["billing_schedule"])
plan_tier = int(metadata["plan_tier"]) plan_tier = int(metadata["plan_tier"])
charge_automatically = stripe_invoice.collection_method != "send_invoice" charge_automatically = stripe_invoice.collection_method != "send_invoice"
@@ -183,7 +183,7 @@ def handle_invoice_paid_event(stripe_invoice: stripe.Invoice, invoice: Invoice)
billing_schedule=billing_schedule, billing_schedule=billing_schedule,
charge_automatically=charge_automatically, charge_automatically=charge_automatically,
free_trial=False, free_trial=False,
remote_server_legacy_plan=remote_server_legacy_plan, remote_server_legacy_plan=complimentary_access_plan,
stripe_invoice_paid=True, stripe_invoice_paid=True,
) )
return return
@@ -207,6 +207,6 @@ def handle_invoice_paid_event(stripe_invoice: stripe.Invoice, invoice: Invoice)
billing_schedule=billing_schedule, billing_schedule=billing_schedule,
charge_automatically=charge_automatically, charge_automatically=charge_automatically,
free_trial=False, free_trial=False,
remote_server_legacy_plan=remote_server_legacy_plan, remote_server_legacy_plan=complimentary_access_plan,
stripe_invoice_paid=True, stripe_invoice_paid=True,
) )

View File

@@ -103,11 +103,11 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
billing_session.migrate_customer_to_legacy_plan(legacy_anchor, next_plan_anchor) billing_session.migrate_customer_to_legacy_plan(legacy_anchor, next_plan_anchor)
customer = billing_session.get_customer() customer = billing_session.get_customer()
assert customer is not None assert customer is not None
legacy_plan = billing_session.get_remote_server_legacy_plan(customer) complimentary_access_plan = billing_session.get_complimentary_access_plan(customer)
assert legacy_plan is not None assert complimentary_access_plan is not None
assert legacy_plan.end_date is not None assert complimentary_access_plan.end_date is not None
if upgrade: if upgrade:
upgrade_legacy_plan(legacy_plan) upgrade_legacy_plan(complimentary_access_plan)
super().setUp() super().setUp()