Commit Graph

647 Commits

Author SHA1 Message Date
Aman Agrawal 222077804b upgrade: Simplify getting session data for card update. 2023-12-01 08:55:58 -08:00
Aman Agrawal 0286f10816 stripe: Move non class specific function outside.
Doesn't seem to benefit from being defined inside the class.
2023-12-01 08:55:58 -08:00
Aman Agrawal 25cf0f71a3 event_status: Remove unused variables in context. 2023-12-01 08:55:58 -08:00
Aman Agrawal 953f0f436e stripe_event_handler: Rename get_billing_session. 2023-12-01 08:55:58 -08:00
Mateusz Mandera 7fad8f1f54 remote_billing: Implement session expiry mechanism.
We still need to add better UX than these JSON errors. We'll want to
utilize the next parameter and redirect the user back to login.
2023-11-30 15:51:10 -08:00
Mateusz Mandera ea9e2ece49 remote_billing: Extract RemoteBillingUserDict sub-dict. 2023-11-30 15:51:10 -08:00
Mateusz Mandera 5a198c639e remote_billing: Sort out remote_billing_identities typing.
This does two important things:
1. Fix return type of get_identity_dict_from_session to correctly be
   Optional[Union[RemoteBillingIdentityDict, LegacyServerIdentityDict]].
   RemoteBillingIdentityDict is the type in the 8.0+ auth flow,
   LegacyServerIdentityDict is the type in old servers flow, where only
   the server uuid info is available.
2. The uuid key used in request.session["remote_billing_identities"]
   should be explicitly namespaced depending on which flow and type
   we're
   dealing with - to avoid confusion in case of collisions between a
   realm and server that have the same UUID. Such a situation should not
   occur naturally and I haven't come up with any actual exploitation
   ideas that could utilize this by manipulating your server/realm
   uuids, but it's much easier to just not think about such collision
   security implications by making them impossible.
2023-11-30 15:51:10 -08:00
Aman Agrawal 8d485726e4 upgrade: Make add card workflow functional.
Add / update card for remote realms on /upgrade page works now.
2023-11-30 11:22:19 -08:00
Aman Agrawal a39cb2bda3 session: Migrate to typed endpoint. 2023-11-30 11:22:19 -08:00
Aman Agrawal d05315b051 event_status: Migrate to typed_endpoint. 2023-11-30 11:22:19 -08:00
Aman Agrawal 05f2ad5299 event_status: Migrate to typed_endpoint. 2023-11-30 11:22:19 -08:00
Aman Agrawal 4d60c3a96c models: Allow realm_id to be blank.
We cannot provide realm_id for some remote session logs.
2023-11-30 11:22:19 -08:00
Aman Agrawal 5c9a10da31 stripe: Call log create method once.
Makes it easier to look at.
2023-11-30 11:22:19 -08:00
Tim Abbott cab0215f3f decorator: Pass RemoteServerBillingSession to views. 2023-11-30 11:22:19 -08:00
Aman Agrawal 7540e70cc8 decorator: Pass remote billing session instead of remote realm.
Since endpoints using the
`authenticated_remote_realm_management_endpoint` decorator
want to initialize a billing session and if need be remote_realm
is accessible to via the session variable.
2023-11-30 11:22:19 -08:00
Aman Agrawal 1df8e00d7c remote_billing: Redirect to upgrade/sponsorship page based on next.
We pass `next` parameter with /self-hosted-billing to redirect
users to the intended page after login.

Fixed realm_uuid incorrectly required in remote_realm_upgrade_page.
2023-11-30 11:22:19 -08:00
Lauryn Menard 2c34dcf7dc corporate: Use enum value for type of plan tier change.
Updates do_change_plan_to_new_tier in BillingSession to use an
enum for the value returned when checking for a valid change
between two plan tier types. This makes it more explicit that
the implementation for a valid upgrade in plan tier will be
different from a valid downgrade in plan tier.
2023-11-30 09:43:55 -08:00
Lauryn Menard 4eea4d4717 corporate: Move invoice_plan to BillingSession abstract class. 2023-11-30 09:43:55 -08:00
Tim Abbott ebb02bad8f billing: Add INVOICING_STATUS_ prefix to values. 2023-11-29 23:32:56 -08:00
Tim Abbott 610338d192 billing: Add BILLING_SCHEDULE_ prefix to values. 2023-11-29 23:32:56 -08:00
Tim Abbott 5d6b635efe billing: Use better variable names for plan tiers.
The existing values didn't have our standard type-prefixing naming
scheme.

