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.

stripe: Change plan type immediately after creating a live plan.

Aman Agrawalb1ea8f3c1c6a
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index c6c82758555..3d33537fd41 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1745,7 +1745,16 @@ class BillingSession(ABC):
customer=customer, next_invoice_date=next_invoice_date, **plan_params
)
+ self.write_to_audit_log(
+ event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED,
+ event_time=event_time,
+ extra_data=plan_params,
+ )
+
if plan.status < CustomerPlan.LIVE_STATUS_THRESHOLD:
+ # Tier and usage limit change will happen when plan becomes live.
+ self.do_change_plan_type(tier=plan_tier)
+
# LicenseLedger entries are way for us to charge customer and track their license usage.
# So, we should only create these entries for live plans.
ledger_entry = LicenseLedger.objects.create(
@@ -1777,12 +1786,6 @@ class BillingSession(ABC):
# Creates due today invoice for additional licenses.
self.invoice_plan(plan, event_time)
- self.write_to_audit_log(
- event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED,
- event_time=event_time,
- extra_data=plan_params,
- )
-
if not stripe_invoice_paid and not (
free_trial or should_schedule_upgrade_for_legacy_remote_server
):
@@ -1796,9 +1799,6 @@ class BillingSession(ABC):
billing_schedule=billing_schedule,
charge_automatically=False,
)
- if plan.status < CustomerPlan.LIVE_STATUS_THRESHOLD:
- # Tier and usage limit change will happen when plan becomes live.
- self.do_change_plan_type(tier=plan_tier)
def do_upgrade(self, upgrade_request: UpgradeRequest) -> Dict[str, Any]:
customer = self.get_customer()
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 29d047418e2..316dc214773 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -1062,13 +1062,14 @@ class StripeTest(StripeTestCase):
.order_by("id")
)
self.assertEqual(
- audit_log_entries[:2],
+ audit_log_entries[:3],
[
(
RealmAuditLog.STRIPE_CUSTOMER_CREATED,
timestamp_to_datetime(stripe_customer.created),
),
(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),
+ (RealmAuditLog.REALM_PLAN_TYPE_CHANGED, self.now),
],
)
self.assertEqual(audit_log_entries[2][0], RealmAuditLog.REALM_PLAN_TYPE_CHANGED)
@@ -1173,7 +1174,7 @@ class StripeTest(StripeTestCase):
.order_by("id")
)
self.assertEqual(
- audit_log_entries[:3],
+ audit_log_entries[:4],
[
(
RealmAuditLog.STRIPE_CUSTOMER_CREATED,
@@ -1184,6 +1185,7 @@ class StripeTest(StripeTestCase):
self.now,
),
(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),
+ (RealmAuditLog.REALM_PLAN_TYPE_CHANGED, self.now),
],
)
self.assertEqual(audit_log_entries[3][0], RealmAuditLog.REALM_PLAN_TYPE_CHANGED)
@@ -1391,13 +1393,14 @@ class StripeTest(StripeTestCase):
.order_by("id")
)
self.assertEqual(
- audit_log_entries[:2],
+ audit_log_entries[:3],
[
(
RealmAuditLog.STRIPE_CUSTOMER_CREATED,
timestamp_to_datetime(stripe_customer.created),
),
(RealmAuditLog.CUSTOMER_PLAN_CREATED, self.now),
+ (RealmAuditLog.REALM_PLAN_TYPE_CHANGED, self.now),
],
)
self.assertEqual(audit_log_entries[2][0], RealmAuditLog.REALM_PLAN_TYPE_CHANGED)