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: Fix customer charged for upgrade during free trial.

Aman Agrawal8e617f5df8c0
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 3420809e9dd..179163cffff 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1138,6 +1138,7 @@ class BillingSession(ABC):
remote_server_legacy_plan: Optional[CustomerPlan] = None,
should_schedule_upgrade_for_legacy_remote_server: bool = False,
) -> None:
+ is_self_hosted_billing = not isinstance(self, RealmBillingSession)
customer = self.update_or_create_stripe_customer()
assert customer.stripe_customer_id is not None # for mypy
self.ensure_current_plan_is_upgradable(customer, plan_tier)
@@ -1158,6 +1159,7 @@ class BillingSession(ABC):
customer.default_discount,
free_trial,
billing_cycle_anchor,
+ is_self_hosted_billing,
)
# TODO: The correctness of this relies on user creation, deactivation, etc being
@@ -1323,7 +1325,8 @@ class BillingSession(ABC):
"monthly": CustomerPlan.BILLING_SCHEDULE_MONTHLY,
}[schedule]
data: Dict[str, Any] = {}
- free_trial = is_free_trial_offer_enabled()
+ is_self_hosted_billing = not isinstance(self, RealmBillingSession)
+ free_trial = is_free_trial_offer_enabled(is_self_hosted_billing)
remote_server_legacy_plan = self.get_remote_server_legacy_plan(customer)
should_schedule_upgrade_for_legacy_remote_server = (
remote_server_legacy_plan is not None
@@ -1341,7 +1344,7 @@ class BillingSession(ABC):
automanage_licenses,
billing_schedule,
charge_automatically,
- is_free_trial_offer_enabled(),
+ free_trial,
remote_server_legacy_plan,
should_schedule_upgrade_for_legacy_remote_server,
)
@@ -3641,8 +3644,8 @@ def get_free_trial_days(is_self_hosted_billing: bool = False) -> Optional[int]:
return settings.CLOUD_FREE_TRIAL_DAYS
-def is_free_trial_offer_enabled() -> bool:
- return settings.CLOUD_FREE_TRIAL_DAYS not in (None, 0)
+def is_free_trial_offer_enabled(is_self_hosted_billing: bool) -> bool:
+ return get_free_trial_days(is_self_hosted_billing) not in (None, 0)
def ensure_customer_does_not_have_active_plan(customer: Customer) -> None:
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 0b3b4f09273..be73803a66e 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -599,7 +599,7 @@ class StripeTestCase(ZulipTestCase):
# Return early if the upgrade request failed.
return upgrade_json_response
- if invoice or not talk_to_stripe or is_free_trial_offer_enabled():
+ if invoice or not talk_to_stripe or is_free_trial_offer_enabled(False):
# Upgrade already happened for free trial or invoice realms.
return upgrade_json_response
diff --git a/zerver/views/auth.py b/zerver/views/auth.py
index 5c447abeb53..093e91d8219 100644
--- a/zerver/views/auth.py
+++ b/zerver/views/auth.py
@@ -392,7 +392,7 @@ def login_or_register_remote_user(request: HttpRequest, result: ExternalAuthResu
if is_realm_creation is not None and settings.BILLING_ENABLED:
from corporate.lib.stripe import is_free_trial_offer_enabled
- if is_free_trial_offer_enabled():
+ if is_free_trial_offer_enabled(False):
redirect_to = reverse("upgrade_page")
redirect_to = get_safe_redirect_to(redirect_to, user_profile.realm.uri)