Commit Graph

396 Commits

Author SHA1 Message Date
Aman Agrawal bddb44eebf stripe: Disable free trial for legacy customer with ended plan.
This ensures that customer who had legacy plan any time in the past
cannot avail free trial.
2024-02-21 21:40:47 -08:00
Tim Abbott d0c276d863 corporate: Fix billing_session variable reuse confusion.
The previous logic incorrectly used the server-level number of users
even when a (presumably smaller) realm-level count was available.

Fixes a bug introduced in 2e1ed4431a.
2024-02-21 17:51:30 -08:00
Prakhar Pratyush 2f8e4a71d6 corporate: Send a reminder email 2 months before the end date.
For fixed-price plans, we send a reminder email to
sales@zulip.com, 2 months before the end date, to review
the pricing and configure a new fixed-price plan accordingly.
2024-02-21 10:43:23 -08:00
Prakhar Pratyush 06e48fd553 corporate: Add end_date to fixed-price plans.
Earlier, we were not configuring the end_date while creating
a fixed-price plan which would result in the automatic renewal
of the plan at the end of billing cycle.

Our plan is to re-evaluate the pricing when we are close to the
end date, then:
1. Schedule a new fixed-price plan with the updated or same price.
2. or Don't do anything - the plan will end on the end_date.

Now, we add an end_date of 1 year from the start date when
creating a fixed-price plan.
2024-02-21 10:43:23 -08:00
Prakhar Pratyush 648d0286bc stripe: Extract repetitive write_to_audit_log code into a function.
This is a prep commit which extracts the write_to_audit_log
code block in `update_end_date_of_current_plan` into a
function named 'write_to_audit_log_plan_property_changed'.

This would be helpful to avoid repetition as we plan to
include another such block when the plan's property
reminder_to_review_plan_email_sent is changed.
2024-02-21 10:43:23 -08:00
Prakhar Pratyush a20ce627d9 stripe: Add a check to create invoices only for paid plans.
In 'invoice_plan()', the primary way to not create
an invoice for a plan is to not have any new ledger entry.

This commit adds a 'self.on_paid_plan()' check which is
an extra layer of defense to avoid creating any invoices
for customers not on paid plan. It saves a DB query too.
2024-02-20 08:25:49 -08:00
Mateusz Mandera be03dabf76 zilencer: Implement do_reactivate_remote_server utility function.
The inverse of do_deactivate_remote_server. It's just flipping the
.deactivated flag, but we also should have an AuditLog for these events.
2024-02-19 20:26:47 -08:00
Tim Abbott 2e1ed4431a corporate: Fix plan precedence issues with expired plans.
RemoteRealm customer takes precedence over RemoteServer
in general. But if an inactive plan is associated with
RemoteRealm and an active plan with RemoteServer, the
ACTIVE plan takes precendence.

Co-authored-by: Prakhar Pratyush <prakhar@zulip.com>
2024-02-19 17:58:49 -08:00
Anders Kaseorg a4938d3760 page_params: Parse page_params and state_data with Zod.
This establishes a runtime check that their types continue to reflect
reality going forward.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-02-17 00:02:38 -08:00
Alya Abbott 4f1659fe8f billing: Make push notifications error message more clear. 2024-02-16 16:01:53 -08:00
Prakhar Pratyush d05a3f0cb0 corporate: Send invoice overdue mail also when data never uploaded.
Earlier, during invoicing we used to send a mail to
sales@zulip.com when the last_audit_log_update was
at least one day ago.

There was an assertion that last_audit_log_update
can't be None which is incorrect as such customers exist.

This commit extends the behaviour to send an invoice
overdue email even if the data was never uploaded.
2024-02-16 14:48:31 -08:00
Lauryn Menard 9c7d0c6e5a remote-support: Note if emails were sent for remote server sponsorship.
In cases where a support admin approves a sponsorship for a remote
server without any billing users having been created, note that no
emails were sent in the success message on the support page.