Add some extra unused placeholder values while we're at it.
2023-11-29 23:32:56 -08:00
Tim Abbott a01618d633 billing: Add BillingSession support for requesting sponsorship. 2023-11-29 19:04:32 -08:00
Tim Abbott 1691205306 billing: Remove unnecessary sponsorship request variables. 2023-11-29 19:04:32 -08:00
Aman Agrawal e43b51b01e stripe: Extract common helper function. 2023-11-29 19:04:32 -08:00
Tim Abbott 405c28252a decorator: Don't pass processed args/kwargs onwards.
We've already processed the only URL parameters we intend to support
to determine which RemoteRealm or RemoteZulipServer is involved, so
there should be nothing further to do here.

And it's cleaner to not have to write the downstream code to expect
these unnecessary parameters.
2023-11-29 19:04:32 -08:00
Aman Agrawal ba11d0fe5d decorator: Add decorator to provide remote_server to endpoint. 2023-11-29 19:04:32 -08:00
Aman Agrawal 5277ebb268 decorator: Remove wrong positional argument remote_realm.
Not sure how this even worked with this required argument.
2023-11-29 19:04:32 -08:00
Aman Agrawal d8f8152f9b models: Make requested_by optional in sponsorship request model.
`requested_by` needs to be a UserProfile which is not available
for remote server sponsorship requests.
2023-11-29 19:04:32 -08:00
Aman Agrawal d999d18476 upgrade: Use valid form data to fill email context. 2023-11-29 19:04:32 -08:00
Aman Agrawal cd7893b1bf sponsorship: Use `organization_type` as field name for simplification. 2023-11-29 19:04:32 -08:00
Mateusz Mandera 2765c63f56 remote_billing: Add flow for legacy servers. 2023-11-29 14:40:27 -08:00
Prakhar Pratyush 44d8dc66d2 send_email: Update 'from_name' for non user-facing emails.
This commit performs a minor update in 'from_name' text for
'support' and 'sponsorship' emails.

Removes capitalization and adds a comment specifying that the
emails are not user-facing.
2023-11-29 14:20:01 -08:00
Alex Vandiver 61fc838179 python: Switch mocking of timezone_now to time_machine. 2023-11-28 15:10:39 -08:00
Alex Vandiver f4cbb494ac test_remote_counts: Insert in date order.
Inserting these in order means that they have dates which ascend with
their ids and remote_ids, for a more accurate simulation.
2023-11-28 09:46:48 -08:00
Aman Agrawal e8fed998ce test_stripe: Add method to better mock stripe invoice creation. 2023-11-28 08:58:19 -08:00
Aman Agrawal 28a49be161 get_initial_upgrade_context: Use tier passed as part of request. 2023-11-28 08:58:19 -08:00
Alya Abbott fcd0783202 upgrade: Simplify free trial upgrade page. 2023-11-28 08:57:27 -08:00
Alya Abbott 9788e7514f billing: Edit text of free trial upgrade page. 2023-11-27 14:17:18 -08:00
Aman Agrawal b35a792623 billing: Allow free trial orgs to switch billing frequency.
Fixes #27855
2023-11-27 14:17:18 -08:00
Aman Agrawal 1f8d3fc48f stripe: Extract method to get next billing cycle. 2023-11-27 14:17:18 -08:00
Aman Agrawal 482b5d8871 upgrade: Minor text changes to free trial page.
Fixes #27684
2023-11-27 14:17:18 -08:00
Aman Agrawal fe1a40279c billing: Downgrade realm at the end of free trial.
Fixes #27875

Instead of immediately ending the free trial, we end the free trial
at the end of the cycle.
2023-11-27 14:17:18 -08:00
Aman Agrawal 22c333d135 stripe: Don't allow free trial users to have paid plan states.
Free trial users can only switch to `ACTIVE` or `ENDED`
as possible states. To switch to any other state, they need to
be `ACTIVE` first.
2023-11-27 14:17:18 -08:00
Aman Agrawal d43a60eb9d models: Add status text for some plan status states. 2023-11-27 14:17:18 -08:00
Tim Abbott 7de061cf10 billing: Inline is_realm_on_paid_plan.
This helps simplify the BillingSession interface to have less
realm-specific functions outside RealmBillingSesssion.
2023-11-27 09:01:56 -08:00
Prakhar Pratyush f8b0e16ff2 stripe: Add get_sponsorship_request_context method to BillingSession.
This commit refactors 'sponsorship_request' view and adds
'BillingSession.get_sponsorship_request' method.

