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: Create downgrade_at_the_end_of_billing_cycle.

Vishnu KSdbaea757aec1
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index e9fc4f3bd17..0c2d7fdfe8b 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -637,6 +637,11 @@ def downgrade_now_without_creating_additional_invoices(realm: Realm) -> None:
plan.next_invoice_date = next_invoice_date(plan)
plan.save(update_fields=["invoiced_through", "next_invoice_date"])
+def downgrade_at_the_end_of_billing_cycle(realm: Realm) -> None:
+ plan = get_current_plan_by_realm(realm)
+ assert(plan is not None)
+ do_change_plan_status(plan, CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE)
+
def void_all_open_invoices(realm: Realm) -> int:
customer = get_customer_by_realm(realm)
if customer is None:
diff --git a/corporate/views.py b/corporate/views.py
index a7c981f6e19..913b4690a45 100644
--- a/corporate/views.py
+++ b/corporate/views.py
@@ -20,6 +20,7 @@ from corporate.lib.stripe import (
BillingError,
do_change_plan_status,
do_replace_payment_source,
+ downgrade_at_the_end_of_billing_cycle,
downgrade_now_without_creating_additional_invoices,
get_latest_seat_count,
make_end_of_cycle_updates_if_needed,
@@ -317,7 +318,7 @@ def change_plan_status(request: HttpRequest, user: UserProfile,
do_change_plan_status(plan, status)
elif status == CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE:
assert(plan.status == CustomerPlan.ACTIVE)
- do_change_plan_status(plan, status)
+ downgrade_at_the_end_of_billing_cycle(user.realm)
elif status == CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE:
assert(plan.billing_schedule == CustomerPlan.MONTHLY)
assert(plan.status == CustomerPlan.ACTIVE)