Commit Graph

782 Commits

Author SHA1 Message Date
Anders Kaseorg
edeb17400b stripe: Add assertions to fix errors flagged by mypy 1.10.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 31c7b2bfd7)
2024-05-07 18:01:29 -07:00
Anders Kaseorg
60423d3a75 stripe: Add missing stripe_customer_id assertions.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit b195dc5a89)
2024-05-07 18:01:29 -07:00
Anders Kaseorg
b331d91344 stripe: Stringify invoice metadata.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 7b2a4304fc)
2024-05-07 18:01:29 -07:00
Anders Kaseorg
5e79eff437 stripe: Pass ids, not objects, to pagination API.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 385cd038b0)
2024-05-07 18:01:29 -07:00
Anders Kaseorg
c67f08b58a stripe: Use absent days_until_due rather than invalid None.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 228ade86be)
2024-05-07 18:01:29 -07:00
Anders Kaseorg
1327db6e9c stripe: Use more specific type annotations.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit e7a3d743d1)
2024-05-07 18:01:29 -07:00
Anders Kaseorg
95bdce69c1 ruff: Fix UP032 Use f-string instead of format call.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit a1a341f0ae)
2024-05-07 18:01:29 -07:00
Anders Kaseorg
1eee06e961 ruff: Fix E226 Missing whitespace around arithmetic operator.
This is a preview rule, not yet enabled by default.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 82a9fd927b)
2024-03-07 15:07:12 -08:00
Anders Kaseorg
9ea290d5ae python: Reformat with Ruff formatter.
https://docs.astral.sh/ruff/formatter/

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 570f3dd447)
2024-03-07 15:07:12 -08:00
Mateusz Mandera
7d0917c3c7 remote_billing: Tweak /self-hosted-billing/ endpoints access model.
It's best for these to just be consistent. Therefore:
1. The .../not-configured/ error page endpoint should be restricted to
   .has_billing_access users only.
2. For consistency, self_hosting_auth_view_common is tweaked to also do
   the .has_billing_access check as the first thing, to avoid revealing
   configuration information via its redirect/error-handling behavior.

The revealed configuration information seems super harmless, but it's
simpler to not have to worry about it and just be consistent.

(cherry picked from commit 7e8c645280)
2024-03-07 15:01:15 -08:00
Mateusz Mandera
b67e3d5ffa remote_billing: Make "plan management" always available.
Just shows a config error page if the bouncer is not enabled. Uses a new
endpoint for this so that it can work nicely for both browser and
desktop app clients.
It's necessary, because the desktop app expects to get a json response
with either an error or billing_access_url to redirect to. Showing a
nice config error page can't be done via the json error mechanism, so
instead we just serve a redirect to the new error page, which the app
will open in the browser in a new window or tab.

(cherry picked from commit f6d526f798)
2024-03-07 15:01:15 -08:00
Anders Kaseorg
2e4785f51c requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 93198a19ed)
2024-02-16 12:17:34 -08:00
Mateusz Mandera
ba50faced4 remote_billing: Fix /self-hosted-billing/ handling for desktop app.
When you click "Plan management", the desktop app opens
/self-hosted-billing/ in your browser immediately. So that works badly
if you're already logged into another account in the browser, since that
session will be used and it may be for a different user account than in
the desktop app, causing unintended behavior.

The solution is to replace the on click behavior for "Plan management"
in the desktop app case, to instead make a request to a new endpoint
/json/self-hosted-billing, which provides the billing access url in a
json response. The desktop app takes that URL and window.open()s it (in
the browser). And so a remote billing session for the intended user will
be obtained.
2024-01-15 21:32:00 -08:00
Anders Kaseorg
49d2727e6e test_remote_billing: Use unordered comparison for deactivation test.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-01-15 16:51:09 -08:00
Tim Abbott
81b42e3c41 zilencer: Fix community plan push notifications.
(cherry picked from commit 5dc1d36f73)
2024-01-15 16:51:09 -08:00
Anders Kaseorg
086df4a81e models: Extract zerver.models.realms.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-01-05 10:32:54 -05:00
Anders Kaseorg
ee85ac5433 models: Extract zerver.models.users.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-01-05 10:32:54 -05:00
Karl Stolley
e44ba3b1f1 portico: Add new self-hosted plans.
Co-authored-by: Alya Abbott <alya@zulip.com>
2023-12-15 11:03:42 -08:00
Sahil Batra
03323b0124 push_notifications: Enforce max user count on self managed plan.
We do not support sending push notifications for realms having
more than 10 users on self managed plan.
2023-12-15 11:03:42 -08:00
Tim Abbott
10862451ef billing: Refactor code to compute push status.
This moves the function which computes can_push and
expected_end_timestamp outside RemoteRealmBillingSession
because we might use this function for RemoteZulipServer
as well and also renames it.
2023-12-15 11:03:42 -08:00
Tim Abbott
9423ccecd4 docs: Document plan management login tips. 2023-12-15 11:03:42 -08:00
Tim Abbott
97799b279b billing: Enable billing system in production. 2023-12-15 11:03:42 -08:00
Aman Agrawal
0fe725fdbd test_stripe: Add tests to check sponsorship approval. 2023-12-15 09:08:48 -08:00
Prakhar Pratyush
1588f49b4f test_stripe: Add end-to-end test for RemoteRealm billing flow. 2023-12-15 09:08:48 -08:00
Prakhar Pratyush
33e04362e1 test_stripe: Add 'billing_session" to StripeTest.
This prep commit adds a 'billing_session' field to StripeTest class.