We already do this for remote realms and should be an infrequent
case as ideally most remote servers will submit official
sponsorship requests.
2024-02-16 14:46:59 -08:00
Prakhar Pratyush 9648256c3c corporate: Fix next_invoice_date not updated on end_date extension.
Earlier, on extending end_date for legacy plans, next_invoice_date
was not extended which resulted in invoice_plan() run for such
legacy plans before the end_date.

The intended behaviour is that the legacy plan should be invoiced
only once on the end_date to downgrade or switch to a new tier.

This commit adds logic to update next_invoice_date when end_date
is extended via /support.
2024-02-16 08:30:17 -08:00
Lauryn Menard b275e9c4d6 stripe: Add billing portal for customer name and address.
Adds a link on the upgrade and billing pages that opens a stripe
billing portal for the customer to update their name and address
that will appear on invoices and receipts.

On the billing page, updating the credit card information will
no longer update the customer billing address, since they can
now do this directly through the billing portal. To be consistent
with the credit card form on the upgrade page, we still require
inputting a billing address for the card.

Note that, once an invoice is paid/complete, then changes to the
customer's name and address will not be applied to those invoices.
2024-02-13 14:18:38 -08:00
Lauryn Menard 29e8a63a39 stripe: Add name to stripe customer with payment method.
Set the name on the stripe customer object to the name on the
credit card when one is initially attached to a customer.

Prep commit to adding a stripe billing portal so that billing
admins will be able to update both the name and address that
appears on their stripe generated invoices and receipts.
2024-02-13 14:18:38 -08:00
Aman Agrawal 8cba101e05 support: Add button to delete configured fixed next plan.
This will help us modify the configured plan if we need to.
2024-02-13 09:40:53 -08:00
Aman Agrawal 7b33d660eb billing: Rename self-managed to free. 2024-02-12 21:25:19 -08:00
Aman Agrawal 7ca85bed71 stripe: Fix $0 invoices being generated on upgrade.
Instead of charging the customer using the attached payment
method and then creating the invoice, we create an invoice and
force an immediate payment for the invoice via the attached
payment method.
2024-02-12 15:15:56 -08:00
Prakhar Pratyush a764f9ce25 corporate: Fix 'free_trial=True` for legacy customers during upgrade.
Earlier, we were not setting `free_trial` = False for legacy
customers in `do_upgrade`.

This lead to a bug where customers were upgraded even before the
payment was complete. 'process_initial_upgrade' was always getting
called instead of 'setup_upgrade_payment_intent_and_charge'.

This commit fixes the incorrect behaviour.
2024-02-12 09:06:06 -08:00
Prakhar Pratyush 2055dfa83e support: Add support to configure fixed-price plan with pay-by-invoice.
* Manually create & send invoice
* Configure a fixed-price plan with sent invoice-id.
* When customer pays, upgrade them to concerned plan.
2024-02-06 18:43:23 -08:00
Lauryn Menard cbb6d962d5 stripe: Add billing address collection to checkout session.
This will require customers to include an address when setting
up, or updating, the credit card information for their account.
The billing address for the card will also be saved as the
billing address for the stripe customer object.

The customer object billing address appears on the invoices
that are generated by stripe.
2024-02-05 10:16:04 -08:00
Aman Agrawal de33aa4b7b stripe: Add page to show list of past customer invoices. 2024-02-04 17:38:24 -08:00
Aman Agrawal 130aecbf9e stripe: Extract method to get org_name. 2024-02-01 09:29:08 -08:00
Prakhar Pratyush 82da6abb24 corporate: Restrict free-trial when fixed-price plan is configured.
When fixed-price plan is configured:
* Don't show 'free-trial for 30 days' button on plans page.
* Remove free-trial related texts from /upgrade page.
2024-01-31 12:25:31 -08:00
Prakhar Pratyush c4b6cfe142 support: Fix next plan info missing for customers with no current plan.
Earlier, when a fixed-price plan for a customer with
no current plan was configured via /support, the next plan
info was missing on support page.

It was because we were considering next plan only if the
customer had a current plan.

