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: Fix deleting next fixed-price plan via support.

Lauryn Menarde963d5eaa9d7
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 48b5975e9d0..5d4f7cf2ecc 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1553,6 +1553,28 @@ class BillingSession(ABC):
)
return f"Customer can now buy a fixed price {required_plan_tier_name} plan."
+ def delete_fixed_price_plan(self) -> str:
+ # See configure_fixed_price_plan above for how these CustomerPlan
+ # and CustomerPlanOffer objects are created for fixed-price plans.
+ customer = self.get_customer()
+ assert customer is not None
+ current_plan = get_current_plan_by_customer(customer)
+ if current_plan is None:
+ fixed_price_offer = CustomerPlanOffer.objects.filter(
+ customer=customer, status=CustomerPlanOffer.CONFIGURED
+ ).first()
+ assert fixed_price_offer is not None
+ fixed_price_offer.delete()
+ return "Fixed-price plan offer deleted"
+ fixed_price_next_plan = CustomerPlan.objects.filter(
+ customer=customer,
+ status=CustomerPlan.NEVER_STARTED,
+ fixed_price__isnull=False,
+ ).first()
+ assert fixed_price_next_plan is not None
+ fixed_price_next_plan.delete()
+ return "Fixed-price scheduled plan deleted"
+
def update_customer_sponsorship_status(self, sponsorship_pending: bool) -> str:
customer = self.get_customer()
if customer is None:
@@ -3556,14 +3578,7 @@ class BillingSession(ABC):
new_plan_tier = support_request["new_plan_tier"]
success_message = self.do_change_plan_to_new_tier(new_plan_tier)
elif support_type == SupportType.delete_fixed_price_next_plan:
- customer = self.get_customer()
- assert customer is not None
- fixed_price_offer = CustomerPlanOffer.objects.filter(
- customer=customer, status=CustomerPlanOffer.CONFIGURED
- ).first()
- assert fixed_price_offer is not None
- fixed_price_offer.delete()
- success_message = "Fixed price offer deleted"
+ success_message = self.delete_fixed_price_plan()
return success_message
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 0bd93ba63eb..a85afa23900 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -7730,7 +7730,7 @@ class TestRemoteRealmBillingFlow(StripeTestCase, RemoteRealmBillingTestCase):
support_type=SupportType.delete_fixed_price_next_plan,
)
success_message = billing_session.process_support_view_request(support_request)
- self.assertEqual(success_message, "Fixed price offer deleted")
+ self.assertEqual(success_message, "Fixed-price plan offer deleted")
result = self.client_get("/activity/remote/support", {"q": "example.com"})
self.assert_not_in_success_response(["Next plan information:"], result)
self.assert_in_success_response(
diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py
index d98974933c3..91ed1cb2905 100644
--- a/corporate/tests/test_support_views.py
+++ b/corporate/tests/test_support_views.py
@@ -1647,7 +1647,7 @@ class TestSupportEndpoint(ZulipTestCase):
},
)
self.assert_in_success_response(
- ["Fixed price offer deleted"],
+ ["Fixed-price plan offer deleted"],
result,
)
customer.refresh_from_db()
@@ -1796,6 +1796,21 @@ class TestSupportEndpoint(ZulipTestCase):
self.assertEqual(next_plan.charge_automatically, plan.charge_automatically)
self.assertTrue(next_plan.automanage_licenses)
+ # Test deleting the fixed-price next plan via support.
+ result = self.client_post(
+ "/activity/support",
+ {
+ "realm_id": f"{lear_realm.id}",
+ "delete_fixed_price_next_plan": "true",
+ },
+ )
+ self.assert_in_success_response(
+ ["Fixed-price scheduled plan deleted"],
+ result,
+ )
+ next_plan = billing_session.get_next_plan(plan)
+ self.assertIsNone(next_plan)
+
def test_approve_sponsorship_deactivated_realm(self) -> None:
support_admin = self.example_user("iago")
with self.settings(BILLING_ENABLED=True):