Creates 'client_billing_get', 'client_billing_post', and
'client_billing_patch' helper functions.

This will help in reusing code for RemoteRealm and
RemoteZulipServer end-to-end tests.
2023-12-15 09:08:48 -08:00
Aman Agrawal
53b7e956ea test_remote_billing: Extract remote server / realm login methods. 2023-12-15 09:08:48 -08:00
Prakhar Pratyush
c12a9eeb9c stripe: Fix 'get_billable_licenses_for_customer' not using event_time.
The call to 'get_billable_licenses_for_customer' during the
'sync_license_ledger_if_needed' step should use the audit_log's
event_time while calculating 'current_count_for_billed_licenses'.

Earlier, it used timezone_now(), resulting in the latest user count
recorded corresponding to each audit log.
2023-12-15 08:09:31 -08:00
Aman Agrawal
11dff6b4d8 zilencer: Add tests for migrating customer from server to realm. 2023-12-14 14:31:28 -08:00
Alya Abbott
ba80084ea7 remote_billing_page: Deny login for server / remote realm.
If server has plan, deny login for realm.
If realm has plan, deny login for server.

Co-authored-by: Aman Agrawal <amanagr@zulip.com>
Co-authored-by: Alya Abbott <alya@zulip.com>
2023-12-14 14:25:12 -08:00
Tim Abbott
1757b88760 billing: Offer release announcement subscriptions.
Also avoid prompting for full name time more than once.
Adds TOS version field to Remote server user.

Co-authored-by: Karl Stolley <karl@zulip.com>
Co-authored-by: Aman Agrawal <amanagr@zulip.com>
2023-12-14 10:51:16 -08:00
Aman Agrawal
e02e0cd37e models: Make it easier to debug current plan name and status.
`print(plan)` now works to know the plan tier and status.
2023-12-14 08:22:25 -08:00
Aman Agrawal
d795400b21 billing: Allow upgrade scheduled legacy orgs to view billing page.
Don't redirect them to sponsorship page.
2023-12-14 08:22:25 -08:00
Aman Agrawal
34a1be80a4 model: Use same name for legacy plan across the app. 2023-12-14 08:22:25 -08:00
Lauryn Menard
8bce83709f corporate: Add billing support email constant.
Adds BILLING_SUPPORT_EMAIL to `stripe.py` with a value of
"sales@zulip.com" so that it can be consistently used in
billing code.
2023-12-14 08:12:01 -08:00
Mateusz Mandera
651590c49a remote_billing: Store acting users in remote user audit logs. 2023-12-14 08:11:04 -08:00
Aman Agrawal
a5311c8032 stripe: End legacy plan before approving full sponsorship. 2023-12-13 22:29:30 -08:00
Tim Abbott
d040664952 billing: Set the legacy plan type when migrating. 2023-12-13 16:40:44 -08:00
Tim Abbott
6308e07e53 billing: Standardize remote server plan type IDs.
This will likely save us at least one headache.
2023-12-13 16:40:44 -08:00
Lauryn Menard
89545891f6 support: Filter remote realm data query for customer realm None. 2023-12-13 14:36:23 -08:00
Lauryn Menard
a897d68d93 support: Add active plan information to remote server activity.
Adds three columns to the remote server activity chart and updates
the chart key for the third of those columns.

The first is the plan name. If there are multiple plans with a
status under the live threshhold, then we send "See support view".

The second is the plan status. If there are multiple plans, then
we send "Multiple plans".

The third is the estimated annual revenue for the plan. Note that
for free trials, this will be calculated as if the plan was paid
for 12 months (so a full year).

If there is no plan for the server under the live threshold or at
all then "---" is inserted into the table row. Note that 100%
sponsored servers/realms would fall into this category.
2023-12-13 13:43:00 -08:00
Lauryn Menard
484c0df076 corporate: Move renewal_amount to BillingSession framework. 2023-12-13 13:43:00 -08:00
Lauryn Menard
e8500fbdb0 support: Include sponsorship request for remote server support view.
Preparation for updating the sponsorship forms template to include
information about the latest sponsorship request if sponsorship is
pending.
2023-12-13 10:28:11 -08:00
Aman Agrawal
9efb236c35 remote_billing_page: Fix redirects for self hosted login. 2023-12-13 08:13:33 -08:00
Aman Agrawal
081d94c4e8 stripe: Add user and org metadata to stripe payments. 2023-12-13 08:13:33 -08:00
Aman Agrawal
0c99420ceb stripe: Don't approve sponsorship for customers on paid plan.
This would avoid us accidentally approving sponsorship for customers
on paid plan.
2023-12-13 08:13:33 -08:00
Tim Abbott
95f4b31ce7 billing: Don't require data to add to legacy plan. 2023-12-13 00:44:50 -08:00
Tim Abbott
af83093a65 billing: Remove some stale TODOs. 2023-12-13 00:33:37 -08:00
Aman Agrawal
45a2f7eac1 portico: Pass requested sponsorship context to plan page. 2023-12-12 23:27:39 -08:00
Tim Abbott
f281199d2f billing_session: Push nocoverage comments down a layer. 2023-12-12 22:03:24 -08:00
Aman Agrawal
63f4fc51de server_deactivate: Show error message for server on active plan. 2023-12-12 21:00:42 -08:00