This commit fixes the incorrect behaviour.
2024-01-31 12:25:31 -08:00
Prakhar Pratyush 26536a20ed support: Always show the option to update end_date on /support page.
If a plan is already on "basic" or "business" plan and wants to
switch to a fixed-price "basic" / "business" plan, then it is
necessary that the current plan should have an end date configured.

Earlier, we could update the end_date only if the current plan
already had an end_date set.

This commit makes it possible to always show the option to
set or update end_date.
2024-01-30 10:09:52 -08:00
Prakhar Pratyush 928de1a74b stripe: Set fixed price plan status within if statement.
While configuring fixed price offer via /support, the
status for fixed price plan & offer are not the same.

Updates the code to not set it initially & then overwrite,
instead set it while creating the plan / offer.
2024-01-30 10:09:16 -08:00
Lauryn Menard 12ec133224 templates: Move billing templates to /templates/corporate/billing. 2024-01-30 10:06:48 -08:00
Tim Abbott ae52adb4ee lint: Fix errors caused by rebasing past black upgrade. 2024-01-29 11:31:04 -08:00
Prakhar Pratyush edec29e0b6 support: Add support to configure fixed_price plan. 2024-01-29 11:23:20 -08:00
Anders Kaseorg 93198a19ed requirements: Upgrade Python requirements.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2024-01-29 10:41:54 -08:00
Lauryn Menard dcae35196c remote-activity: Prefetch LicenseLedger entry for current plan.
To estimate the annual recurring revenue for remote server and
remote realm CustomerPlans, we prefetch the current license
ledger as part of the CustomerPlan query.

Also adds a select related to the remote realm audit log query
so that we don't go to the database for the remote realm ID.

With the test added in the previous commit, the query count for
the remote activity view goes from 27 to 11, as we are no longer
hitting the database multiple times for every current plan or
for every remote realm with audit log data.

Refactors get_customer_plan_renewal_amount so that a license
ledger is always passed and make_end_of_cycle_updates_if_needed
does not need to be called.
2024-01-25 15:35:44 -08:00
Prakhar Pratyush 3a6c98f6a9 stripe: Fix invoicing for new plans scheduled to upgrade.
Earlier, the next_invoicing_date and invoicing_status
for new plan weren't set correctly, resulting in the
scheduled switching of legacy plan to a new plan not
working as expected.

This commit fixes the incorrect behaviour.
2024-01-25 10:57:29 -08:00
Prakhar Pratyush 026eb37c28 stripe: Fix legacy plans not being invoiced.
Earlier, in 'migrate_customer_to_legacy_plan`, we set
'next_invoice_date' to None for legacy plans.
This will result in legacy plans not getting invoiced.
We need to invoice legacy plans on their end date to
either downgrade them or switch to a new plan.

We set next_invoice_date for legacy plans to end_date.
2024-01-25 10:57:29 -08:00
Tim Abbott cbb83b214f billing: Remove buggy i18n check. 2024-01-23 10:00:28 -08:00
Aman Agrawal 5a97a4d8dc stripe: End legacy plan on end_date. 2024-01-19 09:34:36 -08:00
Aman Agrawal 884c44d3cb stripe: Avoid redirects from `event_status` to `event_status/`. 2024-01-17 12:46:44 -08:00
Lauryn Menard 7e1d0adb6e support-tests: Add coverage for discount actions when upgrade scheduled. 2024-01-15 03:10:04 -08:00
Lauryn Menard a5f2883a75 remote-support: Add ability to set a required plan tier for customer. 2024-01-15 03:10:04 -08:00
Lauryn Menard fbe7145231 corporate: Check plan tier for new plan discount calculations.
Now that a customer discount may require a particular plan tier to
be applied, update the billing code to check the plan tier when
getting the customer default_discount field/information for a new
plan.

For billing schedule changes and displaying billing information for
current plans, we explicitly use the discount set on the current,
active plan and do not check the customer object for these actions.
2024-01-15 03:10:04 -08:00
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