From ce56e19d1c3fbe857e06260e60a4c34cd6956cd7 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Sun, 10 Dec 2023 04:13:00 +0000 Subject: [PATCH] stripe: Separate activation of free trial for remote realm/server. Add a separate setting to only enable free trial for remote realm / server. --- corporate/lib/stripe.py | 18 ++++++++++++++---- corporate/views/portico.py | 6 +++--- zproject/default_settings.py | 1 + 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 6656b3f99d..a3715efcd0 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -1813,10 +1813,16 @@ class BillingSession(ABC): free_trial_end_date = None # Don't show free trial for remote servers on legacy plan. if remote_server_legacy_plan_end_date is None: - free_trial_days = get_free_trial_days() + is_self_hosted_billing = not isinstance(self, RealmBillingSession) + free_trial_days = get_free_trial_days(is_self_hosted_billing) if free_trial_days is not None: _, _, free_trial_end, _ = compute_plan_parameters( - tier, False, CustomerPlan.BILLING_SCHEDULE_ANNUAL, None, True + tier, + False, + CustomerPlan.BILLING_SCHEDULE_ANNUAL, + None, + True, + is_self_hosted_billing=is_self_hosted_billing, ) free_trial_end_date = ( f"{free_trial_end:%B} {free_trial_end.day}, {free_trial_end.year}" @@ -3600,6 +3606,7 @@ def compute_plan_parameters( discount: Optional[Decimal], free_trial: bool = False, billing_cycle_anchor: Optional[datetime] = None, + is_self_hosted_billing: bool = False, ) -> Tuple[datetime, datetime, datetime, int]: # Everything in Stripe is stored as timestamps with 1 second resolution, # so standardize on 1 second resolution. @@ -3621,13 +3628,16 @@ def compute_plan_parameters( next_invoice_date = add_months(billing_cycle_anchor, 1) if free_trial: period_end = billing_cycle_anchor + timedelta( - days=assert_is_not_none(get_free_trial_days()) + days=assert_is_not_none(get_free_trial_days(is_self_hosted_billing)) ) next_invoice_date = period_end return billing_cycle_anchor, next_invoice_date, period_end, price_per_license -def get_free_trial_days() -> Optional[int]: +def get_free_trial_days(is_self_hosted_billing: bool = False) -> Optional[int]: + if is_self_hosted_billing: + return settings.SELF_HOSTING_FREE_TRIAL_DAYS + return settings.CLOUD_FREE_TRIAL_DAYS diff --git a/corporate/views/portico.py b/corporate/views/portico.py index f14662a82a..f938be2798 100644 --- a/corporate/views/portico.py +++ b/corporate/views/portico.py @@ -90,7 +90,7 @@ def plans_view(request: HttpRequest) -> HttpResponse: context = PlansPageContext( is_cloud_realm=True, sponsorship_url=reverse("sponsorship_request"), - free_trial_days=get_free_trial_days(), + free_trial_days=get_free_trial_days(False), is_sponsored=realm is not None and realm.plan_type == Realm.PLAN_TYPE_STANDARD_FREE, ) if is_subdomain_root_or_alias(request): @@ -137,7 +137,7 @@ def remote_realm_plans_page( sponsorship_url=reverse( "remote_realm_sponsorship_page", args=(billing_session.remote_realm.uuid,) ), - free_trial_days=get_free_trial_days(), + free_trial_days=get_free_trial_days(True), billing_base_url=billing_session.billing_base_url, is_sponsored=billing_session.is_sponsored(), ) @@ -172,7 +172,7 @@ def remote_server_plans_page( sponsorship_url=reverse( "remote_server_sponsorship_page", args=(billing_session.remote_server.uuid,) ), - free_trial_days=get_free_trial_days(), + free_trial_days=get_free_trial_days(True), billing_base_url=billing_session.billing_base_url, is_sponsored=billing_session.is_sponsored(), ) diff --git a/zproject/default_settings.py b/zproject/default_settings.py index 76bd50accc..0f6e3a22ba 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -547,6 +547,7 @@ ARCHIVED_DATA_VACUUMING_DELAY_DAYS = 30 BILLING_ENABLED = False CLOUD_FREE_TRIAL_DAYS: Optional[int] = int(get_secret("cloud_free_trial_days", "0")) +SELF_HOSTING_FREE_TRIAL_DAYS: Optional[int] = int(get_secret("self_hosting_free_trial_days", "0")) # Custom message (supports HTML) to be shown in the navbar of landing pages. Used mainly for # making announcements.