Commit Graph

502 Commits

Author SHA1 Message Date
Aman Agrawal
9d643ba31b stripe: Add test to verify charge for new users during free trial.
Added test to check if customer is charged for new users after
invoice payment at the end of free trial.
2025-07-22 17:13:37 -07:00
Aman Agrawal
c105bcc322 stripe: Fix free trial pay by invoice customer billed twice.
This was a result of us moving `billing_cycle_anchor` ahead in time
of the `LicenseLedger` entry the customer paid for. Thus, this
confused our logic in thinking that customer hasn't paid for
the current billing cycle.
2025-07-10 08:30:44 -07:00
Aman Agrawal
87694e9606 support: Add field to ask type of hosting request in demo form. 2025-06-04 16:29:03 -07:00
Lauryn Menard
2912d48579 corporate: Rename CustomerPlan.invoice_overdue_email_sent field.
Renames invoice_overdue_email_sent to stale_audit_log_data_email_sent
to better reflect the email and state that field is tracking for
the CustomerPlan.
2025-05-30 14:57:00 -07:00
Lauryn Menard
9edabf5ac8 corporate: Revise internal billing emails for stale audit log data.
These emails are not necessarily sent when an self-hosted customer
has an outstanding invoice, e.g., they are on an annual plan and
the monthly check for additional licenses happens when the audit
log data is stale.

Updates the notice_reason to be "stale_audit_log_data" instead of
"invoice_overdue". Revises the email subject and text to better
reflect what the support admin needs to investigate.
2025-05-30 14:57:00 -07:00
Aman Agrawal
906b96cdfc test_stripe: Fix weak URL testing.
The host of this URL could have been forged to redirect user
to a different subdomain and tests would still pass.

This also fixes the CodeQL warnings related to it.
2025-05-14 13:45:35 -07:00
Aman Agrawal
e04a32dee6 stripe: Upgrade API_VERSION to "2025-04-30.basil".
This involves the following major changes to the code:
* `Invoice.upcoming` removed in https://docs.stripe.com/changelog/basil/2025-03-31/invoice-preview-api-deprecations.

* InvoiceItem always needs to be created with an Invoice id for
  InvoiceItem to be attached to the Invoice.

  This seems to just be required after the upgrade and looking at
  stripe python SDK history, this was how it was always supposed to work.

  This is a welcome change since it adds to the clarity of the code.

* Change due to following breaking changes:

  - https://docs.stripe.com/changelog/basil/2025-03-31/invoice-pricing-configurations
  - https://docs.stripe.com/changelog/basil/2025-03-31/add-support-for-multiple-partial-payments-on-invoices

  which removes and adds various parameters and attributes to the
  invoice related objects.

  Also, out of band invoices now count in `amount_paid` in Invoice as
  part of above linked changes.

  See https://github.com/stripe/stripe-python/blob/master/CHANGELOG.md
  for an easier to search list of changes.

* Removed `proration` parameter from testing since we were not using it
  and testing its constant `false` value would require us writing more
  custom code to access its value.

* Added test for "usd" for the currency, since there were some changes
  in the API related local currency and I wanted to check Invoices
  were being created as expected.
2025-05-14 13:45:35 -07:00
Aman Agrawal
0a1f84fba1 stripe: Link InvoiceItem to Invoice.
This is required for upgrading to the basil version of stripe.
Changes haven't been tested in this commit. It is just for easy
verification of changes.
2025-05-14 13:45:35 -07:00
Aman Agrawal
c0504777b2 stripe: Link InvoiceItem to Invoice.
This is required for upgrading to the basil version of stripe.
Changes haven't been tested in this commit. It is just for easy
verification of changes.
2025-05-14 13:45:35 -07:00
Aman Agrawal
1a516f8b04 stripe: Link InvoiceItem to Invoice.
This is required for upgrading to the basil version of stripe.
Changes haven't been tested in this commit. It is just for easy
verification of changes.
2025-05-14 13:45:35 -07:00
Aman Agrawal
f8abfa2936 test_stripe: Add check for initially added card. 2025-05-14 13:45:35 -07:00
Aman Agrawal
625118bbb5 test_stripe: Add explanatory comment. 2025-05-14 13:45:35 -07:00
Aman Agrawal
567cf3c127 test_stripe: Fix incorrect pattern replacement in fixtures.
When normalizing fixture data, all numbers were being
replaced if they matched `exp_month`. This can lead to various
errors and flaky fixture generation. We use a pattern match
which includes the parameter being matched to fix this.
2025-05-14 13:45:35 -07:00
Aman Agrawal
104a7dd7a0 test_stripe: Don't return None on mocked return of stripe functions.
When mocking stripe function, don't return `None` as it can be
treated as the call was unsuccessful by the code being tested.
2025-05-14 13:45:35 -07:00
Aman Agrawal
9bcdaee065 test_stripe: Add clarification comment.
Wasted some time on this today, so decided to leave a comment here.
2025-05-14 13:45:35 -07:00
Lauryn Menard
4d1bfe6537 demo-orgs: Disable corporate upgrade and sponsorship pages.
Use a shared error template for demo organizations when rendering
the upgrade or sponsorship pages.