This refactoring will help in minimizing duplicate code
while supporting both realm and remote_Server customers.
2023-11-27 09:01:56 -08:00
Prakhar Pratyush 1b17626327 stripe: Add 'is_sponsored' method to 'BillingSession' class.
This prep commit adds a 'is_sponsored' method as we need
to explicitly check this in 'event_status' view.
2023-11-27 09:01:56 -08:00
Prakhar Pratyush 29f77bfd31 stripe: Add 'get_event_status' method to the 'BillingSession' class.
This commit refactors 'event_status' view and adds
'BillingSession.get_event_status' method.

This refactoring will help in minimizing duplicate code
while supporting both realm and remote_server customers.
2023-11-27 09:01:56 -08:00
Aman Agrawal 20cae359d1 sponsorship: Show correct plan for sponsored without CustomerPlan.
For users on limited plan, if approved for full sponsorship
via support page, we don't create a CustomerPlan for them, but
they are fully sponsored.
2023-11-27 08:23:36 -08:00
Aman Agrawal 3615fa4745 sponsorship: Use customer instead of realm to store sponsorship data.
Since Customer already stores the realm it is linked to and
customer is always created to store sponsorship request, we directly
use customer to link to the sponsorship data for the realm.
2023-11-27 08:23:36 -08:00
Aman Agrawal ede73fc2c6 decorator: Add wrapper to directly pass remote_realm to view_func. 2023-11-26 20:23:24 -08:00
Aman Agrawal 354330d81b decorator: Move self_hosting_management_endpoint wrapper to corporate. 2023-11-26 20:23:24 -08:00
Mateusz Mandera c79d116f8c tests: Add basic tests for remote billing auth flow. 2023-11-26 19:57:12 -08:00
Lauryn Menard b167eeff08 corporate: Create change plan tier function for BillingSession.
Moves and generalizes `switch_realm_from_standard_to_plus_plan`
in stripe.py to be a more general function for changing a
CustomerPlan to a new and valid tier, `do_change_plan_to_new_tier`.

Adds a helper function with the previous function name to be used
for the support view and management command for changing a realm
from the Standard plan tier to the Plus plan tier.
2023-11-26 19:39:52 -08:00
Lauryn Menard a00e687d02 corporate: Update stripe create_balance_transaction description. 2023-11-26 19:39:52 -08:00
Lauryn Menard 1f1f1b913b corporate: Simplify initial plan tier switch check.
Simplifies the initial check for switching a customer plan tier
for an existing and active plan, so that it is more generic.
2023-11-26 19:39:52 -08:00
Lauryn Menard 39bfab0ec4 corporate: Move plan tier change to separate helper function.
Renames CustomerPlan.SWITCH_NOW_FROM_STANDARD_TO_PLUS to be more
generic, CustomerPlan.SWITCH_PLAN_TIER_NOW.

