Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stripe: Fix invoicing for new plans scheduled to upgrade.

Prakhar Pratyush3a6c98f6a915
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index cc3852a7d86..f5fd997e280 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1337,6 +1337,7 @@ class BillingSession(ABC):
free_trial,
billing_cycle_anchor,
is_self_hosted_billing,
+ should_schedule_upgrade_for_legacy_remote_server,
)
# TODO: The correctness of this relies on user creation, deactivation, etc being
@@ -1397,6 +1398,9 @@ class BillingSession(ABC):
# to worry about this plan being used for any other purpose.
# NOTE: This is the 2nd plan for the customer.
plan_params["status"] = CustomerPlan.NEVER_STARTED
+ plan_params[
+ "invoicing_status"
+ ] = CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT
event_time = timezone_now().replace(microsecond=0)
# Schedule switching to the new plan at plan end date.
@@ -4309,6 +4313,7 @@ def compute_plan_parameters(
free_trial: bool = False,
billing_cycle_anchor: Optional[datetime] = None,
is_self_hosted_billing: bool = False,
+ should_schedule_upgrade_for_legacy_remote_server: bool = False,
) -> Tuple[datetime, datetime, datetime, int]:
# Everything in Stripe is stored as timestamps with 1 second resolution,
# so standardize on 1 second resolution.
@@ -4333,6 +4338,8 @@ def compute_plan_parameters(
days=assert_is_not_none(get_free_trial_days(is_self_hosted_billing, tier))
)
next_invoice_date = period_end
+ if should_schedule_upgrade_for_legacy_remote_server:
+ next_invoice_date = billing_cycle_anchor
return billing_cycle_anchor, next_invoice_date, period_end, price_per_license
@@ -4438,7 +4445,9 @@ def get_plan_renewal_or_end_date(plan: CustomerPlan, event_time: datetime) -> da
def invoice_plans_as_needed(event_time: Optional[datetime] = None) -> None:
if event_time is None:
event_time = timezone_now()
- for plan in CustomerPlan.objects.filter(next_invoice_date__lte=event_time):
+ # For self hosted legacy plan with status SWITCH_PLAN_TIER_AT_PLAN_END, we need
+ # to invoice legacy plan followed by new plan on the same day, hence ordered by ID.
+ for plan in CustomerPlan.objects.filter(next_invoice_date__lte=event_time).order_by("id"):
remote_server: Optional[RemoteZulipServer] = None
if plan.customer.realm is not None:
billing_session: BillingSession = RealmBillingSession(realm=plan.customer.realm)
diff --git a/corporate/migrations/0036_fix_customer_plans_scheduled_after_legacy_plan.py b/corporate/migrations/0036_fix_customer_plans_scheduled_after_legacy_plan.py
new file mode 100644
index 00000000000..581e519b281
--- /dev/null
+++ b/corporate/migrations/0036_fix_customer_plans_scheduled_after_legacy_plan.py
@@ -0,0 +1,40 @@
+# Generated by Django 4.2.8 on 2024-01-24 08:08
+
+from django.db import migrations
+from django.db.backends.base.schema import BaseDatabaseSchemaEditor
+from django.db.migrations.state import StateApps
+
+
+def fix_customer_plans_scheduled_after_legacy_plan(
+ apps: StateApps, schema_editor: BaseDatabaseSchemaEditor
+) -> None:
+ CustomerPlan = apps.get_model("corporate", "CustomerPlan")
+ CustomerPlan.TIER_SELF_HOSTED_LEGACY = 101
+ CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END = 8
+ CustomerPlan.NEVER_STARTED = 12
+ CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT = 3
+
+ # Legacy plans scheduled to switch to a new plan.
+ legacy_plans = CustomerPlan.objects.filter(
+ tier=CustomerPlan.TIER_SELF_HOSTED_LEGACY, status=CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END
+ )
+
+ for legacy_plan in legacy_plans:
+ CustomerPlan.objects.filter(
+ customer=legacy_plan.customer,
+ billing_cycle_anchor=legacy_plan.end_date,
+ status=CustomerPlan.NEVER_STARTED,
+ ).update(
+ next_invoice_date=legacy_plan.end_date,
+ invoicing_status=CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT,
+ )
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("corporate", "0035_update_legacy_plan_next_invoice_date"),
+ ]
+
+ operations = [
+ migrations.RunPython(fix_customer_plans_scheduled_after_legacy_plan),
+ ]
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.create.1.json
new file mode 100644
index 00000000000..d3ab7466e10
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.create.1.json
@@ -0,0 +1,33 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1705936954,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip.testserver 15439a7d-691",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_PQFq9E4uE975fx",
+ "invoice_prefix": "A8DC88AC",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": null,
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_realm_host": "zulip.testserver",
+ "remote_realm_uuid": "15439a7d-6911-4d6e-a26a-154a525214ab"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.modify.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.modify.1.json
new file mode 100644
index 00000000000..2eba77b7854
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.modify.1.json
@@ -0,0 +1,33 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1705936954,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip.testserver 15439a7d-691",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_PQFq9E4uE975fx",
+ "invoice_prefix": "A8DC88AC",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": "pm_1ObPKaDEQaroqDjsfNthLIRI",
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_realm_host": "zulip.testserver",
+ "remote_realm_uuid": "15439a7d-6911-4d6e-a26a-154a525214ab"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.1.json
new file mode 100644
index 00000000000..4700d35b53e
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.1.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1705936954,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip.testserver 15439a7d-691",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_PQFq9E4uE975fx",
+ "invoice_prefix": "A8DC88AC",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "9XKsMixKBi6kIIzd",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1705936956,
+ "customer": "cus_PQFq9E4uE975fx",
+ "id": "pm_1ObPKaDEQaroqDjsfNthLIRI",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_realm_host": "zulip.testserver",
+ "remote_realm_uuid": "15439a7d-6911-4d6e-a26a-154a525214ab"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.2.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.2.json
new file mode 100644
index 00000000000..4700d35b53e
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.2.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1705936954,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip.testserver 15439a7d-691",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_PQFq9E4uE975fx",
+ "invoice_prefix": "A8DC88AC",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "9XKsMixKBi6kIIzd",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1705936956,
+ "customer": "cus_PQFq9E4uE975fx",
+ "id": "pm_1ObPKaDEQaroqDjsfNthLIRI",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_realm_host": "zulip.testserver",
+ "remote_realm_uuid": "15439a7d-6911-4d6e-a26a-154a525214ab"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.3.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.3.json
new file mode 100644
index 00000000000..4700d35b53e
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.3.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1705936954,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip.testserver 15439a7d-691",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_PQFq9E4uE975fx",
+ "invoice_prefix": "A8DC88AC",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "9XKsMixKBi6kIIzd",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1705936956,
+ "customer": "cus_PQFq9E4uE975fx",
+ "id": "pm_1ObPKaDEQaroqDjsfNthLIRI",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_realm_host": "zulip.testserver",
+ "remote_realm_uuid": "15439a7d-6911-4d6e-a26a-154a525214ab"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.4.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.4.json
new file mode 100644
index 00000000000..4700d35b53e
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Customer.retrieve.4.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1705936954,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip.testserver 15439a7d-691",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_PQFq9E4uE975fx",
+ "invoice_prefix": "A8DC88AC",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "9XKsMixKBi6kIIzd",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1705936956,
+ "customer": "cus_PQFq9E4uE975fx",
+ "id": "pm_1ObPKaDEQaroqDjsfNthLIRI",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_realm_host": "zulip.testserver",
+ "remote_realm_uuid": "15439a7d-6911-4d6e-a26a-154a525214ab"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.create.1.json
new file mode 100644
index 00000000000..1d1c0da36bf
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.create.1.json
@@ -0,0 +1,212 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 176000,
+ "amount_paid": 0,
+ "amount_remaining": 176000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1705936965,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_PQFq9E4uE975fx",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": null,
+ "ending_balance": null,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": null,
+ "id": "in_1ObPKjDEQaroqDjsYKBE5vLt",
+ "invoice_pdf": null,
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": -24000,
+ "amount_excluding_tax": -24000,
+ "currency": "usd",
+ "description": "$20.00/month new customer discount",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_1ObPKjDEQaroqDjsuKxGXobH",
+ "invoice_item": "ii_1ObPKjDEQaroqDjs3x3epO24",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1705936965,
+ "start": 1705936965
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705038418,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1OXda2DEQaroqDjsJIdzQXRS",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PLhPbuhP0lDy6A",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "-24000"
+ },
+ {
+ "amount": 200000,
+ "amount_excluding_tax": 200000,
+ "currency": "usd",
+ "description": "Zulip Business - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_1ObPKjDEQaroqDjs2AULFuhP",
+ "invoice_item": "ii_1ObPKiDEQaroqDjsamUEIkvg",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705931933,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1ObO1ZDEQaroqDjsgkIuEZa0",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PQEU5cW8VfaPha",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 25,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_1ObPKjDEQaroqDjsYKBE5vLt/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1705940565,
+ "number": null,
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": null,
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1705936965,
+ "period_start": 1705936965,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "auto"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Business",
+ "status": "draft",
+ "status_transitions": {
+ "finalized_at": null,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 176000,
+ "subtotal_excluding_tax": 176000,
+ "tax": null,
+ "test_clock": null,
+ "total": 176000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 176000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.finalize_invoice.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.finalize_invoice.1.json
new file mode 100644
index 00000000000..e4d1a16019b
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.finalize_invoice.1.json
@@ -0,0 +1,212 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 176000,
+ "amount_paid": 0,
+ "amount_remaining": 176000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1705936965,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_PQFq9E4uE975fx",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1705936966,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_17vTkwDEQaroqDjs/test_YWNjdF8xN3ZUa3dERVFhcm9xRGpzLF9QUUZxSklHSkNvR3oxU1UzYWpTTFNINE5wbUtoWFZLLDk2NDc3NzY30200cNWtwxh3?s=ap",
+ "id": "in_1ObPKjDEQaroqDjsYKBE5vLt",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_17vTkwDEQaroqDjs/test_YWNjdF8xN3ZUa3dERVFhcm9xRGpzLF9QUUZxSklHSkNvR3oxU1UzYWpTTFNINE5wbUtoWFZLLDk2NDc3NzY30200cNWtwxh3/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": -24000,
+ "amount_excluding_tax": -24000,
+ "currency": "usd",
+ "description": "$20.00/month new customer discount",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_1ObPKjDEQaroqDjsuKxGXobH",
+ "invoice_item": "ii_1ObPKjDEQaroqDjs3x3epO24",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1705936965,
+ "start": 1705936965
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705038418,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1OXda2DEQaroqDjsJIdzQXRS",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PLhPbuhP0lDy6A",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "-24000"
+ },
+ {
+ "amount": 200000,
+ "amount_excluding_tax": 200000,
+ "currency": "usd",
+ "description": "Zulip Business - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_1ObPKjDEQaroqDjs2AULFuhP",
+ "invoice_item": "ii_1ObPKiDEQaroqDjsamUEIkvg",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705931933,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1ObO1ZDEQaroqDjsgkIuEZa0",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PQEU5cW8VfaPha",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 25,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_1ObPKjDEQaroqDjsYKBE5vLt/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1705940565,
+ "number": "A8DC88AC-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_3ObPKkDEQaroqDjs0a57znwB",
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1705936965,
+ "period_start": 1705936965,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "letter"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Business",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1705936966,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 176000,
+ "subtotal_excluding_tax": 176000,
+ "tax": null,
+ "test_clock": null,
+ "total": 176000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 176000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1705936966
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.list.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.list.1.json
new file mode 100644
index 00000000000..e39960ab725
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.list.1.json
@@ -0,0 +1,6 @@
+{
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.list.2.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.list.2.json
new file mode 100644
index 00000000000..b744b45077a
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--Invoice.list.2.json
@@ -0,0 +1,219 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 176000,
+ "amount_paid": 0,
+ "amount_remaining": 176000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1705936965,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_PQFq9E4uE975fx",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1705936966,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_17vTkwDEQaroqDjs/test_YWNjdF8xN3ZUa3dERVFhcm9xRGpzLF9QUUZxSklHSkNvR3oxU1UzYWpTTFNINE5wbUtoWFZLLDk2NDc3NzY40200rci3hfcF?s=ap",
+ "id": "in_1ObPKjDEQaroqDjsYKBE5vLt",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_17vTkwDEQaroqDjs/test_YWNjdF8xN3ZUa3dERVFhcm9xRGpzLF9QUUZxSklHSkNvR3oxU1UzYWpTTFNINE5wbUtoWFZLLDk2NDc3NzY40200rci3hfcF/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": -24000,
+ "amount_excluding_tax": -24000,
+ "currency": "usd",
+ "description": "$20.00/month new customer discount",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_1ObPKjDEQaroqDjsuKxGXobH",
+ "invoice_item": "ii_1ObPKjDEQaroqDjs3x3epO24",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1705936965,
+ "start": 1705936965
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705038418,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1OXda2DEQaroqDjsJIdzQXRS",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PLhPbuhP0lDy6A",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "-24000"
+ },
+ {
+ "amount": 200000,
+ "amount_excluding_tax": 200000,
+ "currency": "usd",
+ "description": "Zulip Business - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_1ObPKjDEQaroqDjs2AULFuhP",
+ "invoice_item": "ii_1ObPKiDEQaroqDjsamUEIkvg",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705931933,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1ObO1ZDEQaroqDjsgkIuEZa0",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PQEU5cW8VfaPha",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 25,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_1ObPKjDEQaroqDjsYKBE5vLt/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1705940565,
+ "number": "A8DC88AC-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_3ObPKkDEQaroqDjs0a57znwB",
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1705936965,
+ "period_start": 1705936965,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "letter"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Business",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1705936966,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 176000,
+ "subtotal_excluding_tax": 176000,
+ "tax": null,
+ "test_clock": null,
+ "total": 176000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 176000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1705936966
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--InvoiceItem.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--InvoiceItem.create.1.json
new file mode 100644
index 00000000000..b6f37a0d6bd
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--InvoiceItem.create.1.json
@@ -0,0 +1,47 @@
+{
+ "amount": 200000,
+ "currency": "usd",
+ "customer": "cus_PQFq9E4uE975fx",
+ "date": 1705936964,
+ "description": "Zulip Business - renewal",
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_1ObPKiDEQaroqDjsamUEIkvg",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705931933,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1ObO1ZDEQaroqDjsgkIuEZa0",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PQEU5cW8VfaPha",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "quantity": 25,
+ "subscription": null,
+ "tax_rates": [],
+ "test_clock": null,
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--InvoiceItem.create.2.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--InvoiceItem.create.2.json
new file mode 100644
index 00000000000..7b0be491cd0
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--InvoiceItem.create.2.json
@@ -0,0 +1,47 @@
+{
+ "amount": -24000,
+ "currency": "usd",
+ "customer": "cus_PQFq9E4uE975fx",
+ "date": 1705936965,
+ "description": "$20.00/month new customer discount",
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_1ObPKjDEQaroqDjs3x3epO24",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1705936965,
+ "start": 1705936965
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1705038418,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_1OXda2DEQaroqDjsJIdzQXRS",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_PLhPbuhP0lDy6A",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "quantity": 1,
+ "subscription": null,
+ "tax_rates": [],
+ "test_clock": null,
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.create.1.json
new file mode 100644
index 00000000000..77b2d9ba285
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.create.1.json
@@ -0,0 +1,34 @@
+{
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "seti_1ObPKbDEQaroqDjswS8iYKUZ_secret_PQFqUvgHe6EuPuoMRsMv474sl28mLGG",
+ "created": 1705936957,
+ "customer": "cus_PQFq9E4uE975fx",
+ "description": null,
+ "flow_directions": null,
+ "id": "seti_1ObPKbDEQaroqDjswS8iYKUZ",
+ "last_setup_error": null,
+ "latest_attempt": "setatt_1ObPKbDEQaroqDjs83zpB3Qp",
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": "pm_1ObPKaDEQaroqDjsfNthLIRI",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "succeeded",
+ "usage": "off_session"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.list.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.list.1.json
new file mode 100644
index 00000000000..2a3882a55c0
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.list.1.json
@@ -0,0 +1,41 @@
+{
+ "data": [
+ {
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "seti_1ObPKZDEQaroqDjs8b3IjTPr_secret_PQFqRpZo7GtZivYNZihxO8aVQm8CEcK",
+ "created": 1705936955,
+ "customer": "cus_PQFq9E4uE975fx",
+ "description": null,
+ "flow_directions": null,
+ "id": "seti_1ObPKZDEQaroqDjs8b3IjTPr",
+ "last_setup_error": null,
+ "latest_attempt": null,
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": null,
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "requires_payment_method",
+ "usage": "off_session"
+ }
+ ],
+ "has_more": true,
+ "object": "list",
+ "url": "/v1/setup_intents"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.retrieve.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.retrieve.1.json
new file mode 100644
index 00000000000..77b2d9ba285
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--SetupIntent.retrieve.1.json
@@ -0,0 +1,34 @@
+{
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "seti_1ObPKbDEQaroqDjswS8iYKUZ_secret_PQFqUvgHe6EuPuoMRsMv474sl28mLGG",
+ "created": 1705936957,
+ "customer": "cus_PQFq9E4uE975fx",
+ "description": null,
+ "flow_directions": null,
+ "id": "seti_1ObPKbDEQaroqDjswS8iYKUZ",
+ "last_setup_error": null,
+ "latest_attempt": "setatt_1ObPKbDEQaroqDjs83zpB3Qp",
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": "pm_1ObPKaDEQaroqDjsfNthLIRI",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "succeeded",
+ "usage": "off_session"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--checkout.Session.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--checkout.Session.create.1.json
new file mode 100644
index 00000000000..5bb73a2034e
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--checkout.Session.create.1.json
@@ -0,0 +1,74 @@
+{
+ "after_expiration": null,
+ "allow_promotion_codes": null,
+ "amount_subtotal": null,
+ "amount_total": null,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_address_collection": null,
+ "cancel_url": "http://selfhosting.testserver/realm/15439a7d-6911-4d6e-a26a-154a525214ab/upgrade/?manual_license_management=false&tier=1",
+ "client_reference_id": null,
+ "client_secret": null,
+ "consent": null,
+ "consent_collection": null,
+ "created": 1705936955,
+ "currency": null,
+ "currency_conversion": null,
+ "custom_fields": [],
+ "custom_text": {
+ "after_submit": null,
+ "shipping_address": null,
+ "submit": null,
+ "terms_of_service_acceptance": null
+ },
+ "customer": "cus_PQFq9E4uE975fx",
+ "customer_creation": null,
+ "customer_details": {
+ "address": null,
+ "email": "[email protected]",
+ "name": null,
+ "phone": null,
+ "tax_exempt": null,
+ "tax_ids": null
+ },
+ "customer_email": null,
+ "expires_at": 1706023355,
+ "id": "cs_test_c1qZ1SB9ON9X4HjwvECPXKXwJXjgxYns80vP99CiWvk6GZIatHDSUOzqC8",
+ "invoice": null,
+ "invoice_creation": null,
+ "livemode": false,
+ "locale": null,
+ "metadata": {
+ "remote_realm_user_id": "1",
+ "type": "card_update"
+ },
+ "mode": "setup",
+ "object": "checkout.session",
+ "payment_intent": null,
+ "payment_link": null,
+ "payment_method_collection": "always",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {},
+ "payment_method_types": [
+ "card"
+ ],
+ "payment_status": "no_payment_required",
+ "phone_number_collection": {
+ "enabled": false
+ },
+ "recovered_from": null,
+ "setup_intent": "seti_1ObPKZDEQaroqDjs8b3IjTPr",
+ "shipping": null,
+ "shipping_address_collection": null,
+ "shipping_options": [],
+ "shipping_rate": null,
+ "status": "open",
+ "submit_type": null,
+ "subscription": null,
+ "success_url": "http://selfhosting.testserver/realm/15439a7d-6911-4d6e-a26a-154a525214ab/billing/event_status/?stripe_session_id={CHECKOUT_SESSION_ID}",
+ "total_details": null,
+ "ui_mode": "hosted",
+ "url": "https://checkout.stripe.com/c/pay/cs_test_c1qZ1SB9ON9X4HjwvECPXKXwJXjgxYns80vP99CiWvk6GZIatHDSUOzqC8#fid1d2BpamRhQ2prcSc%2FJ1ZqcHdmYCVWZGt2JVV3aicpJ2R1bE5gfCc%2FJ3VuWnFgdnFaXVRmMU5zNkldQTY9SnNRY09XZml2UXNQJyknY3dqaFZgd3Ngdyc%2FcXdwYCknaWR8anBxUXx1YCc%2FJ3Zsa2JpYFpmamlwaGsnKSdga2RnaWBVaWRmYG1qaWFgd3YnP3F3cGB4JSUl"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--checkout.Session.list.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--checkout.Session.list.1.json
new file mode 100644
index 00000000000..dce12681a32
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_realm_legacy_plan--checkout.Session.list.1.json
@@ -0,0 +1,81 @@
+{
+ "data": [
+ {
+ "after_expiration": null,
+ "allow_promotion_codes": null,
+ "amount_subtotal": null,
+ "amount_total": null,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_address_collection": null,
+ "cancel_url": "http://selfhosting.testserver/realm/15439a7d-6911-4d6e-a26a-154a525214ab/upgrade/?manual_license_management=false&tier=1",
+ "client_reference_id": null,
+ "client_secret": null,
+ "consent": null,
+ "consent_collection": null,
+ "created": 1705936955,
+ "currency": null,
+ "currency_conversion": null,
+ "custom_fields": [],
+ "custom_text": {
+ "after_submit": null,
+ "shipping_address": null,
+ "submit": null,
+ "terms_of_service_acceptance": null
+ },
+ "customer": "cus_PQFq9E4uE975fx",
+ "customer_creation": null,
+ "customer_details": {
+ "address": null,
+ "email": "[email protected]",
+ "name": null,
+ "phone": null,
+ "tax_exempt": null,
+ "tax_ids": null
+ },
+ "customer_email": null,
+ "expires_at": 1706023355,
+ "id": "cs_test_c1qZ1SB9ON9X4HjwvECPXKXwJXjgxYns80vP99CiWvk6GZIatHDSUOzqC8",
+ "invoice": null,
+ "invoice_creation": null,
+ "livemode": false,
+ "locale": null,
+ "metadata": {
+ "remote_realm_user_id": "1",
+ "type": "card_update"
+ },
+ "mode": "setup",
+ "object": "checkout.session",
+ "payment_intent": null,
+ "payment_link": null,
+ "payment_method_collection": "always",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {},
+ "payment_method_types": [
+ "card"
+ ],
+ "payment_status": "no_payment_required",
+ "phone_number_collection": {
+ "enabled": false
+ },
+ "recovered_from": null,
+ "setup_intent": "seti_1ObPKZDEQaroqDjs8b3IjTPr",
+ "shipping": null,
+ "shipping_address_collection": null,
+ "shipping_options": [],
+ "shipping_rate": null,
+ "status": "open",
+ "submit_type": null,
+ "subscription": null,
+ "success_url": "http://selfhosting.testserver/realm/15439a7d-6911-4d6e-a26a-154a525214ab/billing/event_status/?stripe_session_id={CHECKOUT_SESSION_ID}",
+ "total_details": null,
+ "ui_mode": "hosted",
+ "url": "https://checkout.stripe.com/c/pay/cs_test_c1qZ1SB9ON9X4HjwvECPXKXwJXjgxYns80vP99CiWvk6GZIatHDSUOzqC8#fid1d2BpamRhQ2prcSc%2FJ1ZqcHdmYCVWZGt2JVV3aicpJ2R1bE5gfCc%2FJ3VuWnFgdnFaXVRmMU5zNkldQTY9SnNRY09XZml2UXNQJyknY3dqaFZgd3Ngdyc%2FcXdwYCknaWR8anBxUXx1YCc%2FJ3Zsa2JpYFpmamlwaGsnKSdga2RnaWBVaWRmYG1qaWFgd3YnP3F3cGB4JSUl"
+ }
+ ],
+ "has_more": true,
+ "object": "list",
+ "url": "/v1/checkout/sessions"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.create.1.json
new file mode 100644
index 00000000000..3d6b9bc66c1
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.create.1.json
@@ -0,0 +1,33 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "demo.example.com 6cde5f7a-1f7",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_NORMALIZED0001",
+ "invoice_prefix": "NORMA01",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": null,
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_server_str": "demo.example.com 6cde5f7a-1f7",
+ "remote_server_uuid": "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.modify.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.modify.1.json
new file mode 100644
index 00000000000..af040d6ebf2
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.modify.1.json
@@ -0,0 +1,33 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "demo.example.com 6cde5f7a-1f7",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_NORMALIZED0001",
+ "invoice_prefix": "NORMA01",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": "pm_1ObOgeDEQaroqDjseaS84gKZ",
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_server_str": "demo.example.com 6cde5f7a-1f7",
+ "remote_server_uuid": "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.1.json
new file mode 100644
index 00000000000..9fa212c26a1
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.1.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "demo.example.com 6cde5f7a-1f7",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_NORMALIZED0001",
+ "invoice_prefix": "NORMA01",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "NORMALIZED000001",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED0001",
+ "id": "pm_1ObOgeDEQaroqDjseaS84gKZ",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_server_str": "demo.example.com 6cde5f7a-1f7",
+ "remote_server_uuid": "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.2.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.2.json
new file mode 100644
index 00000000000..9fa212c26a1
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.2.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "demo.example.com 6cde5f7a-1f7",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_NORMALIZED0001",
+ "invoice_prefix": "NORMA01",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "NORMALIZED000001",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED0001",
+ "id": "pm_1ObOgeDEQaroqDjseaS84gKZ",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_server_str": "demo.example.com 6cde5f7a-1f7",
+ "remote_server_uuid": "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.3.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.3.json
new file mode 100644
index 00000000000..9fa212c26a1
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.3.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "demo.example.com 6cde5f7a-1f7",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_NORMALIZED0001",
+ "invoice_prefix": "NORMA01",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "NORMALIZED000001",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED0001",
+ "id": "pm_1ObOgeDEQaroqDjseaS84gKZ",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_server_str": "demo.example.com 6cde5f7a-1f7",
+ "remote_server_uuid": "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.4.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.4.json
new file mode 100644
index 00000000000..9fa212c26a1
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Customer.retrieve.4.json
@@ -0,0 +1,79 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "demo.example.com 6cde5f7a-1f7",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_NORMALIZED0001",
+ "invoice_prefix": "NORMA01",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "billing_details": {
+ "address": {
+ "city": null,
+ "country": null,
+ "line1": null,
+ "line2": null,
+ "postal_code": null,
+ "state": null
+ },
+ "email": null,
+ "name": null,
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": null,
+ "address_postal_code_check": null,
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 1,
+ "exp_year": 2025,
+ "fingerprint": "NORMALIZED000001",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED0001",
+ "id": "pm_1ObOgeDEQaroqDjseaS84gKZ",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "remote_server_str": "demo.example.com 6cde5f7a-1f7",
+ "remote_server_uuid": "6cde5f7a-1f7e-4978-9716-49f69ebfc9fe"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.create.1.json
new file mode 100644
index 00000000000..274d2109139
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.create.1.json
@@ -0,0 +1,212 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 176000,
+ "amount_paid": 0,
+ "amount_remaining": 176000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": null,
+ "ending_balance": null,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": null,
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": null,
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": -24000,
+ "amount_excluding_tax": -24000,
+ "currency": "usd",
+ "description": "$20.00/month new customer discount",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000001",
+ "invoice_item": "ii_NORMALIZED00000000000001",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000001",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "-24000"
+ },
+ {
+ "amount": 200000,
+ "amount_excluding_tax": 200000,
+ "currency": "usd",
+ "description": "Zulip Business - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000002",
+ "invoice_item": "ii_NORMALIZED00000000000002",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000002",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0002",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 25,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1000000000,
+ "number": null,
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": null,
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "auto"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Business",
+ "status": "draft",
+ "status_transitions": {
+ "finalized_at": null,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 176000,
+ "subtotal_excluding_tax": 176000,
+ "tax": null,
+ "test_clock": null,
+ "total": 176000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 176000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.finalize_invoice.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.finalize_invoice.1.json
new file mode 100644
index 00000000000..20663d0de05
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.finalize_invoice.1.json
@@ -0,0 +1,212 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 176000,
+ "amount_paid": 0,
+ "amount_remaining": 176000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QUUZCVlhNQ1lmTDVLcEdsN1lkZDVKMHhuMW5vQWs1LDk2NDc1Mjg30200s9T6vrBl?s=ap",
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QUUZCVlhNQ1lmTDVLcEdsN1lkZDVKMHhuMW5vQWs1LDk2NDc1Mjg30200s9T6vrBl/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": -24000,
+ "amount_excluding_tax": -24000,
+ "currency": "usd",
+ "description": "$20.00/month new customer discount",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000001",
+ "invoice_item": "ii_NORMALIZED00000000000001",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000001",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "-24000"
+ },
+ {
+ "amount": 200000,
+ "amount_excluding_tax": 200000,
+ "currency": "usd",
+ "description": "Zulip Business - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000002",
+ "invoice_item": "ii_NORMALIZED00000000000002",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000002",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0002",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 25,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1000000000,
+ "number": "NORMALI-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000001",
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "letter"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Business",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 176000,
+ "subtotal_excluding_tax": 176000,
+ "tax": null,
+ "test_clock": null,
+ "total": 176000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 176000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.list.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.list.1.json
new file mode 100644
index 00000000000..e39960ab725
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.list.1.json
@@ -0,0 +1,6 @@
+{
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.list.2.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.list.2.json
new file mode 100644
index 00000000000..eb172329421
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--Invoice.list.2.json
@@ -0,0 +1,219 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 176000,
+ "amount_paid": 0,
+ "amount_remaining": 176000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QUUZCVlhNQ1lmTDVLcEdsN1lkZDVKMHhuMW5vQWs1LDk2NDc1Mjg30200s9T6vrBl?s=ap",
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QUUZCVlhNQ1lmTDVLcEdsN1lkZDVKMHhuMW5vQWs1LDk2NDc1Mjg30200s9T6vrBl/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": -24000,
+ "amount_excluding_tax": -24000,
+ "currency": "usd",
+ "description": "$20.00/month new customer discount",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000001",
+ "invoice_item": "ii_NORMALIZED00000000000001",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000001",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "-24000"
+ },
+ {
+ "amount": 200000,
+ "amount_excluding_tax": 200000,
+ "currency": "usd",
+ "description": "Zulip Business - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000002",
+ "invoice_item": "ii_NORMALIZED00000000000002",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000002",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0002",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 25,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1000000000,
+ "number": "NORMALI-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000001",
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "letter"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Business",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 176000,
+ "subtotal_excluding_tax": 176000,
+ "tax": null,
+ "test_clock": null,
+ "total": 176000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 176000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--InvoiceItem.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--InvoiceItem.create.1.json
new file mode 100644
index 00000000000..5a66ec8d12f
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--InvoiceItem.create.1.json
@@ -0,0 +1,47 @@
+{
+ "amount": 200000,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED0001",
+ "date": 1000000000,
+ "description": "Zulip Business - renewal",
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000002",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1364871845,
+ "start": 1333335845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000002",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0002",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "quantity": 25,
+ "subscription": null,
+ "tax_rates": [],
+ "test_clock": null,
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--InvoiceItem.create.2.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--InvoiceItem.create.2.json
new file mode 100644
index 00000000000..df3e1a69858
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--InvoiceItem.create.2.json
@@ -0,0 +1,47 @@
+{
+ "amount": -24000,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED0001",
+ "date": 1000000000,
+ "description": "$20.00/month new customer discount",
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000001",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "price_NORMALIZED00000000000001",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+ },
+ "proration": false,
+ "quantity": 1,
+ "subscription": null,
+ "tax_rates": [],
+ "test_clock": null,
+ "unit_amount": -24000,
+ "unit_amount_decimal": "-24000"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.create.1.json
new file mode 100644
index 00000000000..649eed8ec64
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.create.1.json
@@ -0,0 +1,34 @@
+{
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "seti_1ObOgeDEQaroqDjshk2gggMZ_secret_PQFBSb5fOXrjqzMOuVk0jppCYjasyqc",
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED0001",
+ "description": null,
+ "flow_directions": null,
+ "id": "seti_1ObOgeDEQaroqDjshk2gggMZ",
+ "last_setup_error": null,
+ "latest_attempt": "setatt_1ObOgeDEQaroqDjs4UWDxlSB",
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": "pm_1ObOgeDEQaroqDjseaS84gKZ",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "succeeded",
+ "usage": "off_session"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.list.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.list.1.json
new file mode 100644
index 00000000000..a26a4efb088
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.list.1.json
@@ -0,0 +1,41 @@
+{
+ "data": [
+ {
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "seti_1ObOgdDEQaroqDjspz8sVDGN_secret_PQFALsI8aRqccVsN5G8xwREw047nyB8",
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED0001",
+ "description": null,
+ "flow_directions": null,
+ "id": "seti_1ObOgdDEQaroqDjspz8sVDGN",
+ "last_setup_error": null,
+ "latest_attempt": null,
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": null,
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "requires_payment_method",
+ "usage": "off_session"
+ }
+ ],
+ "has_more": true,
+ "object": "list",
+ "url": "/v1/setup_intents"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.retrieve.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.retrieve.1.json
new file mode 100644
index 00000000000..649eed8ec64
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--SetupIntent.retrieve.1.json
@@ -0,0 +1,34 @@
+{
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "seti_1ObOgeDEQaroqDjshk2gggMZ_secret_PQFBSb5fOXrjqzMOuVk0jppCYjasyqc",
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED0001",
+ "description": null,
+ "flow_directions": null,
+ "id": "seti_1ObOgeDEQaroqDjshk2gggMZ",
+ "last_setup_error": null,
+ "latest_attempt": "setatt_1ObOgeDEQaroqDjs4UWDxlSB",
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": "pm_1ObOgeDEQaroqDjseaS84gKZ",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "succeeded",
+ "usage": "off_session"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--checkout.Session.create.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--checkout.Session.create.1.json
new file mode 100644
index 00000000000..e9aca33bb81
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--checkout.Session.create.1.json
@@ -0,0 +1,74 @@
+{
+ "after_expiration": null,
+ "allow_promotion_codes": null,
+ "amount_subtotal": null,
+ "amount_total": null,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_address_collection": null,
+ "cancel_url": "http://selfhosting.testserver/server/6cde5f7a-1f7e-4978-9716-49f69ebfc9fe/upgrade/?manual_license_management=false&tier=1",
+ "client_reference_id": null,
+ "client_secret": null,
+ "consent": null,
+ "consent_collection": null,
+ "created": 1000000000,
+ "currency": null,
+ "currency_conversion": null,
+ "custom_fields": [],
+ "custom_text": {
+ "after_submit": null,
+ "shipping_address": null,
+ "submit": null,
+ "terms_of_service_acceptance": null
+ },
+ "customer": "cus_NORMALIZED0001",
+ "customer_creation": null,
+ "customer_details": {
+ "address": null,
+ "email": "[email protected]",
+ "name": null,
+ "phone": null,
+ "tax_exempt": null,
+ "tax_ids": null
+ },
+ "customer_email": null,
+ "expires_at": 1000000000,
+ "id": "cs_test_NORMALIZED02tZPg16h6lq8MUzJcTR3fCVEFLSGvXuTt9jgKURdDLGo8nc",
+ "invoice": null,
+ "invoice_creation": null,
+ "livemode": false,
+ "locale": null,
+ "metadata": {
+ "remote_server_user_id": "1",
+ "type": "card_update"
+ },
+ "mode": "setup",
+ "object": "checkout.session",
+ "payment_intent": null,
+ "payment_link": null,
+ "payment_method_collection": "always",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {},
+ "payment_method_types": [
+ "card"
+ ],
+ "payment_status": "no_payment_required",
+ "phone_number_collection": {
+ "enabled": false
+ },
+ "recovered_from": null,
+ "setup_intent": "seti_1ObOgdDEQaroqDjspz8sVDGN",
+ "shipping": null,
+ "shipping_address_collection": null,
+ "shipping_options": [],
+ "shipping_rate": null,
+ "status": "open",
+ "submit_type": null,
+ "subscription": null,
+ "success_url": "http://selfhosting.testserver/server/6cde5f7a-1f7e-4978-9716-49f69ebfc9fe/billing/event_status/?stripe_session_id={CHECKOUT_SESSION_ID}",
+ "total_details": null,
+ "ui_mode": "hosted",
+ "url": "https://checkout.stripe.com/c/pay/cs_test_NORMALIZED02tZPg16h6lq8MUzJcTR3fCVEFLSGvXuTt9jgKURdDLGo8nc#fid1d2BpamRhQ2prcSc%2FJ1ZqcHdmYCVWZGt2JVV3aicpJ2R1bE5gfCc%2FJ3VuWnFgdnFaXVRmMU5zNkldQTY9SnNRY09XZml2UXNQJyknY3dqaFZgd3Ngdyc%2FcXdwYCknaWR8anBxUXx1YCc%2FJ3Zsa2JpYFpmamlwaGsnKSdga2RnaWBVaWRmYG1qaWFgd3YnP3F3cGB4JSUl"
+}
diff --git a/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--checkout.Session.list.1.json b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--checkout.Session.list.1.json
new file mode 100644
index 00000000000..eefe8c3b55a
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/invoice_scheduled_upgrade_server_legacy_plan--checkout.Session.list.1.json
@@ -0,0 +1,81 @@
+{
+ "data": [
+ {
+ "after_expiration": null,
+ "allow_promotion_codes": null,
+ "amount_subtotal": null,
+ "amount_total": null,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_address_collection": null,
+ "cancel_url": "http://selfhosting.testserver/server/6cde5f7a-1f7e-4978-9716-49f69ebfc9fe/upgrade/?manual_license_management=false&tier=1",
+ "client_reference_id": null,
+ "client_secret": null,
+ "consent": null,
+ "consent_collection": null,
+ "created": 1000000000,
+ "currency": null,
+ "currency_conversion": null,
+ "custom_fields": [],
+ "custom_text": {
+ "after_submit": null,
+ "shipping_address": null,
+ "submit": null,
+ "terms_of_service_acceptance": null
+ },
+ "customer": "cus_NORMALIZED0001",
+ "customer_creation": null,
+ "customer_details": {
+ "address": null,
+ "email": "[email protected]",
+ "name": null,
+ "phone": null,
+ "tax_exempt": null,
+ "tax_ids": null
+ },
+ "customer_email": null,
+ "expires_at": 1000000000,
+ "id": "cs_test_NORMALIZED02tZPg16h6lq8MUzJcTR3fCVEFLSGvXuTt9jgKURdDLGo8nc",
+ "invoice": null,
+ "invoice_creation": null,
+ "livemode": false,
+ "locale": null,
+ "metadata": {
+ "remote_server_user_id": "1",
+ "type": "card_update"
+ },
+ "mode": "setup",
+ "object": "checkout.session",
+ "payment_intent": null,
+ "payment_link": null,
+ "payment_method_collection": "always",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {},
+ "payment_method_types": [
+ "card"
+ ],
+ "payment_status": "no_payment_required",
+ "phone_number_collection": {
+ "enabled": false
+ },
+ "recovered_from": null,
+ "setup_intent": "seti_1ObOgdDEQaroqDjspz8sVDGN",
+ "shipping": null,
+ "shipping_address_collection": null,
+ "shipping_options": [],
+ "shipping_rate": null,
+ "status": "open",
+ "submit_type": null,
+ "subscription": null,
+ "success_url": "http://selfhosting.testserver/server/6cde5f7a-1f7e-4978-9716-49f69ebfc9fe/billing/event_status/?stripe_session_id={CHECKOUT_SESSION_ID}",
+ "total_details": null,
+ "ui_mode": "hosted",
+ "url": "https://checkout.stripe.com/c/pay/cs_test_NORMALIZED02tZPg16h6lq8MUzJcTR3fCVEFLSGvXuTt9jgKURdDLGo8nc#fid1d2BpamRhQ2prcSc%2FJ1ZqcHdmYCVWZGt2JVV3aicpJ2R1bE5gfCc%2FJ3VuWnFgdnFaXVRmMU5zNkldQTY9SnNRY09XZml2UXNQJyknY3dqaFZgd3Ngdyc%2FcXdwYCknaWR8anBxUXx1YCc%2FJ3Zsa2JpYFpmamlwaGsnKSdga2RnaWBVaWRmYG1qaWFgd3YnP3F3cGB4JSUl"
+ }
+ ],
+ "has_more": true,
+ "object": "list",
+ "url": "/v1/checkout/sessions"
+}
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index cb7efdac6a6..6145f2bead3 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -6547,6 +6547,99 @@ class TestRemoteRealmBillingFlow(StripeTestCase, RemoteRealmBillingTestCase):
invoice_plans_as_needed(add_months(self.next_month, 1))
self.assert_length(outbox, messages_count + 1)
+ @responses.activate
+ @mock_stripe()
+ def test_invoice_scheduled_upgrade_realm_legacy_plan(self, *mocks: Mock) -> None:
+ remote_server = RemoteZulipServer.objects.get(hostname="demo.example.com")
+ server_billing_session = RemoteServerBillingSession(remote_server=remote_server)
+
+ # Migrate server to legacy plan.
+ with time_machine.travel(self.now, tick=False):
+ start_date = timezone_now()
+ end_date = add_months(start_date, months=3)
+ server_billing_session.migrate_customer_to_legacy_plan(start_date, end_date)
+
+ # Upload data.
+ self.add_mock_response()
+ with time_machine.travel(self.now, tick=False):
+ send_server_data_to_push_bouncer(consider_usage_statistics=False)
+
+ self.login("hamlet")
+ hamlet = self.example_user("hamlet")
+
+ # Login. Performs customer migration from server to realms.
+ self.execute_remote_billing_authentication_flow(hamlet)
+ remote_server.refresh_from_db()
+
+ # Schedule upgrade to business plan
+ with time_machine.travel(self.now, tick=False):
+ stripe_customer = self.add_card_and_upgrade(
+ remote_server_plan_start_date="billing_cycle_end_date", talk_to_stripe=False
+ )
+
+ zulip_realm_customer = Customer.objects.get(stripe_customer_id=stripe_customer.id)
+ assert zulip_realm_customer is not None
+ realm_legacy_plan = get_current_plan_by_customer(zulip_realm_customer)
+ assert realm_legacy_plan is not None
+ self.assertEqual(realm_legacy_plan.tier, CustomerPlan.TIER_SELF_HOSTED_LEGACY)
+ self.assertEqual(realm_legacy_plan.status, CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END)
+ self.assertEqual(realm_legacy_plan.next_invoice_date, end_date)
+
+ new_plan = self.billing_session.get_next_plan(realm_legacy_plan)
+ assert new_plan is not None
+ self.assertEqual(new_plan.tier, CustomerPlan.TIER_SELF_HOSTED_BUSINESS)
+ self.assertEqual(new_plan.status, CustomerPlan.NEVER_STARTED)
+ self.assertEqual(
+ new_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT
+ )
+ self.assertEqual(new_plan.next_invoice_date, end_date)
+ self.assertEqual(new_plan.billing_cycle_anchor, end_date)
+
+ realm_user_count = UserProfile.objects.filter(
+ realm=hamlet.realm, is_bot=False, is_active=True
+ ).count()
+ licenses = max(
+ realm_user_count,
+ self.billing_session.min_licenses_for_plan(CustomerPlan.TIER_SELF_HOSTED_BUSINESS),
+ )
+
+ with mock.patch("stripe.Invoice.create") as invoice_create, time_machine.travel(
+ end_date, tick=False
+ ):
+ send_server_data_to_push_bouncer(consider_usage_statistics=False)
+ invoice_plans_as_needed()
+ # 'invoice_plan()' is called with both legacy & new plan, but
+ # invoice is created only for new plan. The legacy plan only goes
+ # through the end of cycle updates.
+ invoice_create.assert_called_once()
+
+ realm_legacy_plan.refresh_from_db()
+ new_plan.refresh_from_db()
+ self.assertEqual(realm_legacy_plan.status, CustomerPlan.ENDED)
+ self.assertEqual(realm_legacy_plan.next_invoice_date, None)
+ self.assertEqual(new_plan.status, CustomerPlan.ACTIVE)
+ self.assertEqual(new_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_DONE)
+ self.assertEqual(new_plan.next_invoice_date, add_months(end_date, 1))
+
+ [invoice0] = iter(stripe.Invoice.list(customer=stripe_customer.id))
+
+ [invoice_item0, invoice_item1] = iter(invoice0.lines)
+ invoice_item_params = {
+ "amount": -2000 * 12,
+ "description": "$20.00/month new customer discount",
+ "quantity": 1,
+ }
+ for key, value in invoice_item_params.items():
+ self.assertEqual(invoice_item0[key], value)
+
+ invoice_item_params = {
+ "amount": licenses * 80 * 100,
+ "description": "Zulip Business - renewal",
+ "quantity": licenses,
+ }
+ for key, value in invoice_item_params.items():
+ self.assertEqual(invoice_item1[key], value)
+
@override_settings(PUSH_NOTIFICATION_BOUNCER_URL="https://push.zulip.org.example.com")
class TestRemoteServerBillingFlow(StripeTestCase, RemoteServerTestCase):
@@ -6855,6 +6948,7 @@ class TestRemoteServerBillingFlow(StripeTestCase, RemoteServerTestCase):
new_customer_plan = self.billing_session.get_next_plan(customer_plan)
assert new_customer_plan is not None
self.assertEqual(new_customer_plan.tier, CustomerPlan.TIER_SELF_HOSTED_BUSINESS)
+ self.assertEqual(new_customer_plan.status, CustomerPlan.NEVER_STARTED)
self.assertEqual(new_customer_plan.billing_cycle_anchor, end_date)
# Visit billing page
@@ -7379,3 +7473,90 @@ class TestRemoteServerBillingFlow(StripeTestCase, RemoteServerTestCase):
self.assertEqual(self.remote_server.plan_type, RemoteZulipServer.PLAN_TYPE_SELF_MANAGED)
self.assertEqual(plan.next_invoice_date, None)
self.assertEqual(plan.status, CustomerPlan.ENDED)
+
+ @responses.activate
+ @mock_stripe()
+ def test_invoice_scheduled_upgrade_server_legacy_plan(self, *mocks: Mock) -> None:
+ # Upload data
+ self.add_mock_response()
+ with time_machine.travel(self.now, tick=False):
+ send_server_data_to_push_bouncer(consider_usage_statistics=False)
+
+ # Migrate server to legacy plan.
+ with time_machine.travel(self.now, tick=False):
+ start_date = timezone_now()
+ end_date = add_months(start_date, months=3)
+ self.billing_session.migrate_customer_to_legacy_plan(start_date, end_date)
+
+ customer = self.billing_session.get_customer()
+ assert customer is not None
+ legacy_plan = get_current_plan_by_customer(customer)
+ assert legacy_plan is not None
+ self.assertEqual(legacy_plan.tier, CustomerPlan.TIER_SELF_HOSTED_LEGACY)
+ self.assertEqual(legacy_plan.status, CustomerPlan.ACTIVE)
+ self.assertEqual(legacy_plan.next_invoice_date, end_date)
+
+ self.login("hamlet")
+ hamlet = self.example_user("hamlet")
+
+ self.execute_remote_billing_authentication_flow(hamlet.delivery_email, hamlet.full_name)
+ # Add card and schedule upgrade
+ with time_machine.travel(self.now, tick=False):
+ stripe_customer = self.add_card_and_upgrade(
+ remote_server_plan_start_date="billing_cycle_end_date", talk_to_stripe=False
+ )
+ legacy_plan.refresh_from_db()
+ self.assertEqual(legacy_plan.status, CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END)
+ new_plan = self.billing_session.get_next_plan(legacy_plan)
+ assert new_plan is not None
+ self.assertEqual(new_plan.tier, CustomerPlan.TIER_SELF_HOSTED_BUSINESS)
+ self.assertEqual(new_plan.status, CustomerPlan.NEVER_STARTED)
+ self.assertEqual(
+ new_plan.invoicing_status,
+ CustomerPlan.INVOICING_STATUS_INITIAL_INVOICE_TO_BE_SENT,
+ )
+ self.assertEqual(new_plan.next_invoice_date, end_date)
+ self.assertEqual(new_plan.billing_cycle_anchor, end_date)
+
+ server_user_count = UserProfile.objects.filter(is_bot=False, is_active=True).count()
+ min_licenses = self.billing_session.min_licenses_for_plan(
+ CustomerPlan.TIER_SELF_HOSTED_BUSINESS
+ )
+ licenses = max(min_licenses, server_user_count)
+
+ with mock.patch("stripe.Invoice.create") as invoice_create, time_machine.travel(
+ end_date, tick=False
+ ):
+ send_server_data_to_push_bouncer(consider_usage_statistics=False)
+ invoice_plans_as_needed()
+ # 'invoice_plan()' is called with both legacy & new plan, but
+ # invoice is created only for new plan. The legacy plan only
+ # goes through the end of cycle updates.
+ invoice_create.assert_called_once()
+
+ legacy_plan.refresh_from_db()
+ new_plan.refresh_from_db()
+ self.assertEqual(legacy_plan.status, CustomerPlan.ENDED)
+ self.assertEqual(legacy_plan.next_invoice_date, None)
+ self.assertEqual(new_plan.status, CustomerPlan.ACTIVE)
+ self.assertEqual(new_plan.invoicing_status, CustomerPlan.INVOICING_STATUS_DONE)
+ self.assertEqual(new_plan.next_invoice_date, add_months(end_date, 1))
+
+ [invoice0] = iter(stripe.Invoice.list(customer=stripe_customer.id))
+
+ [invoice_item0, invoice_item1] = iter(invoice0.lines)
+ invoice_item_params = {
+ "amount": -2000 * 12,
+ "description": "$20.00/month new customer discount",
+ "quantity": 1,
+ }
+ for key, value in invoice_item_params.items():
+ self.assertEqual(invoice_item0[key], value)
+
+ invoice_item_params = {
+ "amount": licenses * 80 * 100,
+ "description": "Zulip Business - renewal",
+ "quantity": licenses,
+ }
+ for key, value in invoice_item_params.items():
+ self.assertEqual(invoice_item1[key], value)