Commit Graph

506 Commits

Author SHA1 Message Date
Lauryn Menard
f27b6d896a audit-logs: Add generic property changed for Customer and CustomerPlan.
Change audit logs for changing a Customer or CustomerPlan property
to use a generic event type and specify the property name in the
extra data.
2024-01-15 03:10:04 -08:00
Prakhar Pratyush
89f9e097db stripe: Add cron-based plan invoicing to remote server billing system. 2024-01-14 15:47:55 -08:00
Prakhar Pratyush
11908c4c2e stripe: Add cron-based plan invoicing to remote realm billing system. 2024-01-14 15:47:55 -08:00
Prakhar Pratyush
6088186223 stripe: Add flat discount while invoicing self-hosted realm/server.
This prep commit adds logic to calculate discount based
on flat_discount and flat_discounted_months. Creates
a stripe invoice item for the discount.

This will be used by remote realm/server billing system
while invoicing via cron job.
2024-01-14 15:47:55 -08:00
Aman Agrawal
f285de39e9 populate_realms: Allow billing page access without stripe_api_key. 2024-01-12 08:47:43 -08:00
Prakhar Pratyush
976354dbda stripe: Fix the invoice item description for flat discounts.
Earlier, in process_initial_upgrade, the flat_discount value
wasn't converted into dollars when specified in the invoice
description, resulting in showing the incorrect value of $2000
as a discount.

This commit converts the value in cents to dollars and adds tests
to verify the invoice generated.
2024-01-11 12:35:58 -08:00
Lauryn Menard
787d64e327 support: Update validation for adding or updating a discount.
Updates the HTML input field to have a min of 0, max of 99.99 and
allow increments of 0.01.

Also, use format_discount_percentage for displaying the customer
default discount in the support form.
2024-01-11 09:20:41 -08:00
Lauryn Menard
2994685399 support: Add admin support for updating end date of active plan.
This currently will only apply to tier.SELF_HOSTED_LEGACY plans.
2024-01-09 10:13:21 -08:00
Aman Agrawal
37c1b88917 stripe: Only enable free trial for basic plan. 2024-01-08 14:41:22 -08:00
Aman Agrawal
073f432a69 stripe: Set min license count based on flat discount.
For self hosted basic plan, we need to allow customers to subscribe
without purchasing 10 licenses and also we need to allow customer
take fully use the available discount so that if the add more
users in the future, the full discount was already applied.

To fix above, we set minimum user count to the least number
of licenses we require for the charge to be positive after applying
the complete discount.
2024-01-08 14:17:56 -08:00
Sahil Batra
63363ba50a push_notification: Check users count for plans to be downgraded.
We return expected_end_timestamp as "None" for the plans to be
downgraded if number of users is not more than MAX_USERS_WITHOUT_PLAN
since they will be downgraded to self-managed plan and would
have push notifications enabled.
2024-01-05 13:30:57 -08:00
Lauryn Menard
fb29a35262 support: Add updating minimum licenses requirement after discount.
Adds a support action for updating the minimum licenses on a
customer object once a default discount has also been set.

In the case that the current billing entity has a current active
plan or a scheduled upgrade to a new plan, then the minimum
licenses will not be updated.
2024-01-04 18:42:07 -08:00
Lauryn Menard
cc957e92f4 support: Raise errors for support requests that are not processed.
Previously, the message string was sent as a success response to
the context, which could have been confusing or ignored when shown
in the support admin view.
2024-01-04 18:42:07 -08:00
Tim Abbott
219df72d07 billing: Require no realm plans when approving server sponsorship. 2024-01-04 18:31:16 -08:00
Mateusz Mandera
367d552052 billing: Improve make_end_of_cycle_... interactions with audit logs.
- Make `self.write_to_audit_log` support a `background_update:
  bool=False` parameter that can be passed when code that might have an
  acting user happens to trigger a background update.
- Make `make_end_of_cycle_updates_if_needed` pass that parameter for its
  direct audit log writes.
- Audit code that `make_end_of_cycle_updates_if_needed` calls and make
  sure those write audit logs this way too.