Because the plan tier change is immediate, moves the code to end
the current plan with the old tier and create the new plan with
the new tier from `make_end_of_cycle_updates_if_needed` to instead
be in a separate helper function, `switch_plan_tier`.
2023-11-26 19:39:52 -08:00
Lauryn Menard 30f0005799 corporate: Extract calculation of amount to credit for tier change. 2023-11-26 19:39:52 -08:00
Aman Agrawal 3cfcd0efee remote_upgrade_page: Add /upgrade URL for self hosted realms. 2023-11-24 09:22:02 -08:00
Aman Agrawal caf2b7da26 stripe: Use remote_billing_url for redirecting to sponsorship page.
The will make redirects to sponsorship page work for all
BillingSession child classes.
2023-11-24 09:22:02 -08:00
Aman Agrawal 6ad9217fbf stripe: Set discount to None for 0 discount. 2023-11-24 09:22:02 -08:00
Aman Agrawal 6040ffb94b stripe: Verify context via TypedDict for upgrade page. 2023-11-24 09:22:02 -08:00
Aman Agrawal e3abd57dce stripe: Rename update_context_initial_upgrade. 2023-11-24 09:22:02 -08:00
Aman Agrawal 053f30ca25 stripe: Sort upgrade page context keys.
This will help us verify changes easily.
2023-11-24 09:22:02 -08:00
Aman Agrawal 4844ef9810 upgrade: Pass customer_name instead of realm object to upgrade context.
This will help simplify things for remote realms.
2023-11-24 09:22:02 -08:00
Aman Agrawal ace14e5a7d remote_billing_page: Extract method to get RemoteBillingIdentityDict.
This will likely be used in other files.
2023-11-24 09:22:02 -08:00
Aman Agrawal f006be0cdf initial_upgrade: Rename to upgrade_page.
Replaced for "(initial_upgrade)", " initial_upgrade"
`'initial_upgrade'` and `"initial_upgrade"`.
2023-11-24 09:22:02 -08:00
Aman Agrawal 95f5d8bdb8 billing: Note applied discount on upgrade and billing pages.
Fixes #27526
2023-11-23 10:32:39 -08:00
Aman Agrawal 07d29126fd sponsorship: Improve page for sponsorship pending orgs.
Fixes #27686
2023-11-23 10:32:39 -08:00
Aman Agrawal 003b29ba14 billing_page: Redirect orgs on paid plans with sponsorship pending.
Redirect sponsorship pending realms on a paid plan to billing page
with banner which reflects the current status of their request.
2023-11-23 10:32:39 -08:00
Aman Agrawal 74d8a050e4 billing_page: Extract method to check if realm is on paid plan. 2023-11-23 10:32:39 -08:00
Aman Agrawal 5422dd3661 sponsorship: Improve sponsorship page for sponsored realms. 2023-11-23 10:32:39 -08:00
Prakhar Pratyush 51b39cb682 stripe: Add 'do_update_plan' method to the 'BillingSession' class.
This commit moves a major portion of the 'update_plan`
view to a new shared 'BillingSession.do_update_plan' method.

This refactoring will help in minimizing duplicate code
while supporting both realm and remote_server customers.
2023-11-23 09:01:45 -08:00
Tim Abbott efa423395f billing: Make support_session an explicit parameter. 2023-11-23 09:01:45 -08:00
Mateusz Mandera 3958743b33 corporate: Add prototype authentication system for self-hosters.
This makes it possible for a self-hosted realm administrator to
directly access a logged-page on the push notifications bouncer
service, enabling billing, support contacts, and other administrator
for enterprise customers to be managed without manual setup.
2023-11-22 17:03:47 -08:00
Aman Agrawal d82efbd503 free_trial: Remove extra onboarding flow.
We still redirect free trial users to upgrade page on first
signup but no longer pass the onboarding param.
2023-11-22 08:06:22 -08:00
Aman Agrawal 2218c49244 billing: Minor changes to text for free trial.
Fixes #27685
2023-11-22 08:06:22 -08:00
Prakhar Pratyush 476b44ae67 stripe: Use 'get_price_per_license' in 'get_initial_upgrade_context'.
This commit updates the 'get_initial_upgrade_context' method
to use 'get_price_per_license' for determining 'annual_price'
and 'monthly_price' based on tier and discount instead of hardcoding.

Also, removed the 'percent_off' page_params as
'get_price_per_license' already performs the price calculation
taking discount into consideration.
2023-11-21 23:39:18 -08:00
Aman Agrawal de267b964c event_status: Return user back to same license management after session.
If the update / add card session is successful, return user to
manual license management page if user was on it before clicking
the add / update card button.
2023-11-21 11:44:04 -08:00
Aman Agrawal 69d8442ab4 billing: Allow user to switch between billing frequencies. 2023-11-21 10:42:12 -08:00
Tim Abbott e3a3f36225 billing: Rename do_initial_upgrade.
This function gets context without doing anything, and so deserves a
name that hints that.
2023-11-20 12:04:56 -08:00
Aman Agrawal 09009ab03a upgrade: Separate add card and purchase upgrade flow.
We now let user add / update card in a separate session and then
charge users after clicking on the purchase button.
2023-11-20 12:04:56 -08:00
Prakhar Pratyush 26c5149d31 stripe: Add 'do_initial_upgrade' method to the 'BillingSession' class.
This commit moves a major portion of the 'initial_upgrade`
view to a new shared 'BillingSession.do_initial_upgrade' method.

