stripe: End legacy plan before approving full sponsorship.

This commit is contained in:
Aman Agrawal 2023-12-14 04:35:11 +00:00 committed by Tim Abbott
parent 612f2c73d6
commit a5311c8032
1 changed files with 18 additions and 0 deletions

View File

@ -3204,6 +3204,15 @@ class RemoteRealmBillingSession(BillingSession):
if error_message != "": if error_message != "":
return error_message return error_message
if self.remote_realm.plan_type == RemoteRealm.PLAN_TYPE_SELF_MANAGED_LEGACY:
plan = get_current_plan_by_customer(customer)
# Ideally we should have always have a plan here but since this is support page, we can be lenient about it.
if plan is not None:
assert self.get_next_plan(plan) is None
assert plan.tier == CustomerPlan.TIER_SELF_HOSTED_LEGACY
plan.status = CustomerPlan.ENDED
plan.save(update_fields=["status"])
self.do_change_plan_type(tier=None, is_sponsored=True) self.do_change_plan_type(tier=None, is_sponsored=True)
if customer is not None and customer.sponsorship_pending: if customer is not None and customer.sponsorship_pending:
customer.sponsorship_pending = False customer.sponsorship_pending = False
@ -3596,6 +3605,15 @@ class RemoteServerBillingSession(BillingSession):
if error_message != "": if error_message != "":
return error_message return error_message
if self.remote_server.plan_type == RemoteZulipServer.PLAN_TYPE_SELF_MANAGED_LEGACY:
plan = get_current_plan_by_customer(customer)
# Ideally we should have always have a plan here but since this is support page, we can be lenient about it.
if plan is not None:
assert self.get_next_plan(plan) is None
assert plan.tier == CustomerPlan.TIER_SELF_HOSTED_LEGACY
plan.status = CustomerPlan.ENDED
plan.save(update_fields=["status"])
self.do_change_plan_type(tier=None, is_sponsored=True) self.do_change_plan_type(tier=None, is_sponsored=True)
if customer is not None and customer.sponsorship_pending: if customer is not None and customer.sponsorship_pending:
customer.sponsorship_pending = False customer.sponsorship_pending = False