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.

corporate: Move void_all_open_invoices to BillingSession.

Lauryn Menard4fb564026d62
diff --git a/analytics/tests/test_support_views.py b/analytics/tests/test_support_views.py
index f3441a2e5c9..092eb02ef86 100644
--- a/analytics/tests/test_support_views.py
+++ b/analytics/tests/test_support_views.py
@@ -758,7 +758,9 @@ class TestSupportEndpoint(ZulipTestCase):
with mock.patch(
"analytics.views.support.RealmBillingSession.downgrade_now_without_creating_additional_invoices"
) as m1:
- with mock.patch("analytics.views.support.void_all_open_invoices", return_value=1) as m2:
+ with mock.patch(
+ "analytics.views.support.RealmBillingSession.void_all_open_invoices", return_value=1
+ ) as m2:
result = self.client_post(
"/activity/support",
{
@@ -767,7 +769,7 @@ class TestSupportEndpoint(ZulipTestCase):
},
)
m1.assert_called_once()
- m2.assert_called_once_with(get_realm("zulip"))
+ m2.assert_called_once()
self.assert_in_success_response(
["zulip downgraded and voided 1 open invoices"], result
)
diff --git a/analytics/views/support.py b/analytics/views/support.py
index 2c7bac46fbf..a1584c34dc1 100644
--- a/analytics/views/support.py
+++ b/analytics/views/support.py
@@ -58,7 +58,6 @@ if settings.BILLING_ENABLED:
SupportType,
SupportViewRequest,
get_latest_seat_count,
- void_all_open_invoices,
)
from corporate.lib.support import (
get_discount_for_realm,
@@ -263,7 +262,7 @@ def support(
] = f"{realm.string_id} downgraded without creating additional invoices"
elif modify_plan == "downgrade_now_void_open_invoices":
billing_session.downgrade_now_without_creating_additional_invoices()
- voided_invoices_count = void_all_open_invoices(realm)
+ voided_invoices_count = billing_session.void_all_open_invoices()
context[
"success_message"
] = f"{realm.string_id} downgraded and voided {voided_invoices_count} open invoices"
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 7703c3d4985..f2f5a1cee16 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1561,6 +1561,19 @@ class BillingSession(ABC):
assert plan is not None
do_change_plan_status(plan, CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE)
+ def void_all_open_invoices(self) -> int:
+ customer = self.get_customer()
+ if customer is None:
+ return 0
+ invoices = get_all_invoices_for_customer(customer)
+ voided_invoices_count = 0
+ for invoice in invoices:
+ if invoice.status == "open":
+ assert invoice.id is not None
+ stripe.Invoice.void_invoice(invoice.id)
+ voided_invoices_count += 1
+ return voided_invoices_count
+
# During realm deactivation we instantly downgrade the plan to Limited.
# Extra users added in the final month are not charged. Also used
# for the cancellation of Free Trial.
@@ -3151,20 +3164,6 @@ def get_all_invoices_for_customer(customer: Customer) -> Generator[stripe.Invoic
)
-def void_all_open_invoices(realm: Realm) -> int:
- customer = get_customer_by_realm(realm)
- if customer is None:
- return 0
- invoices = get_all_invoices_for_customer(customer)
- voided_invoices_count = 0
- for invoice in invoices:
- if invoice.status == "open":
- assert invoice.id is not None
- stripe.Invoice.void_invoice(invoice.id)
- voided_invoices_count += 1
- return voided_invoices_count
-
-
def customer_has_last_n_invoices_open(customer: Customer, n: int) -> bool:
if customer.stripe_customer_id is None: # nocoverage
return False
@@ -3195,7 +3194,7 @@ def downgrade_small_realms_behind_on_payments_as_needed() -> None:
# We've now decided to downgrade this customer and void all invoices, and the below will execute this.
billing_session = RealmBillingSession(user=None, realm=realm)
billing_session.downgrade_now_without_creating_additional_invoices()
- void_all_open_invoices(realm)
+ billing_session.void_all_open_invoices()
context: Dict[str, Union[str, Realm]] = {
"upgrade_url": f"{realm.uri}{reverse('upgrade_page')}",
"realm": realm,
@@ -3210,4 +3209,7 @@ def downgrade_small_realms_behind_on_payments_as_needed() -> None:
)
else:
if customer_has_last_n_invoices_open(customer, 1):
- void_all_open_invoices(realm)
+ # If a small realm, without an active plan, has
+ # the last invoice open, void the open invoices.
+ billing_session = RealmBillingSession(user=None, realm=realm)
+ billing_session.void_all_open_invoices()
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.1.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.1.json
index c6547b86a36..d51abd4e9ec 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.1.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.1.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvOXlXRkt5MzRORjBnQzFTSUhWcjFPSjRTT2NkLDkwNzk3MjA50200YGJ2NPPR?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODM30200upxFIB1S?s=ap",
"id": "in_NORMALIZED00000000000001",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvOXlXRkt5MzRORjBnQzFTSUhWcjFPSjRTT2NkLDkwNzk3MjA50200YGJ2NPPR/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODM30200upxFIB1S/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
@@ -154,5 +154,5 @@
"total_excluding_tax": 10000,
"total_tax_amounts": [],
"transfer_data": null,
- "webhooks_delivered_at": null
+ "webhooks_delivered_at": 1000000000
}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.2.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.2.json
index 6305fc54a9d..8dbf351f31d 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.2.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.2.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvY2dvOVVsWUhwMUdZRThMQ05LbHByMU9qMzgxLDkwNzk3MjEy0200ZEQL6SGL?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zR0ludkFteWg2TGhESHlqRFk3QlBiOXB0UjRuLDkxOTg3ODQz0200HrCxNaZi?s=ap",
"id": "in_NORMALIZED00000000000002",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvY2dvOVVsWUhwMUdZRThMQ05LbHByMU9qMzgxLDkwNzk3MjEy0200ZEQL6SGL/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zR0ludkFteWg2TGhESHlqRFk3QlBiOXB0UjRuLDkxOTg3ODQz0200HrCxNaZi/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.3.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.3.json
index fd10c3e5cb1..c2d252559a1 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.3.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.3.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcFRXNTk3N2lOdlNjc2FNWFFJdHVYaFl5bUw5LDkwNzk3MjE00200LQm4HAva?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3ODUy0200N7T1v5Ug?s=ap",
"id": "in_NORMALIZED00000000000003",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcFRXNTk3N2lOdlNjc2FNWFFJdHVYaFl5bUw5LDkwNzk3MjE00200LQm4HAva/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3ODUy0200N7T1v5Ug/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
@@ -154,5 +154,5 @@
"total_excluding_tax": 10000,
"total_tax_amounts": [],
"transfer_data": null,
- "webhooks_delivered_at": null
+ "webhooks_delivered_at": 1000000000
}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.4.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.4.json
index d8fcad733c1..9e700ad9af8 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.4.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.4.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvYXIyN3BKNDFEbXZIVmVTNXJwNkpBV2JpRk1rLDkwNzk3MjE20200HfH858XY?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODUz0200KokZjam1?s=ap",
"id": "in_NORMALIZED00000000000004",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvYXIyN3BKNDFEbXZIVmVTNXJwNkpBV2JpRk1rLDkwNzk3MjE20200HfH858XY/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODUz0200KokZjam1/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.5.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.5.json
index 9ada85e8602..debe721aaaf 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.5.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.5.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcjd0Z3owZmIxMklIOFhBbFdVMFQxTVlZMmZWLDkwNzk3MjE40200GRL71WPc?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zVVdNMzhmUzNQODk3WGhuV09uVmh3bXNNbHhwLDkxOTg3ODU20200o2YvMshB?s=ap",
"id": "in_NORMALIZED00000000000005",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcjd0Z3owZmIxMklIOFhBbFdVMFQxTVlZMmZWLDkwNzk3MjE40200GRL71WPc/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zVVdNMzhmUzNQODk3WGhuV09uVmh3bXNNbHhwLDkxOTg3ODU20200o2YvMshB/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
@@ -154,5 +154,5 @@
"total_excluding_tax": 10000,
"total_tax_amounts": [],
"transfer_data": null,
- "webhooks_delivered_at": null
+ "webhooks_delivered_at": 1000000000
}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.6.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.6.json
index 0ec037e08a1..3ac14d180e0 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.6.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.6.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvd0N3MUpXS1ZXMGdLelhBRkM0cU82ODU4NWp4LDkwNzk3MjIx0200QbwNncrS?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3ODU40200psOmU2aX?s=ap",
"id": "in_NORMALIZED00000000000006",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvd0N3MUpXS1ZXMGdLelhBRkM0cU82ODU4NWp4LDkwNzk3MjIx0200QbwNncrS/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3ODU40200psOmU2aX/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.7.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.7.json
index 8f408b07875..fa8b4cdd55f 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.7.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.7.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvakl5NThVWDQ1RG5sUFlBa0Zpa1J3NXE2WURILDkwNzk3MjI0020060kueflN?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zSmVJOEFpYU9mTE5JMGFzN05tdDVncUpKeDdlLDkxOTg3ODcy0200wxjqltn4?s=ap",
"id": "in_NORMALIZED00000000000007",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvakl5NThVWDQ1RG5sUFlBa0Zpa1J3NXE2WURILDkwNzk3MjI0020060kueflN/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zSmVJOEFpYU9mTE5JMGFzN05tdDVncUpKeDdlLDkxOTg3ODcy0200wxjqltn4/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
@@ -154,5 +154,5 @@
"total_excluding_tax": 10000,
"total_tax_amounts": [],
"transfer_data": null,
- "webhooks_delivered_at": null
+ "webhooks_delivered_at": 1000000000
}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.8.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.8.json
index 7fd8bdfe361..286d2ff1008 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.8.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.finalize_invoice.8.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvanlXeXBJNVVrUmN2UUxBeDJrUzdRVXNXNFI5LDkwNzk3MjI30200vRYyGUVn?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zeUxMc0psMGh6dXk2NVN3RHBJS1hCYjhyUTAxLDkxOTg3ODgw0200uZl3iVT0?s=ap",
"id": "in_NORMALIZED00000000000008",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvanlXeXBJNVVrUmN2UUxBeDJrUzdRVXNXNFI5LDkwNzk3MjI30200vRYyGUVn/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zeUxMc0psMGh6dXk2NVN3RHBJS1hCYjhyUTAxLDkxOTg3ODgw0200uZl3iVT0/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.10.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.10.json
new file mode 100644
index 00000000000..5cb8cfb3b18
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.10.json
@@ -0,0 +1,323 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0006",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3OTA00200tPqNOv6G?s=ap",
+ "id": "in_NORMALIZED00000000000006",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3OTA00200tPqNOv6G/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000006",
+ "invoice_item": "ii_NORMALIZED00000000000006",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000006/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0006",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": true,
+ "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": "letter"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "status": "paid",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": 1000000000,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ },
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0006",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zVVdNMzhmUzNQODk3WGhuV09uVmh3bXNNbHhwLDkxOTg3OTA00200Ch0wFaMl?s=ap",
+ "id": "in_NORMALIZED00000000000005",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zVVdNMzhmUzNQODk3WGhuV09uVmh3bXNNbHhwLDkxOTg3OTA00200Ch0wFaMl/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000005",
+ "invoice_item": "ii_NORMALIZED00000000000005",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000005/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0005",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": true,
+ "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": "letter"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "status": "paid",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": 1000000000,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "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/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.11.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.11.json
new file mode 100644
index 00000000000..e39960ab725
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.11.json
@@ -0,0 +1,6 @@
+{
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.12.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.12.json
new file mode 100644
index 00000000000..c1d40a3a27f
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.12.json
@@ -0,0 +1,165 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0004",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zR0ludkFteWg2TGhESHlqRFk3QlBiOXB0UjRuLDkxOTg3OTA102009jNNTK4w?s=ap",
+ "id": "in_NORMALIZED00000000000002",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zR0ludkFteWg2TGhESHlqRFk3QlBiOXB0UjRuLDkxOTg3OTA102009jNNTK4w/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000002",
+ "invoice_item": "ii_NORMALIZED00000000000002",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000002/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0002",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000002",
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "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/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.13.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.13.json
new file mode 100644
index 00000000000..f400a99f55f
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.13.json
@@ -0,0 +1,165 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0005",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3OTA10200cRJhKU91?s=ap",
+ "id": "in_NORMALIZED00000000000004",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3OTA10200cRJhKU91/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000004",
+ "invoice_item": "ii_NORMALIZED00000000000004",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000004/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0004",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000004",
+ "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 Cloud Standard",
+ "status": "void",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": 1000000000
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ }
+ ],
+ "has_more": true,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.14.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.14.json
new file mode 100644
index 00000000000..1b46fc43e5d
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.14.json
@@ -0,0 +1,165 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0006",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3OTA20200OUEUwWbp?s=ap",
+ "id": "in_NORMALIZED00000000000006",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3OTA20200OUEUwWbp/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000006",
+ "invoice_item": "ii_NORMALIZED00000000000006",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000006/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0006",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": true,
+ "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": "letter"
+ }
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "status": "paid",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": 1000000000,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ }
+ ],
+ "has_more": true,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.15.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.15.json
new file mode 100644
index 00000000000..a8a346ef31d
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.15.json
@@ -0,0 +1,323 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0007",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zeUxMc0psMGh6dXk2NVN3RHBJS1hCYjhyUTAxLDkxOTg3OTA2020053eydl1A?s=ap",
+ "id": "in_NORMALIZED00000000000008",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zeUxMc0psMGh6dXk2NVN3RHBJS1hCYjhyUTAxLDkxOTg3OTA2020053eydl1A/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000008",
+ "invoice_item": "ii_NORMALIZED00000000000008",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000008/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0008",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000008",
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ },
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0007",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zSmVJOEFpYU9mTE5JMGFzN05tdDVncUpKeDdlLDkxOTg3OTA20200BqkV9DLT?s=ap",
+ "id": "in_NORMALIZED00000000000007",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zSmVJOEFpYU9mTE5JMGFzN05tdDVncUpKeDdlLDkxOTg3OTA20200BqkV9DLT/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000007",
+ "invoice_item": "ii_NORMALIZED00000000000007",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000007/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0007",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000007",
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "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/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.2.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.2.json
index 6af424d6c99..adee0b0a4eb 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.2.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.2.json
@@ -42,9 +42,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvOXlXRkt5MzRORjBnQzFTSUhWcjFPSjRTT2NkLDkwNzk3MjI30200T967Zo9W?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODgz0200R2ilEUVW?s=ap",
"id": "in_NORMALIZED00000000000001",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvOXlXRkt5MzRORjBnQzFTSUhWcjFPSjRTT2NkLDkwNzk3MjI30200T967Zo9W/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODgz0200R2ilEUVW/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.3.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.3.json
index e39960ab725..adee0b0a4eb 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.3.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.3.json
@@ -1,5 +1,164 @@
{
- "data": [],
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0002",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODgz0200R2ilEUVW?s=ap",
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODgz0200R2ilEUVW/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "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/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.4.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.4.json
index 63ce5a83f97..e39960ab725 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.4.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.4.json
@@ -1,164 +1,5 @@
{
- "data": [
- {
- "account_country": "US",
- "account_name": "Kandra Labs, Inc.",
- "account_tax_ids": null,
- "amount_due": 10000,
- "amount_paid": 0,
- "amount_remaining": 10000,
- "amount_shipping": 0,
- "application": null,
- "application_fee_amount": null,
- "attempt_count": 0,
- "attempted": false,
- "auto_advance": true,
- "automatic_tax": {
- "enabled": false,
- "status": null
- },
- "billing_reason": "manual",
- "charge": null,
- "collection_method": "send_invoice",
- "created": 1000000000,
- "currency": "usd",
- "custom_fields": null,
- "customer": "cus_NORMALIZED0004",
- "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": 1000000000,
- "effective_at": 1000000000,
- "ending_balance": 0,
- "footer": null,
- "from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvY2dvOVVsWUhwMUdZRThMQ05LbHByMU9qMzgxLDkwNzk3MjI40200PElWRyWq?s=ap",
- "id": "in_NORMALIZED00000000000002",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvY2dvOVVsWUhwMUdZRThMQ05LbHByMU9qMzgxLDkwNzk3MjI40200PElWRyWq/pdf?s=ap",
- "last_finalization_error": null,
- "latest_revision": null,
- "lines": {
- "data": [
- {
- "amount": 10000,
- "amount_excluding_tax": 10000,
- "currency": "usd",
- "description": "Zulip Cloud Standard",
- "discount_amounts": [],
- "discountable": false,
- "discounts": [],
- "id": "il_NORMALIZED00000000000002",
- "invoice_item": "ii_NORMALIZED00000000000002",
- "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": 10000,
- "unit_amount_decimal": "10000"
- },
- "proration": false,
- "proration_details": {
- "credited_items": null
- },
- "quantity": 1,
- "subscription": null,
- "tax_amounts": [],
- "tax_rates": [],
- "type": "invoiceitem",
- "unit_amount_excluding_tax": "10000"
- }
- ],
- "has_more": false,
- "object": "list",
- "total_count": 1,
- "url": "/v1/invoices/in_NORMALIZED00000000000002/lines"
- },
- "livemode": false,
- "metadata": {},
- "next_payment_attempt": null,
- "number": "NORMALI-0002",
- "object": "invoice",
- "on_behalf_of": null,
- "paid": false,
- "paid_out_of_band": false,
- "payment_intent": "pi_NORMALIZED00000000000002",
- "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 Cloud Standard",
- "status": "open",
- "status_transitions": {
- "finalized_at": 1000000000,
- "marked_uncollectible_at": null,
- "paid_at": null,
- "voided_at": null
- },
- "subscription": null,
- "subscription_details": {
- "metadata": null
- },
- "subtotal": 10000,
- "subtotal_excluding_tax": 10000,
- "tax": null,
- "test_clock": null,
- "total": 10000,
- "total_discount_amounts": [],
- "total_excluding_tax": 10000,
- "total_tax_amounts": [],
- "transfer_data": null,
- "webhooks_delivered_at": 1000000000
- }
- ],
+ "data": [],
"has_more": false,
"object": "list",
"url": "/v1/invoices"
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.5.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.5.json
index d0335f5f0e5..e39960ab725 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.5.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.5.json
@@ -1,322 +1,5 @@
{
- "data": [
- {
- "account_country": "US",
- "account_name": "Kandra Labs, Inc.",
- "account_tax_ids": null,
- "amount_due": 10000,
- "amount_paid": 0,
- "amount_remaining": 10000,
- "amount_shipping": 0,
- "application": null,
- "application_fee_amount": null,
- "attempt_count": 0,
- "attempted": false,
- "auto_advance": true,
- "automatic_tax": {
- "enabled": false,
- "status": null
- },
- "billing_reason": "manual",
- "charge": null,
- "collection_method": "send_invoice",
- "created": 1000000000,
- "currency": "usd",
- "custom_fields": null,
- "customer": "cus_NORMALIZED0005",
- "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": 1000000000,
- "effective_at": 1000000000,
- "ending_balance": 0,
- "footer": null,
- "from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvYXIyN3BKNDFEbXZIVmVTNXJwNkpBV2JpRk1rLDkwNzk3MjI402006wxrWPOj?s=ap",
- "id": "in_NORMALIZED00000000000004",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvYXIyN3BKNDFEbXZIVmVTNXJwNkpBV2JpRk1rLDkwNzk3MjI402006wxrWPOj/pdf?s=ap",
- "last_finalization_error": null,
- "latest_revision": null,
- "lines": {
- "data": [
- {
- "amount": 10000,
- "amount_excluding_tax": 10000,
- "currency": "usd",
- "description": "Zulip Cloud Standard",
- "discount_amounts": [],
- "discountable": false,
- "discounts": [],
- "id": "il_NORMALIZED00000000000004",
- "invoice_item": "ii_NORMALIZED00000000000004",
- "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": 10000,
- "unit_amount_decimal": "10000"
- },
- "proration": false,
- "proration_details": {
- "credited_items": null
- },
- "quantity": 1,
- "subscription": null,
- "tax_amounts": [],
- "tax_rates": [],
- "type": "invoiceitem",
- "unit_amount_excluding_tax": "10000"
- }
- ],
- "has_more": false,
- "object": "list",
- "total_count": 1,
- "url": "/v1/invoices/in_NORMALIZED00000000000004/lines"
- },
- "livemode": false,
- "metadata": {},
- "next_payment_attempt": null,
- "number": "NORMALI-0004",
- "object": "invoice",
- "on_behalf_of": null,
- "paid": false,
- "paid_out_of_band": false,
- "payment_intent": "pi_NORMALIZED00000000000004",
- "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 Cloud Standard",
- "status": "open",
- "status_transitions": {
- "finalized_at": 1000000000,
- "marked_uncollectible_at": null,
- "paid_at": null,
- "voided_at": null
- },
- "subscription": null,
- "subscription_details": {
- "metadata": null
- },
- "subtotal": 10000,
- "subtotal_excluding_tax": 10000,
- "tax": null,
- "test_clock": null,
- "total": 10000,
- "total_discount_amounts": [],
- "total_excluding_tax": 10000,
- "total_tax_amounts": [],
- "transfer_data": null,
- "webhooks_delivered_at": 1000000000
- },
- {
- "account_country": "US",
- "account_name": "Kandra Labs, Inc.",
- "account_tax_ids": null,
- "amount_due": 10000,
- "amount_paid": 0,
- "amount_remaining": 10000,
- "amount_shipping": 0,
- "application": null,
- "application_fee_amount": null,
- "attempt_count": 0,
- "attempted": false,
- "auto_advance": true,
- "automatic_tax": {
- "enabled": false,
- "status": null
- },
- "billing_reason": "manual",
- "charge": null,
- "collection_method": "send_invoice",
- "created": 1000000000,
- "currency": "usd",
- "custom_fields": null,
- "customer": "cus_NORMALIZED0005",
- "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": 1000000000,
- "effective_at": 1000000000,
- "ending_balance": 0,
- "footer": null,
- "from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcFRXNTk3N2lOdlNjc2FNWFFJdHVYaFl5bUw5LDkwNzk3MjI40200vtDT9cyt?s=ap",
- "id": "in_NORMALIZED00000000000003",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcFRXNTk3N2lOdlNjc2FNWFFJdHVYaFl5bUw5LDkwNzk3MjI40200vtDT9cyt/pdf?s=ap",
- "last_finalization_error": null,
- "latest_revision": null,
- "lines": {
- "data": [
- {
- "amount": 10000,
- "amount_excluding_tax": 10000,
- "currency": "usd",
- "description": "Zulip Cloud Standard",
- "discount_amounts": [],
- "discountable": false,
- "discounts": [],
- "id": "il_NORMALIZED00000000000003",
- "invoice_item": "ii_NORMALIZED00000000000003",
- "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": 10000,
- "unit_amount_decimal": "10000"
- },
- "proration": false,
- "proration_details": {
- "credited_items": null
- },
- "quantity": 1,
- "subscription": null,
- "tax_amounts": [],
- "tax_rates": [],
- "type": "invoiceitem",
- "unit_amount_excluding_tax": "10000"
- }
- ],
- "has_more": false,
- "object": "list",
- "total_count": 1,
- "url": "/v1/invoices/in_NORMALIZED00000000000003/lines"
- },
- "livemode": false,
- "metadata": {},
- "next_payment_attempt": null,
- "number": "NORMALI-0003",
- "object": "invoice",
- "on_behalf_of": null,
- "paid": false,
- "paid_out_of_band": false,
- "payment_intent": "pi_NORMALIZED00000000000003",
- "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 Cloud Standard",
- "status": "open",
- "status_transitions": {
- "finalized_at": 1000000000,
- "marked_uncollectible_at": null,
- "paid_at": null,
- "voided_at": null
- },
- "subscription": null,
- "subscription_details": {
- "metadata": null
- },
- "subtotal": 10000,
- "subtotal_excluding_tax": 10000,
- "tax": null,
- "test_clock": null,
- "total": 10000,
- "total_discount_amounts": [],
- "total_excluding_tax": 10000,
- "total_tax_amounts": [],
- "transfer_data": null,
- "webhooks_delivered_at": 1000000000
- }
- ],
+ "data": [],
"has_more": false,
"object": "list",
"url": "/v1/invoices"
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.6.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.6.json
index a35013d254c..98107fef849 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.6.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.6.json
@@ -12,7 +12,7 @@
"application_fee_amount": null,
"attempt_count": 0,
"attempted": false,
- "auto_advance": false,
+ "auto_advance": true,
"automatic_tax": {
"enabled": false,
"status": null
@@ -23,9 +23,9 @@
"created": 1000000000,
"currency": "usd",
"custom_fields": null,
- "customer": "cus_NORMALIZED0006",
+ "customer": "cus_NORMALIZED0004",
"customer_address": null,
- "customer_email": "[email protected]",
+ "customer_email": "[email protected]",
"customer_name": null,
"customer_phone": null,
"customer_shipping": null,
@@ -42,9 +42,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvd0N3MUpXS1ZXMGdLelhBRkM0cU82ODU4NWp4LDkwNzk3MjI50200wHk0W9t2?s=ap",
- "id": "in_NORMALIZED00000000000006",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvd0N3MUpXS1ZXMGdLelhBRkM0cU82ODU4NWp4LDkwNzk3MjI50200wHk0W9t2/pdf?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zR0ludkFteWg2TGhESHlqRFk3QlBiOXB0UjRuLDkxOTg3ODk202004ttFZRjb?s=ap",
+ "id": "in_NORMALIZED00000000000002",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zR0ludkFteWg2TGhESHlqRFk3QlBiOXB0UjRuLDkxOTg3ODk202004ttFZRjb/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
@@ -57,8 +57,8 @@
"discount_amounts": [],
"discountable": false,
"discounts": [],
- "id": "il_NORMALIZED00000000000006",
- "invoice_item": "ii_NORMALIZED00000000000006",
+ "id": "il_NORMALIZED00000000000002",
+ "invoice_item": "ii_NORMALIZED00000000000002",
"livemode": false,
"metadata": {},
"object": "line_item",
@@ -103,17 +103,17 @@
"has_more": false,
"object": "list",
"total_count": 1,
- "url": "/v1/invoices/in_NORMALIZED00000000000006/lines"
+ "url": "/v1/invoices/in_NORMALIZED00000000000002/lines"
},
"livemode": false,
"metadata": {},
"next_payment_attempt": null,
- "number": "NORMALI-0006",
+ "number": "NORMALI-0002",
"object": "invoice",
"on_behalf_of": null,
- "paid": true,
- "paid_out_of_band": true,
- "payment_intent": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000002",
"payment_settings": {
"default_mandate": null,
"payment_method_options": null,
@@ -136,169 +136,11 @@
"shipping_details": null,
"starting_balance": 0,
"statement_descriptor": "Zulip Cloud Standard",
- "status": "paid",
+ "status": "open",
"status_transitions": {
"finalized_at": 1000000000,
"marked_uncollectible_at": null,
- "paid_at": 1000000000,
- "voided_at": null
- },
- "subscription": null,
- "subscription_details": {
- "metadata": null
- },
- "subtotal": 10000,
- "subtotal_excluding_tax": 10000,
- "tax": null,
- "test_clock": null,
- "total": 10000,
- "total_discount_amounts": [],
- "total_excluding_tax": 10000,
- "total_tax_amounts": [],
- "transfer_data": null,
- "webhooks_delivered_at": 1000000000
- },
- {
- "account_country": "US",
- "account_name": "Kandra Labs, Inc.",
- "account_tax_ids": null,
- "amount_due": 10000,
- "amount_paid": 0,
- "amount_remaining": 10000,
- "amount_shipping": 0,
- "application": null,
- "application_fee_amount": null,
- "attempt_count": 0,
- "attempted": false,
- "auto_advance": false,
- "automatic_tax": {
- "enabled": false,
- "status": null
- },
- "billing_reason": "manual",
- "charge": null,
- "collection_method": "send_invoice",
- "created": 1000000000,
- "currency": "usd",
- "custom_fields": null,
- "customer": "cus_NORMALIZED0006",
- "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": 1000000000,
- "effective_at": 1000000000,
- "ending_balance": 0,
- "footer": null,
- "from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcjd0Z3owZmIxMklIOFhBbFdVMFQxTVlZMmZWLDkwNzk3MjI50200U9bDJ2Pr?s=ap",
- "id": "in_NORMALIZED00000000000005",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcjd0Z3owZmIxMklIOFhBbFdVMFQxTVlZMmZWLDkwNzk3MjI50200U9bDJ2Pr/pdf?s=ap",
- "last_finalization_error": null,
- "latest_revision": null,
- "lines": {
- "data": [
- {
- "amount": 10000,
- "amount_excluding_tax": 10000,
- "currency": "usd",
- "description": "Zulip Cloud Standard",
- "discount_amounts": [],
- "discountable": false,
- "discounts": [],
- "id": "il_NORMALIZED00000000000005",
- "invoice_item": "ii_NORMALIZED00000000000005",
- "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": 10000,
- "unit_amount_decimal": "10000"
- },
- "proration": false,
- "proration_details": {
- "credited_items": null
- },
- "quantity": 1,
- "subscription": null,
- "tax_amounts": [],
- "tax_rates": [],
- "type": "invoiceitem",
- "unit_amount_excluding_tax": "10000"
- }
- ],
- "has_more": false,
- "object": "list",
- "total_count": 1,
- "url": "/v1/invoices/in_NORMALIZED00000000000005/lines"
- },
- "livemode": false,
- "metadata": {},
- "next_payment_attempt": null,
- "number": "NORMALI-0005",
- "object": "invoice",
- "on_behalf_of": null,
- "paid": true,
- "paid_out_of_band": true,
- "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": "letter"
- }
- },
- "rendering_options": null,
- "shipping_cost": null,
- "shipping_details": null,
- "starting_balance": 0,
- "statement_descriptor": "Zulip Cloud Standard",
- "status": "paid",
- "status_transitions": {
- "finalized_at": 1000000000,
- "marked_uncollectible_at": null,
- "paid_at": 1000000000,
+ "paid_at": null,
"voided_at": null
},
"subscription": null,
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.7.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.7.json
new file mode 100644
index 00000000000..21022fc5ed3
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.7.json
@@ -0,0 +1,323 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0005",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODk20200rl38pOcB?s=ap",
+ "id": "in_NORMALIZED00000000000004",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODk20200rl38pOcB/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000004",
+ "invoice_item": "ii_NORMALIZED00000000000004",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000004/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0004",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000004",
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ },
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0005",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3ODk20200aDNGZnIr?s=ap",
+ "id": "in_NORMALIZED00000000000003",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3ODk20200aDNGZnIr/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000003",
+ "invoice_item": "ii_NORMALIZED00000000000003",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000003/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0003",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000003",
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "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/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.8.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.8.json
new file mode 100644
index 00000000000..83fb2d240ef
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.8.json
@@ -0,0 +1,323 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0005",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODk30200BplrYMUT?s=ap",
+ "id": "in_NORMALIZED00000000000004",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODk30200BplrYMUT/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000004",
+ "invoice_item": "ii_NORMALIZED00000000000004",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000004/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0004",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000004",
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ },
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0005",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3ODk30200GIlceeGS?s=ap",
+ "id": "in_NORMALIZED00000000000003",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3ODk30200GIlceeGS/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000003",
+ "invoice_item": "ii_NORMALIZED00000000000003",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000003/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0003",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000003",
+ "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 Cloud Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "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/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.9.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.9.json
new file mode 100644
index 00000000000..e39960ab725
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.list.9.json
@@ -0,0 +1,6 @@
+{
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.1.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.1.json
index 70810b6edd2..e53335ca771 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.1.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.1.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcjd0Z3owZmIxMklIOFhBbFdVMFQxTVlZMmZWLDkwNzk3MjIx0200y4u4ThYo?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zVVdNMzhmUzNQODk3WGhuV09uVmh3bXNNbHhwLDkxOTg3ODU50200B7vRVb22?s=ap",
"id": "in_NORMALIZED00000000000005",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvcjd0Z3owZmIxMklIOFhBbFdVMFQxTVlZMmZWLDkwNzk3MjIx0200y4u4ThYo/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zVVdNMzhmUzNQODk3WGhuV09uVmh3bXNNbHhwLDkxOTg3ODU50200B7vRVb22/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.2.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.2.json
index 2f7bf65b505..0202cfc1aed 100644
--- a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.2.json
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.pay.2.json
@@ -40,9 +40,9 @@
"ending_balance": 0,
"footer": null,
"from_invoice": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvd0N3MUpXS1ZXMGdLelhBRkM0cU82ODU4NWp4LDkwNzk3MjIy0200yzEhcBwo?s=ap",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3ODYw020057F5Q2QL?s=ap",
"id": "in_NORMALIZED00000000000006",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QMWNvd0N3MUpXS1ZXMGdLelhBRkM0cU82ODU4NWp4LDkwNzk3MjIy0200yzEhcBwo/pdf?s=ap",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zNzN1WjB2TU4wcE00ZHdZT2pCQ0RUcm95a0FqLDkxOTg3ODYw020057F5Q2QL/pdf?s=ap",
"last_finalization_error": null,
"latest_revision": null,
"lines": {
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.1.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.1.json
new file mode 100644
index 00000000000..783743d1a8c
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.1.json
@@ -0,0 +1,158 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0002",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODkz020008ebm9bb?s=ap",
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zS1BrN3RuTEZpYm50bDJ6c3pwMU9TdmdTWEk5LDkxOTg3ODkz020008ebm9bb/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "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 Cloud Standard",
+ "status": "void",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": 1000000000
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.2.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.2.json
new file mode 100644
index 00000000000..5d6b98d7b95
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.2.json
@@ -0,0 +1,158 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0005",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODk40200vU3egTk9?s=ap",
+ "id": "in_NORMALIZED00000000000004",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zemtlY0VrY1lwQjV0MnVYejg3ejZGNnBLUVlrLDkxOTg3ODk40200vU3egTk9/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000004",
+ "invoice_item": "ii_NORMALIZED00000000000004",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000004/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0004",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000004",
+ "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 Cloud Standard",
+ "status": "void",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": 1000000000
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+}
diff --git a/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.3.json b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.3.json
new file mode 100644
index 00000000000..f76701175c2
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/downgrade_small_realms_behind_on_payments_as_needed--Invoice.void_invoice.3.json
@@ -0,0 +1,158 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 10000,
+ "amount_paid": 0,
+ "amount_remaining": 10000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0005",
+ "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": 1000000000,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3OTAy0200hvCHy51i?s=ap",
+ "id": "in_NORMALIZED00000000000003",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01a3dERVFhcm9xRGpzLF9QNm1zbmVJUWhldjM5ajJMY21wbWRqNUJ1ZFlmWE9OLDkxOTg3OTAy0200hvCHy51i/pdf?s=ap",
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 10000,
+ "amount_excluding_tax": 10000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000003",
+ "invoice_item": "ii_NORMALIZED00000000000003",
+ "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": 10000,
+ "unit_amount_decimal": "10000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "10000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000003/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0003",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED00000000000003",
+ "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 Cloud Standard",
+ "status": "void",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": 1000000000
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 10000,
+ "subtotal_excluding_tax": 10000,
+ "tax": null,
+ "test_clock": null,
+ "total": 10000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 10000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+}
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index cc2f35fb161..b698987aea3 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -54,6 +54,7 @@ from corporate.lib.stripe import (
catch_stripe_errors,
compute_plan_parameters,
customer_has_credit_card_as_default_payment_method,
+ customer_has_last_n_invoices_open,
do_change_remote_server_plan_type,
do_deactivate_remote_server,
downgrade_small_realms_behind_on_payments_as_needed,
@@ -72,7 +73,6 @@ from corporate.lib.stripe import (
update_license_ledger_for_automanaged_plan,
update_license_ledger_for_manual_plan,
update_license_ledger_if_needed,
- void_all_open_invoices,
)
from corporate.lib.support import get_discount_for_realm, switch_realm_from_standard_to_plus_plan
from corporate.models import (
@@ -3610,7 +3610,10 @@ class StripeTest(StripeTestCase):
iago = self.example_user("iago")
king = self.lear_user("king")
- self.assertEqual(void_all_open_invoices(iago.realm), 0)
+ voided_invoice_count = RealmBillingSession(
+ user=None, realm=iago.realm
+ ).void_all_open_invoices()
+ self.assertEqual(voided_invoice_count, 0)
zulip_customer = RealmBillingSession(iago).update_or_create_stripe_customer()
lear_customer = RealmBillingSession(king).update_or_create_stripe_customer()
@@ -3651,7 +3654,10 @@ class StripeTest(StripeTestCase):
)
stripe.Invoice.finalize_invoice(stripe_invoice)
- self.assertEqual(void_all_open_invoices(iago.realm), 1)
+ voided_invoice_count = RealmBillingSession(
+ user=None, realm=iago.realm
+ ).void_all_open_invoices()
+ self.assertEqual(voided_invoice_count, 1)
invoices = stripe.Invoice.list(customer=zulip_customer.stripe_customer_id)
self.assert_length(invoices, 1)
for invoice in invoices:
@@ -3660,11 +3666,17 @@ class StripeTest(StripeTestCase):
lear_stripe_customer_id = lear_customer.stripe_customer_id
lear_customer.stripe_customer_id = None
lear_customer.save(update_fields=["stripe_customer_id"])
- self.assertEqual(void_all_open_invoices(king.realm), 0)
+ voided_invoice_count = RealmBillingSession(
+ user=None, realm=king.realm
+ ).void_all_open_invoices()
+ self.assertEqual(voided_invoice_count, 0)
lear_customer.stripe_customer_id = lear_stripe_customer_id
lear_customer.save(update_fields=["stripe_customer_id"])
- self.assertEqual(void_all_open_invoices(king.realm), 1)
+ voided_invoice_count = RealmBillingSession(
+ user=None, realm=king.realm
+ ).void_all_open_invoices()
+ self.assertEqual(voided_invoice_count, 1)
invoices = stripe.Invoice.list(customer=lear_customer.stripe_customer_id)
self.assert_length(invoices, 1)
for invoice in invoices:
@@ -3740,57 +3752,64 @@ class StripeTest(StripeTestCase):
expected_plan_type: int
plan: Optional[CustomerPlan]
expected_plan_status: Optional[int]
- void_all_open_invoices_mock_called: bool
+ expected_invoice_count: int
email_expected_to_be_sent: bool
rows: List[Row] = []
+ # no stripe customer ID (excluded from query)
realm, _, _ = create_realm(
users_to_create=1, create_stripe_customer=False, create_plan=False
)
- # To create local Customer object but no Stripe customer.
billing_session = RealmBillingSession(
user=self.example_user("iago"), realm=realm, support_session=True
)
billing_session.attach_discount_to_customer(Decimal(20))
- rows.append(Row(realm, Realm.PLAN_TYPE_SELF_HOSTED, None, None, False, False))
+ rows.append(Row(realm, Realm.PLAN_TYPE_SELF_HOSTED, None, None, 0, False))
+ # no active paid plan or invoices (no action)
realm, _, _ = create_realm(
users_to_create=1, create_stripe_customer=True, create_plan=False
)
- rows.append(Row(realm, Realm.PLAN_TYPE_SELF_HOSTED, None, None, False, False))
+ rows.append(Row(realm, Realm.PLAN_TYPE_SELF_HOSTED, None, None, 0, False))
+ # no active plan, one unpaid invoice (will be voided, no downgrade or email)
realm, _, _ = create_realm(
users_to_create=1, create_stripe_customer=True, create_plan=False, num_invoices=1
)
- rows.append(Row(realm, Realm.PLAN_TYPE_SELF_HOSTED, None, None, True, False))
+ rows.append(Row(realm, Realm.PLAN_TYPE_SELF_HOSTED, None, None, 0, False))
+ # active plan, no invoices (no action)
realm, plan, _ = create_realm(
users_to_create=1, create_stripe_customer=True, create_plan=True
)
- rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, False, False))
+ rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, 0, False))
+ # active plan, only one unpaid invoice (not downgraded or voided)
realm, plan, _ = create_realm(
users_to_create=1, create_stripe_customer=True, create_plan=True, num_invoices=1
)
- rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, False, False))
+ rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, 1, False))
+ # active plan, two unpaid invoices (will be downgraded, voided and emailed)
realm, plan, _ = create_realm(
users_to_create=3, create_stripe_customer=True, create_plan=True, num_invoices=2
)
- rows.append(Row(realm, Realm.PLAN_TYPE_LIMITED, plan, CustomerPlan.ENDED, True, True))
+ rows.append(Row(realm, Realm.PLAN_TYPE_LIMITED, plan, CustomerPlan.ENDED, 0, True))
+ # active plan, two paid invoices (not downgraded)
realm, plan, invoices = create_realm(
users_to_create=1, create_stripe_customer=True, create_plan=True, num_invoices=2
)
for invoice in invoices:
stripe.Invoice.pay(invoice, paid_out_of_band=True)
- rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, False, False))
+ rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, 0, False))
+ # not a small realm, two unpaid invoices (not downgraded or voided)
realm, plan, _ = create_realm(
users_to_create=20, create_stripe_customer=True, create_plan=True, num_invoices=2
)
- rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, False, False))
+ rows.append(Row(realm, Realm.PLAN_TYPE_STANDARD, plan, CustomerPlan.ACTIVE, 2, False))
# Customer objects without a realm should be excluded from query.
remote_server = RemoteZulipServer.objects.create(
@@ -3801,8 +3820,7 @@ class StripeTest(StripeTestCase):
)
Customer.objects.create(remote_server=remote_server, stripe_customer_id="cus_xxx")
- with patch("corporate.lib.stripe.void_all_open_invoices") as void_all_open_invoices_mock:
- downgrade_small_realms_behind_on_payments_as_needed()
+ downgrade_small_realms_behind_on_payments_as_needed()
from django.core.mail import outbox
@@ -3812,15 +3830,12 @@ class StripeTest(StripeTestCase):
if row.plan is not None:
row.plan.refresh_from_db()
self.assertEqual(row.plan.status, row.expected_plan_status)
- if row.void_all_open_invoices_mock_called:
- void_all_open_invoices_mock.assert_any_call(row.realm)
- else:
- try:
- void_all_open_invoices_mock.assert_any_call(row.realm)
- except AssertionError:
- pass
- else: # nocoverage
- raise AssertionError("void_all_open_invoices_mock should not be called")
+ customer = get_customer_by_realm(row.realm)
+ if customer is not None and customer.stripe_customer_id is not None:
+ open_invoices = customer_has_last_n_invoices_open(
+ customer, row.expected_invoice_count
+ )
+ self.assertTrue(open_invoices)
email_found = False
for email in outbox: