Commit Graph

330 Commits

Author SHA1 Message Date
Mateusz Mandera 7d62471d0b remote_realm: Plumb RemoteRealmBillingUser into BillingSession.
Adds the RemoteRealmBillingUser object to the BillingSession in the
views decorated by authenticated_remote_realm_management_endpoint.
2023-12-10 16:15:28 -08:00
Mateusz Mandera 423aebf98e remote_billing: Implement confirmation flow for RemoteRealm auth.
The way the flow goes now is this:
1. The user initiaties login via "Billing" in the gear menu.
2. That takes them to `/self-hosted-billing/` (possibly with a
   `next_page` param if we use that for some gear menu options).
3. The server queries the bouncer to give the user a link with a signed
   access token.
4. The user is redirected to that link (on `selfhosting.zulipchat.com`).
Now we have two cases, either the user is logging in for the first time
and already did in the past.
If this is the first time, we have:
5. The user is asked to fill in their email in a form that's shown,
   pre-filled with the value provided inside the signed access token.
   They POST this to the next endpoint.
6. The next endpoint sends a confirmation email to that address and asks
   the user to go check their email.
7. The user clicks the link in their email is taken to the
   from_confirmation endpoint.
8. Their initial RemoteBillingUser is created, a new signed link like in
   (3) is generated and they're transparently taken back to (4),
   where now that they have a RemoteBillingUser, they're handled
   just like a user who already logged in before:
If the user already logged in before, they go straight here:
9. "Confirm login" page - they're shown their information (email and
   full_name), can update
   their full name in the form if they want. They also accept ToS here
   if necessary. They POST this form back to
   the endpoint and finally have a logged in session.
10. They're redirected to billing (or `next_page`) now that they have
    access.
2023-12-10 16:15:28 -08:00
Aman Agrawal ce56e19d1c stripe: Separate activation of free trial for remote realm/server.
Add a separate setting to only enable free trial for remote
realm / server.
2023-12-10 15:18:01 -08:00
Aman Agrawal ccd60bc7e2 settings: Use original FREE_TRIAL_DAYS for cloud free trials.
* Renamed FREE_TRIAL_DAYS to CLOUD_FREE_TRIAL_DAYS.
* Used `cloud_free_trial_days` to get free trial days secret.
2023-12-10 15:18:01 -08:00
Aman Agrawal 34704daee7 stripe: Use a function to get free trial days. 2023-12-10 15:18:01 -08:00
Aman Agrawal ec86114330 stripe: Fix discounts for legacy server with upgrade scheduled.
We simply apply discount to both the plans.

Since the discount is saved in `customer.default_discount` it
will applied now to any future plans as well, even if customer
downgrades and the upgrades again.
2023-12-09 12:50:05 -08:00
Aman Agrawal 121e5ad3dc stripe: Extract function to get next plan for legacy customers. 2023-12-09 12:50:05 -08:00
Aman Agrawal e44f3d448d stripe: Use `next_plan` instead of `new_plan` for legacy upgrades. 2023-12-09 12:50:05 -08:00
Aman Agrawal 5d3eafcdd4 support: Fix error on discount applied on legacy server.
This is for legacy server **not** scheduled for an upgrade.
2023-12-09 12:50:05 -08:00
Aman Agrawal dca7e654ca billing: Enforce min license for plan on upgrade and billing page. 2023-12-09 12:50:05 -08:00
Mateusz Mandera abdfdeffe4 remote_billing: Implement confirmation flow for legacy servers.
For the last form (with Full Name and ToS consent field), this pretty
shamelessly re-uses and directly renders the
corporate/remote_realm_billing_finalize_login_confirmation.html
template. That's probably good in terms of re-use, but calls for a
clean-up commit that will generalize the name of this template and the
classes/ids in the HTML.
2023-12-08 23:49:10 -08:00
Prakhar Pratyush bf4fdbff12 stripe: Update LicenseLedger for remote realms.
When a remote server uploads statistics, we update the
LicenseLedger using the audit logs uploaded.