Demo organizations must be converted into a permanent organization,
i.e., not be automatically scheduled for deletion, to either apply
for a sponsorship/discount or upgrade to a paid plan.
2025-04-23 09:23:24 -07:00
Ethan Mayer
c12b94aea4 models: Refactor corporate/models.py into models package.
Fixes #34318.

Seperated models file into a package with component files.
2025-04-08 10:16:35 -07:00
Lauryn Menard
ec89e5afd2 billing: Improve error handling when invoicing plans as needed.
When we're unable to process an invoice for a customer due to a billing
or assertion error, we log the error and add the customer ID to a set
of failed customer IDs. This allows us to continuing invoicing other
customers, and at the same time not invoice any other pending plans
attached to a customer we failed to invoice.
2025-03-27 12:51:52 -07:00
Anders Kaseorg
67fb7daa63 ruff: Fix RUF051 Use pop instead of key in dictdel dict[key].
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-03-14 17:31:50 -07:00
Vector73
c049259d07 user: Remove is_billing_admin user property.
Removed `is_billing_admin` user property as it is no longer used since
billing permissions are now determined by `can_manage_billing_group`
realm setting.
2025-03-10 09:36:30 -07:00
Vector73
158fd58cde settings: Add "can_manage_billing_group" realm setting.
Added "can_manage_billing_group" realm group permission setting
to control who can manage billing and plans in the organization.

Fixes #32745.
2025-03-10 09:36:30 -07:00
Lauryn Menard
c4e3ccafa2 stripe: Delete fixed price plan offer if customer on comp access plan.
Updates delete_fixed_price_plan to use the same structure as
configure_fixed_price_plan. If there is a customer plan and it's
billable, then we delete the configured CustomerPlan object. If
there is no customer plan or it's a complimentary access plan, we
delete the configured CustomerPlanOffer object.
2025-02-28 17:42:04 -08:00
Lauryn Menard
add58e3795 billing: Use customer.minimum_licenses for minimum plan check.
Allow for manually setting a minimum_licenses value on a customer
to return that for min_licenses_for_plan in cases where we wanted
to override the general plan minimum for a particular case.
2025-02-20 14:17:25 -08:00
Anders Kaseorg
4e04eed745 typos: Fix typos caught by typos and mwic.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-02-18 19:44:02 -08:00
Mateusz Mandera
0caf815e36 do_activate_mirror_dummy_user: Assert user_profile is a mirror dummy.
If this is called on a user without is_mirror_dummy=True, that seems
certain to be a bug. Therefore, an assert is preferable in order to
catch this, rather than returning early with noop like some other
function such as do_deactivate_user.
2025-01-28 09:38:56 -08:00
Aman Agrawal
b549562a4d sponsorship: Ask user how they plan to use Zulip.
This will help avoid some back-and-forth on sponsorship requests.
2025-01-22 09:22:52 -08:00
Aman Agrawal
6e1bb56519 stripe: Check for min_licenses when switching plan tier.
When we are upgrading a customer to a different plan tier, we should
check if switching plans would lead to different licenses due to
different minimum license requirement between plans.
2025-01-21 15:53:53 -08:00
Lauryn Menard
1297541059 stripe-tests: Update uses of "legacy" to "complimentary access". 2025-01-21 15:40:27 -08:00
Lauryn Menard
261333c37f corporate: Clean up code remaining comments with "legacy plan".
Replaces documentation in billing code and tests to use
"complimentary access plan" instead of "legacy plan".
2025-01-21 15:40:27 -08:00
Lauryn Menard
d3bc9bec1d billing: Rename migrate_customer_to_legacy_plan.
Renames migrate_customer_to_legacy_plan to
create_complimentary_access_plan for how this
function is currently used.

Prep for adding a complimentary access plan
for Zulip Cloud.
2025-01-21 15:40:27 -08:00
Aman Agrawal
b870faec5a stripe: Require 10 minimum licenses for cloud plus plan. 2025-01-16 11:32:03 -08:00
Lauryn Menard
e963d5eaa9 billing: Fix deleting next fixed-price plan via support.
If the customer has a current fixed-price plan and a support admin
configures a fixed-price plan for the upcoming billing year, then
a CustomerPlan object is created and not a CustomerPlanOffer.

Fix the support action for deleting a configured fixed-price next
plan.

Updates the success strings for these actions to be specify if the
deleted object was a plan offer or a scheduled plan.
2025-01-15 11:23:24 -08:00
Anders Kaseorg
653b0b0436 ruff: Partially reformat Python with Ruff 0.9 (2025 style).
These are the changes that are backwards compatible with the 2024
style.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2025-01-14 09:42:16 -08:00
Lauryn Menard
36210c1ff3 billing: Replace legacy plan languagae with complimentary access.
Replaces the billing context variable for billing entities on a
temporary courtesy plan to use 'complimentary access' instead of
'legacy'.
2024-12-12 11:04:23 -08:00
Lauryn Menard
a0bbc62f2b support: Add fixed-price plan configuration to Cloud support view.
Adds ability to configure a fixed-price plan and to delete a
configured fixed-price plan in the Cloud support view.