This refactoring will help in minimizing duplicate code
while supporting both realm and remote_server customers.
2023-11-20 08:00:05 -08:00
Lauryn Menard 11cb37c9a4 billing: Add prototype remote billing sessions.
These new models are incomplete and totally untested, but merging this
will provide valuable scaffolding for doing smaller PRs working on
individual gaps, and reveals a clear set of TODOs/refactoring/model
changes needed to support where want to end up.

Co-authored-by: Tim Abbott <tabbott@zulip.com>
2023-11-17 12:58:37 -08:00
Tim Abbott f916385cab corporate: Adjust models for RemoteRealm customers. 2023-11-17 12:58:37 -08:00
Tim Abbott c5940bd68f zilencer: Make plan types less weird. 2023-11-17 12:58:37 -08:00
Prakhar Pratyush 135d7c03cc stripe: Add 'get_billing_page_context' method to 'BillingSession'.
This commit moves the main context creation part of the
'billing_home` view to a new shared
'BillingSession.get_billing_page_context' method.

This refactoring will help in minimizing duplicate code
while supporting both realm and remote_server customers.
2023-11-16 09:48:43 -08:00
Mateusz Mandera 1819b85b85 management: Allow changing is_billing_admin using change_user_role. 2023-11-15 18:36:07 -08:00
Anders Kaseorg f4e7a11c35 requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-11-15 15:27:54 -08:00
Anders Kaseorg 7a4ca3135d stripe: Prepare to switch to stripe inline annotations.
https://github.com/stripe/stripe-python/wiki/Inline-type-annotations

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-11-15 15:27:54 -08:00
Prakhar Pratyush f8a0035215 stripe: Move `make_end_of_cycle_updates_if_needed` to BillingSession.
Moves the 'make_end_of_cycle_updates_if_needed' function to
the 'BillingSession' abstract class.

This refactoring will help in minimizing duplicate code while
supporting both realm and remote_server customers.

Since the function is called from our main daily billing cron job
as well, we have changed 'RealmBillingSession' to accept 'user=None'
(our convention for automated system jobs).
2023-11-15 09:26:41 -08:00
Aman Agrawal 27ffcc6576 bililng: Fix incorrect price per license on billing page.
There is a discrepancy between price per license shown on billing
and upgrade page for annual billing frequency due to difference
in methods used to calculate the amount.

To fix it, we use the same method on both the pages.

I didn't use the helpers.format_money directly here since that would
create a visual delay in showing the price per license which will
not be nice considering that will be the only thing on this page
being updated that way.

The stripe fixture used is same as
free_trial_upgrade_by_card--Customer.retrieve.3.json
2023-11-15 15:59:26 +05:30
Prakhar Pratyush fb9e258a65 stripe: Add 'do_upgrade' method to the 'BillingSession' class.
This commit moves a major portion of the 'upgrade`
view to a new shared 'BillingSession.do_upgrade' method.

This refactoring will help in minimizing duplicate code
while supporting both realm and remote_server customers.
2023-11-14 12:07:26 -08:00
Aman Agrawal 67bddb3d72 billing: Show success message for license change after page reload. 2023-11-13 10:35:39 -08:00
Aman Agrawal 2997c269e1 billing: Show breakdown of renewal amount if not fixed_price. 2023-11-13 10:35:39 -08:00
Aman Agrawal 775a90771e stripe: Modify error message for less than min licenses. 2023-11-13 10:35:39 -08:00
Aman Agrawal 5f0969f52b session: Remove unnecessary has_request_variables wrapper. 2023-11-13 10:35:39 -08:00
Aman Agrawal 2570f7ce23 upgrade: Control automatic / manual license management via URL. 2023-11-13 10:35:39 -08:00
Aman Agrawal 395cafcf46 sponsorship: Add extra input fields to get more org info.
Fixes #27600
2023-11-13 08:52:13 -08:00
Prakhar Pratyush b5a6742adc stripe: Move `process_initial_upgrade` to BillingSession.
Moves the 'process_initial_upgrade' function to the
'BillingSession' abstract class.

This refactoring will help in minimizing duplicate code while
supporting both realm and remote_server customers.
2023-11-13 08:11:27 -08:00