We iterate over the RemoteRealmAuditlog data for the concerned
realm starting from the event_time of the last LicenseLedger
created for that customer and update the ledger based on each event.
2023-12-08 12:58:21 -08:00
Prakhar Pratyush ed9b0d330d stripe: Raise 'MissingDataError' while fetching license count.
If the RemoteRealmAuditLog has stale data, it means the server
stopped or never uploaded data. We raise MissingDataError in such
cases when a user action led to calculating licenses count from
stale data.
2023-12-08 12:58:21 -08:00
Prakhar Pratyush 40621478cb zilencer: Add `get_remote_realm_guest_and_non_guest_count`.
We add a 'get_remote_realm_guest_and_non_guest_count'
function that queries 'RemoteRealmAuditLog' to get
the guest and non_guest count for that remote_realm.

This function is used in 'RemoteRealmBillingSession'
to calculate the current count of billed licenses.
2023-12-08 12:58:21 -08:00
Prakhar Pratyush bd99e37910 stripe: Use get_remote_server_guest...count for billing licenses count.
Use 'get_remote_server_guest_and_non_guest_count' function
for the current count of billing licenses in
RemoteServerBillingSession.
2023-12-08 12:58:21 -08:00
Aman Agrawal 3d25c7372a stripe: Remove unused context parameter. 2023-12-08 11:24:15 -08:00
Aman Agrawal 76d9aff5a6 sponsorship: Allow remote orgs to request a plan type.
Sponsorship and billing pages modified to reflect the correctly
requested sponsorship plan name.
Add a line break before "Contact Zulip support".
2023-12-08 11:24:15 -08:00
Tim Abbott 0f163cedbc corporate: Tighten coverage checks in decorator.py. 2023-12-08 09:48:15 -08:00
Aman Agrawal 9ab5f65cc4 stripe: Handle schedule change audit log type for remote realm/server.
This seems to have been accidentally skipped when adding
audit logs for free trials when changing billing schedule.
2023-12-08 09:21:18 -08:00
Aman Agrawal 134a05ff5e billing: Hide license management fields for free trial states.
* For free trial, don't show number of licenses for current billing period.
* For free trial scheduled to downgrade, don't show number of
  licenses for next billing period.
2023-12-08 09:21:18 -08:00
Aman Agrawal 2165486c88 upgrade: Allow showing downgrade success message for legacy server. 2023-12-07 13:55:39 -08:00
Aman Agrawal 825986ac3a billing: Allow legacy servers to cancel upgrade. 2023-12-07 13:55:39 -08:00
Lauryn Menard c94c194ea7 corporate: Send email community plan sponsorship approved. 2023-12-07 13:17:14 -08:00
Aman Agrawal 860e4f6060 stripe: Don't change plan tier before the plan becomes live.
For new plans that have not started, the tier change should only
happen when they become live.
2023-12-06 12:04:10 -08:00
Aman Agrawal ec7fd94782 billing: Show correct info for to be upgraded legacy plan server. 2023-12-06 12:04:10 -08:00
Aman Agrawal f5a96cba05 stripe: Don't modify non-status details of legacy-server plan.
The new plan already has the details for pricing and how to
charge customer and ideally should be used to show information
about it on billing page.
2023-12-06 12:04:10 -08:00
Aman Agrawal 30f7d5e8df stripe: Don't create `LicenseLedger` entries for non-live plans. 2023-12-06 12:04:10 -08:00
Aman Agrawal fec155ea9c stripe: Extract method to get billing page context. 2023-12-06 12:04:10 -08:00
Aman Agrawal 0d3c68cefb stripe: Rearrange code. 2023-12-06 12:04:10 -08:00
Aman Agrawal 74ef619412 stripe: Active plans always have last_ledger_entry. 2023-12-06 12:04:10 -08:00
Aman Agrawal f99214e866 stripe: Plan is always defined for get_billing_page_context calls. 2023-12-06 12:04:10 -08:00
Lauryn Menard 906e667a70 corporate: Implement support_url for all BillingSession child classes.
Adds a helper since there are only a few different parameters for
all BillingSession child clases, `build_support_url`.

