Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

corporate: Pass plan_tier parameter to process_initial_upgrade.

Lauryn Menard928cb7e09e7e
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 6d13973f95c..2ad7c1108ae 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -746,7 +746,7 @@ class RealmBillingSession(BillingSession):
plan_type = Realm.PLAN_TYPE_STANDARD_FREE
elif tier == CustomerPlan.STANDARD:
plan_type = Realm.PLAN_TYPE_STANDARD
- elif tier == CustomerPlan.PLUS:
+ elif tier == CustomerPlan.PLUS: # nocoverage # Plus plan doesn't use this code path yet.
plan_type = Realm.PLAN_TYPE_PLUS
else:
raise AssertionError("Unexpected tier")
@@ -1059,6 +1059,7 @@ def do_deactivate_remote_server(remote_server: RemoteZulipServer) -> None:
@catch_stripe_errors
def process_initial_upgrade(
user: UserProfile,
+ plan_tier: int,
licenses: int,
automanage_licenses: bool,
billing_schedule: int,
@@ -1075,7 +1076,7 @@ def process_initial_upgrade(
period_end,
price_per_license,
) = compute_plan_parameters(
- CustomerPlan.STANDARD,
+ plan_tier,
automanage_licenses,
billing_schedule,
customer.default_discount,
@@ -1099,7 +1100,7 @@ def process_initial_upgrade(
"discount": customer.default_discount,
"billing_cycle_anchor": billing_cycle_anchor,
"billing_schedule": billing_schedule,
- "tier": CustomerPlan.STANDARD,
+ "tier": plan_tier,
}
if free_trial:
plan_params["status"] = CustomerPlan.FREE_TRIAL
@@ -1151,7 +1152,7 @@ def process_initial_upgrade(
)
stripe.Invoice.finalize_invoice(stripe_invoice)
- billing_session.do_change_plan_type(tier=CustomerPlan.STANDARD)
+ billing_session.do_change_plan_type(tier=plan_tier)
def update_license_ledger_for_manual_plan(
diff --git a/corporate/lib/stripe_event_handler.py b/corporate/lib/stripe_event_handler.py
index f9680175fa6..531cd56a08b 100644
--- a/corporate/lib/stripe_event_handler.py
+++ b/corporate/lib/stripe_event_handler.py
@@ -12,7 +12,7 @@ from corporate.lib.stripe import (
ensure_customer_does_not_have_active_plan,
process_initial_upgrade,
)
-from corporate.models import Event, PaymentIntent, Session
+from corporate.models import CustomerPlan, Event, PaymentIntent, Session
from zerver.models import get_active_user_profile_by_id_in_realm
billing_logger = logging.getLogger("corporate.stripe")
@@ -102,6 +102,7 @@ def handle_checkout_session_completed_event(
billing_session.update_or_create_stripe_customer(payment_method)
process_initial_upgrade(
user,
+ CustomerPlan.STANDARD,
int(stripe_session.metadata["licenses"]),
stripe_session.metadata["license_management"] == "automatic",
int(stripe_session.metadata["billing_schedule"]),
@@ -151,6 +152,7 @@ def handle_payment_intent_succeeded_event(
process_initial_upgrade(
user,
+ CustomerPlan.STANDARD,
int(metadata["licenses"]),
metadata["license_management"] == "automatic",
int(metadata["billing_schedule"]),
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 96e7811ca1c..f2042c499e4 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -627,6 +627,7 @@ class StripeTestCase(ZulipTestCase):
) -> Any:
return process_initial_upgrade(
self.example_user("hamlet"),
+ CustomerPlan.STANDARD,
licenses,
automanage_licenses,
billing_schedule,
diff --git a/corporate/views/upgrade.py b/corporate/views/upgrade.py
index 2ae6304dbac..f7f055ea01c 100644
--- a/corporate/views/upgrade.py
+++ b/corporate/views/upgrade.py
@@ -142,6 +142,7 @@ def upgrade(
else:
process_initial_upgrade(
user,
+ CustomerPlan.STANDARD,
licenses,
automanage_licenses,
billing_schedule,