From dbaea757aec19b2bc33c7501fc5b4de3506d6398 Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Thu, 13 Aug 2020 16:36:05 +0530 Subject: [PATCH] billing: Create downgrade_at_the_end_of_billing_cycle. --- corporate/lib/stripe.py | 5 +++++ corporate/views.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index e9fc4f3bd1..0c2d7fdfe8 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 a7c981f6e1..913b4690a4 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)