Also, renames `get_support_url` to more explicitly note that it
is for realms: `get_realm_support_url`.
2023-12-06 11:04:54 -08:00
Lauryn Menard 46dab1beb9 emails: Replace string_id from sponsorship request email context.
Use of `string_id` in the sponsorship request email content was
removed in commit d3834f8b9, but it is still used in the email
subject.

Updates the email subject to use the billing_entity_display_name,
which is still the Realm.string_id for Zulip Cloud organizations.

Sets this string as "billing_entity" in the context and subject
template.
2023-12-06 11:04:54 -08:00
Lauryn Menard ea725aaaf3 support: Handle missing current licenses data for support views. 2023-12-06 11:01:26 -08:00
Lauryn Menard d079a13760 support: Use shared template for current plan details on support views.
Moves the section in support views for any current plan details
to a new template: `templates/analytics/current_plan_details.html`.

Also, updates the PlanData dataclass to have a boolean that checks
if the current plan tier is the self-hosted legacy plan.
2023-12-06 11:01:26 -08:00
Aman Agrawal 49908ba166 sponsorship: Populate sponsorship page with correct context.
Fixes sponsorship page to work for remote realm and server.
2023-12-05 23:44:29 -08:00
Aman Agrawal 044cb820f8 stripe: Fix legacy server upgrade to business plan.
I had pushed a similar change in #28017 but seems to have been lost.
2023-12-05 23:44:29 -08:00
Prakhar Pratyush e5d71fe5ac stripe: Move `update_license_ledger_if_needed` to BillingSession.
This commit moves the 'update_license_ledger_if_needed' and its
helper function 'update_license_ledger_for_automanaged_plan'
to the 'BillingSession' abstract class.

This refactoring will help in minimizing duplicate code while
supporting both realm and remote_server customers.
2023-12-05 12:51:41 -08:00
Prakhar Pratyush 133291ec2d stripe: Move `update_license_ledger_for_manual_plan` to BillingSession.
Moves the 'update_license_ledger_for_manual_plan' function
to the 'BillingSession' abstract class.

This refactoring will help in minimizing duplicate code while
supporting both realm and remote_server customers.
2023-12-05 12:51:41 -08:00
Lauryn Menard 6c5b419267 support: Add downgrade current plan actions to remote servers. 2023-12-05 12:48:42 -08:00
Aman Agrawal 1a063986e3 billing: Render page for legacy server scheduled for upgrade. 2023-12-04 12:36:24 -08:00
Aman Agrawal cd45b6f6f8 upgrade: Allow legacy servers to upgrade to business plan. 2023-12-04 12:36:24 -08:00
Aman Agrawal 9935f002ec stripe: Fill `get_type_of_plan_tier_change` for remote realm/server. 2023-12-04 12:36:24 -08:00
Aman Agrawal f22ccd3125 stripe: Render upgrade page for remote servers on legacy plan. 2023-12-04 12:36:24 -08:00
Aman Agrawal 7d83508235 commands: Add script to create servers on legacy plan.
Also adds `SWITCH_PLAN_TIER_AT_PLAN_END` for `CustomerPlan`
which will be used to mark status of remote server legacy
plans which are scheduled for an upgrade.
2023-12-04 12:36:24 -08:00
Lauryn Menard 45df5750ae corporate: Remove now unused is_sponsored_realm.
This has been replaced with the is_sponsored method in
the RealmBillingSession class.
2023-12-04 07:15:15 -08:00
Lauryn Menard 5eabd51702 corporate: Make is_sponsored_or_pending not abstract in BillingSession.
The logic for BillingSession.is_sponsored_or_pending would be the
same for all three child classes of BillingSession, so this should
be a method on the BillingSession abstract class.
2023-12-04 07:15:15 -08:00
Aman Agrawal a59245e932 billing: Make various buttons on billing page work.
We pass billing_base_url to the template and use it to construct
session specific URLs. Also, add corresponding function on server
to support them.
2023-12-03 15:15:04 -08:00
Aman Agrawal 7e7af6266d stripe: Rename get_metadata to use for both billing and upgrade. 2023-12-03 15:15:04 -08:00
Aman Agrawal f942bbd70f stripe: Show tier information correctly on billing and upgrade page. 2023-12-03 15:15:04 -08:00