Updates the invoice processing to send reminder emails to the
billing support email for these Cloud fixed-price plans about
renewals since we now are able to configure them via our support
panel.

Updates function to get the billing session for stripe webhook
events to handle an intial upgrade for a custom generated invoice
for a fixed-price plan for a Cloud organization, which won't have
a user_id in the invoice metadata.
2024-11-26 12:42:39 -08:00
Lauryn Menard
746268e878 test-stripe: Confirm update of plan type for fixed-price plan upgrade. 2024-11-26 12:42:39 -08:00
Lauryn Menard
cd55488487 billing: Link customer stripe ID for manual fixed-price plan invoices.
For cases where a customer is created in Stripe first for the manual
invoice, we want to connect that customer information to our Customer
object in the database. That way the customer can access the billing
page once the invoice is paid.
2024-11-21 10:34:33 -08:00
Anders Kaseorg
3ec58fd3d5 requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-10-20 18:16:27 -07:00
Anders Kaseorg
10271fb850 ruff: Fix SIM910 Use .get(key) instead of .get(key, None).
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-10-20 18:16:27 -07:00
Aman Agrawal
790d5c44a1 stripe: Allow customer to switch license management type.
Fixes #28633

Added a button to switch license management type on billing page.

Tested that the plan switch works correctly.

Tested that when switching from manual to automatic license
management, customer is only billed for billable users for the
next billing cycle.
2024-09-26 16:13:28 -07:00
Anders Kaseorg
f0f048de69 corporate: Import corporate.lib.stripe lazily.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-09-24 18:18:26 -07:00
Lauryn Menard
b02cf53d5e billing: Validate license management at end of billing cycle.
For plans where we're enforcing correct manual license management,
before we create the renewal entry for the licenses ledger at the
end of a billing cycle, we should check that the current count of
billed licenses is not higher than what the renewal license count
would be.

Co-authored-by: Aman Agrawal <amanagr@zulip.com>
2024-09-20 12:02:39 -07:00
Aman Agrawal
9a1ad1047a test_stripe: Normalize stripe fixtures.
Normalize generated fixtures for exp_month, exp_year and postal code.
2024-09-19 11:26:21 -07:00
Aman Agrawal
4d8e6ba094 stripe: Change stripe email on the upgrade page if available. 2024-09-19 11:26:21 -07:00
Lauryn Menard
2e394f3913 billing: Check minimum for plan tier for stale license count check. 2024-09-18 09:40:42 -07:00
Lauryn Menard
0147578de6 corporate: Make initial upgrade license checks more robust.
In cases where the seat count for automated license management is
stale when the upgrade process is initiated and the user has chosen
automated license management, we should get the current billable
license count when doing the initial payment/charge.

Also, makes the post-payment check for inconsistencies more robust
in that we check for both under and over billing cases. In the case
where the customer may have been overbilled, an email is sent to
the billing support team so that manual investigation can happen.
2024-09-11 11:16:55 -07:00
Lauryn Menard
aad93e149e audit-log: Move remote server event types to AuditLogEventType enum.
Event types moved: REMOTE_SERVER_DEACTIVATED, REMOTE_SERVER_REACTIVATED
REMOTE_SERVER_PLAN_TYPE_CHANGED, REMOTE_SERVER_DISCOUNT_CHANGED
REMOTE_SERVER_SPONSORSHIP_APPROVED, REMOTE_SERVER_BILLING_MODALITY_CHANGED
REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED, REMOTE_SERVER_CREATED
2024-09-09 11:50:13 -07:00
Lauryn Menard
f7e07e91a2 audit-log: Move customer event types to AuditLogEventType enum.
Event types moved: CUSTOMER_CREATED, CUSTOMER_PLAN_CREATED
CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN,
CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN,
CUSTOMER_PROPERTY_CHANGED, CUSTOMER_PLAN_PROPERTY_CHANGED
2024-09-09 11:50:13 -07:00
Lauryn Menard
bf4a650999 audit-log: Move stripe event types to AuditLogEventType enum.
Event types moved: STRIPE_CUSTOMER_CREATED, STRIPE_CARD_CHANGED
STRIPE_PLAN_CHANGED, STRIPE_PLAN_QUANTITY_RESET
2024-09-09 11:50:13 -07:00
Lauryn Menard
d2c32f23db audit-log: Move realm event types to AuditLogEventType enum.
Event types moved: REALM_DEACTIVATED, REALM_REACTIVATED, REALM_SCRUBBED
REALM_PLAN_TYPE_CHANGED, REALM_LOGO_CHANGED, REALM_EXPORTED
REALM_PROPERTY_CHANGED, REALM_ICON_SOURCE_CHANGED, REALM_DISCOUNT_CHANGED
REALM_SPONSORSHIP_APPROVED, REALM_BILLING_MODALITY_CHANGED
REALM_REACTIVATION_EMAIL_SENT, REALM_SPONSORSHIP_PENDING_STATUS_CHANGED
REALM_SUBDOMAIN_CHANGED
2024-09-09 11:50:13 -07:00