- Pass the user in the `billing_page` code that had to avoid it as a
  workaround:
```
    # BUG: This should pass the acting_user; this is just working
    # around that make_end_of_cycle_updates_if_needed doesn't do audit
    # logging not using the session user properly.
    billing_session = RealmBillingSession(user=None, realm=user.realm)
```
2024-01-02 10:59:05 -08:00
Lauryn Menard
9f009a2e63 support: Reformat percentages in attach discount success message. 2023-12-30 11:22:30 -08:00
Aman Agrawal
e192aef23d billing: Apply a flat discount for self hosted plans. 2023-12-20 23:09:21 -08:00
Karl Stolley
a37354f92a corporate: Add a Basic plan. 2023-12-20 23:09:21 -08:00
Prakhar Pratyush
63bb63ad80 corporate: Remove '#nocoverage' comments.
This commit removes '#nocoverage' comment as we have added
few E2E tests in 'test_stripe.py'.
2023-12-19 10:59:38 -08:00
Aman Agrawal
b2faa5c5bb stripe: Add a CustomerPlan for self hosted sponsored customers. 2023-12-18 12:55:34 -08:00
Aman Agrawal
d4a852e97c stripe: Save a query to get CustomerPlan for sponsored customers. 2023-12-18 12:55:34 -08:00
Aman Agrawal
d962814a30 upgrade: Make it possible to upgrade to a provided tier.
Main work is maintaining context during various redirects and
and passing the context to the final upgrade process.
2023-12-18 12:23:46 -08:00
Aman Agrawal
1326619b77 stripe: Provide min license count to template as per tier. 2023-12-18 12:23:46 -08:00
Tim Abbott
5dc1d36f73 zilencer: Fix community plan push notifications. 2023-12-17 09:36:47 -08:00
Aman Agrawal
311a645c5a sponsorship_request: Minor changes.
* Show if requested org is hosted on Zulip Cloud.
* Change how user numbers are displayed.
2023-12-17 09:33:37 -08:00
Anders Kaseorg
cd96193768 models: Extract zerver.models.realms.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-12-16 22:08:44 -08:00
Anders Kaseorg
45bb8d2580 models: Extract zerver.models.users.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2023-12-16 22:08:44 -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
Prakhar Pratyush
1588f49b4f test_stripe: Add end-to-end test for RemoteRealm billing flow. 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
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
484c0df076 corporate: Move renewal_amount to BillingSession framework. 2023-12-13 13:43:00 -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
Lauryn Menard
aebafcc43f corporate: Show error page if mobile push data has not been uploaded.
Adds a template that displays an error message when the billing
or upgrade context for a remote server or remote realm raises a
MissingDataError.
2023-12-12 19:36:06 -08:00
Mateusz Mandera
e515574b3e remote_billing: Add endpoint and a helper to make deactivation links.
This is a general link for logging into the billing system on behalf of
a server, but it's tied to the .contact_email and takes the user
straight to the /deactivate/ page via the next_page mechanism.
2023-12-12 13:31:59 -08:00
Prakhar Pratyush
4ad03804cf stripe: Add sync_license_ledger... for RemoteServerBillingSession.
This commit implements the 'sync_license_ledger_if_needed' method
for RemoteServerBillingSession.
2023-12-12 12:15:32 -08:00
Prakhar Pratyush
1d515a57cd stripe: Make 'sync_license_ledger_if_needed' abstract method.
This prep commit makes 'sync_license_ledger_if_needed'
function a 'BillingSession' abstract method.

We'll override the method for RemoteServerBillingSession
in the next commit.
2023-12-12 12:15:32 -08:00
Prakhar Pratyush
88fb3b735a stripe: Add 'get_last_ledger_for_automanaged_plan_if_exists' method.
This prep commit extracts out the code block that determines the
last license ledger for the customer plan having automanage_licenses
set to True into a new BillingSession method named
'get_last_ledger_for_automanaged_plan_if_exists'.

We'll be using this function while implementing the
'sync_license_ledger_if_needed' method for RemoteServerBillingSession.
2023-12-12 12:15:31 -08:00