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.

billing: Make compute_plan_paramaters take tier as arg.

Vishnu KS641402856da7
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index f5b28807cb9..0e27530cc47 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -408,6 +408,7 @@ def make_end_of_cycle_updates_if_needed(
discount = plan.customer.default_discount or plan.discount
_, _, _, price_per_license = compute_plan_parameters(
+ tier=plan.tier,
automanage_licenses=plan.automanage_licenses,
billing_schedule=CustomerPlan.ANNUAL,
discount=plan.discount,
@@ -495,6 +496,7 @@ def get_price_per_license(
def compute_plan_parameters(
+ tier: int,
automanage_licenses: bool,
billing_schedule: int,
discount: Optional[Decimal],
@@ -511,7 +513,7 @@ def compute_plan_parameters(
else: # nocoverage
raise InvalidBillingSchedule(billing_schedule)
- price_per_license = get_price_per_license(CustomerPlan.STANDARD, billing_schedule, discount)
+ price_per_license = get_price_per_license(tier, billing_schedule, discount)
next_invoice_date = period_end
if automanage_licenses:
@@ -568,7 +570,11 @@ def process_initial_upgrade(
period_end,
price_per_license,
) = compute_plan_parameters(
- automanage_licenses, billing_schedule, customer.default_discount, free_trial
+ CustomerPlan.STANDARD,
+ automanage_licenses,
+ billing_schedule,
+ customer.default_discount,
+ free_trial,
)
# The main design constraint in this function is that if you upgrade with a credit card, and the
# charge fails, everything should be rolled back as if nothing had happened. This is because we
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index b59b69d5cd9..6989e7599c4 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -3162,22 +3162,53 @@ class BillingHelpersTest(ZulipTestCase):
year_later = datetime(2020, 12, 31, 1, 2, 3, tzinfo=timezone.utc)
test_cases = [
# test all possibilities, since there aren't that many
- ((True, CustomerPlan.ANNUAL, None), (anchor, month_later, year_later, 8000)),
- ((True, CustomerPlan.ANNUAL, 85), (anchor, month_later, year_later, 1200)),
- ((True, CustomerPlan.MONTHLY, None), (anchor, month_later, month_later, 800)),
- ((True, CustomerPlan.MONTHLY, 85), (anchor, month_later, month_later, 120)),
- ((False, CustomerPlan.ANNUAL, None), (anchor, year_later, year_later, 8000)),
- ((False, CustomerPlan.ANNUAL, 85), (anchor, year_later, year_later, 1200)),
- ((False, CustomerPlan.MONTHLY, None), (anchor, month_later, month_later, 800)),
- ((False, CustomerPlan.MONTHLY, 85), (anchor, month_later, month_later, 120)),
+ (
+ (CustomerPlan.STANDARD, True, CustomerPlan.ANNUAL, None),
+ (anchor, month_later, year_later, 8000),
+ ),
+ (
+ (CustomerPlan.STANDARD, True, CustomerPlan.ANNUAL, 85),
+ (anchor, month_later, year_later, 1200),
+ ),
+ (
+ (CustomerPlan.STANDARD, True, CustomerPlan.MONTHLY, None),
+ (anchor, month_later, month_later, 800),
+ ),
+ (
+ (CustomerPlan.STANDARD, True, CustomerPlan.MONTHLY, 85),
+ (anchor, month_later, month_later, 120),
+ ),
+ (
+ (CustomerPlan.STANDARD, False, CustomerPlan.ANNUAL, None),
+ (anchor, year_later, year_later, 8000),
+ ),
+ (
+ (CustomerPlan.STANDARD, False, CustomerPlan.ANNUAL, 85),
+ (anchor, year_later, year_later, 1200),
+ ),
+ (
+ (CustomerPlan.STANDARD, False, CustomerPlan.MONTHLY, None),
+ (anchor, month_later, month_later, 800),
+ ),
+ (
+ (CustomerPlan.STANDARD, False, CustomerPlan.MONTHLY, 85),
+ (anchor, month_later, month_later, 120),
+ ),
# test exact math of Decimals; 800 * (1 - 87.25) = 101.9999999..
- ((False, CustomerPlan.MONTHLY, 87.25), (anchor, month_later, month_later, 102)),
+ (
+ (CustomerPlan.STANDARD, False, CustomerPlan.MONTHLY, 87.25),
+ (anchor, month_later, month_later, 102),
+ ),
# test dropping of fractional cents; without the int it's 102.8
- ((False, CustomerPlan.MONTHLY, 87.15), (anchor, month_later, month_later, 102)),
+ (
+ (CustomerPlan.STANDARD, False, CustomerPlan.MONTHLY, 87.15),
+ (anchor, month_later, month_later, 102),
+ ),
]
with patch("corporate.lib.stripe.timezone_now", return_value=anchor):
- for (automanage_licenses, billing_schedule, discount), output in test_cases:
+ for (tier, automanage_licenses, billing_schedule, discount), output in test_cases:
output_ = compute_plan_parameters(
+ tier,
automanage_licenses,
billing_schedule,
None if discount is None else Decimal(discount),