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: Make initial upgrade license checks more robust.

Lauryn Menard0147578de631
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 628a3b98e1d..884e0579ee3 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -1704,6 +1704,15 @@ class BillingSession(ABC):
)
return self.create_stripe_invoice_and_charge(updated_metadata)
+ def stale_seat_count_check(self, request_seat_count: int, tier: int) -> int:
+ current_seat_count = self.current_count_for_billed_licenses()
+ minimum_seat_count = self.min_licenses_for_plan(tier)
+ if request_seat_count == minimum_seat_count and current_seat_count < minimum_seat_count:
+ # Continue to use the minimum licenses for the plan tier.
+ return request_seat_count
+ # Otherwise, use a current count for billed licenses.
+ return current_seat_count
+
def ensure_current_plan_is_upgradable(self, customer: Customer, new_plan_tier: int) -> None:
# Upgrade for customers with an existing plan is only supported for remote realm / server right now.
if isinstance(self, RealmBillingSession):
@@ -1785,13 +1794,18 @@ class BillingSession(ABC):
# TODO: The correctness of this relies on user creation, deactivation, etc being
# in a transaction.atomic() with the relevant RealmAuditLog entries
with transaction.atomic():
- # billed_licenses can be greater than licenses if users are added between the start of
- # this function (process_initial_upgrade) and now
+ # We get the current license count here in case the number of billable
+ # licenses has changed since the upgrade process began.
current_licenses_count = self.get_billable_licenses_for_customer(
customer, plan_tier, licenses
)
- # In case user wants more licenses for the plan. (manual license management)
- billed_licenses = max(current_licenses_count, licenses)
+ if current_licenses_count != licenses and not automanage_licenses:
+ # With manual license management, the user may want to purchase more
+ # licenses than are currently in use.
+ billable_licenses = max(current_licenses_count, licenses)
+ else:
+ billable_licenses = current_licenses_count
+
plan_params = {
"automanage_licenses": automanage_licenses,
"charge_automatically": charge_automatically,
@@ -1862,7 +1876,7 @@ class BillingSession(ABC):
)
# Update license_at_next_renewal as per new plan.
assert last_ledger_entry is not None
- last_ledger_entry.licenses_at_next_renewal = billed_licenses
+ last_ledger_entry.licenses_at_next_renewal = billable_licenses
last_ledger_entry.save(update_fields=["licenses_at_next_renewal"])
remote_server_legacy_plan.status = CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END
remote_server_legacy_plan.save(update_fields=["status"])
@@ -1910,21 +1924,47 @@ class BillingSession(ABC):
# TODO: Do a check for max licenses for fixed price plans here after we add that.
if (
stripe_invoice_paid
- and billed_licenses != licenses
+ and billable_licenses != licenses
and not customer.exempt_from_license_number_check
and not fixed_price_plan_offer
):
- # Customer paid for less licenses than they have.
- # We need to create a new ledger entry to track the additional licenses.
- LicenseLedger.objects.create(
- plan=plan,
- is_renewal=False,
- event_time=event_time,
- licenses=billed_licenses,
- licenses_at_next_renewal=billed_licenses,
- )
- # Creates due today invoice for additional licenses.
- self.invoice_plan(plan, event_time)
+ # Billable licenses in use do not match what was paid/invoiced by customer.
+ if billable_licenses > licenses:
+ # Customer paid for less licenses than they have in use.
+ # We need to create a new ledger entry to track the additional licenses.
+ LicenseLedger.objects.create(
+ plan=plan,
+ is_renewal=False,
+ event_time=event_time,
+ licenses=billable_licenses,
+ licenses_at_next_renewal=billable_licenses,
+ )
+ # Creates due today invoice for additional licenses.
+ self.invoice_plan(plan, event_time)
+ else:
+ # Customer paid for more licenses than they have in use.
+ # We need to create a new ledger entry to track the reduced renewal licenses.
+ LicenseLedger.objects.create(
+ plan=plan,
+ is_renewal=False,
+ event_time=event_time,
+ licenses=licenses,
+ licenses_at_next_renewal=billable_licenses,
+ )
+ # Send internal billing notice about license discrepancy.
+ context = {
+ "billing_entity": self.billing_entity_display_name,
+ "support_url": self.support_url(),
+ "paid_licenses": licenses,
+ "current_licenses": billable_licenses,
+ "notice_reason": "license_discrepancy",
+ }
+ send_email(
+ "zerver/emails/internal_billing_notice",
+ to_emails=[BILLING_SUPPORT_EMAIL],
+ from_address=FromAddress.tokenized_no_reply_address(),
+ context=context,
+ )
if not stripe_invoice_paid and not (
free_trial or should_schedule_upgrade_for_legacy_remote_server
@@ -1936,7 +1976,7 @@ class BillingSession(ABC):
customer,
price_per_license=price_per_license,
fixed_price=plan.fixed_price,
- licenses=billed_licenses,
+ licenses=billable_licenses,
plan_tier=plan.tier,
billing_schedule=billing_schedule,
charge_automatically=False,
@@ -1953,7 +1993,7 @@ class BillingSession(ABC):
# fails to pay the invoice before expiration, we downgrade the customer.
self.generate_stripe_invoice(
plan_tier,
- licenses=billed_licenses,
+ licenses=billable_licenses,
license_management="automatic" if automanage_licenses else "manual",
billing_schedule=billing_schedule,
billing_modality="send_invoice",
@@ -1968,14 +2008,20 @@ class BillingSession(ABC):
self.ensure_current_plan_is_upgradable(customer, upgrade_request.tier)
billing_modality = upgrade_request.billing_modality
schedule = upgrade_request.schedule
+
license_management = upgrade_request.license_management
- licenses = upgrade_request.licenses
+ if billing_modality == "send_invoice":
+ license_management = "manual"
- seat_count = unsign_seat_count(upgrade_request.signed_seat_count, upgrade_request.salt)
+ licenses = upgrade_request.licenses
+ request_seat_count = unsign_seat_count(
+ upgrade_request.signed_seat_count, upgrade_request.salt
+ )
+ # For automated license management, we check for changes to the
+ # billable licenses count made after the billing portal was loaded.
+ seat_count = self.stale_seat_count_check(request_seat_count, upgrade_request.tier)
if billing_modality == "charge_automatically" and license_management == "automatic":
licenses = seat_count
- if billing_modality == "send_invoice":
- license_management = "manual"
exempt_from_license_number_check = (
customer is not None and customer.exempt_from_license_number_check
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json
new file mode 100644
index 00000000000..edc79871f77
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json
@@ -0,0 +1,120 @@
+{
+ "data": [
+ {
+ "amount": 48000,
+ "amount_captured": 48000,
+ "amount_refunded": 0,
+ "application": null,
+ "application_fee": null,
+ "application_fee_amount": null,
+ "balance_transaction": "txn_NORMALIZED",
+ "billing_details": {
+ "address": {
+ "city": "San Francisco",
+ "country": "US",
+ "line1": "123 Main St",
+ "line2": null,
+ "postal_code": "94105",
+ "state": "CA"
+ },
+ "email": null,
+ "name": "John Doe",
+ "phone": null
+ },
+ "calculated_statement_descriptor": "ZULIP CLOUD STANDARD",
+ "captured": true,
+ "created": 1000000000,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED",
+ "description": "Payment for Invoice",
+ "destination": null,
+ "dispute": null,
+ "disputed": false,
+ "failure_balance_transaction": null,
+ "failure_code": null,
+ "failure_message": null,
+ "fraud_details": {},
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json",
+ "invoice": "in_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "charge",
+ "on_behalf_of": null,
+ "order": null,
+ "outcome": {
+ "network_status": "approved_by_network",
+ "reason": null,
+ "risk_level": "normal",
+ "risk_score": 0,
+ "seller_message": "Payment complete.",
+ "type": "authorized"
+ },
+ "paid": true,
+ "payment_intent": "pi_NORMALIZED",
+ "payment_method": "pm_NORMALIZED",
+ "payment_method_details": {
+ "card": {
+ "amount_authorized": 48000,
+ "authorization_code": null,
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": "pass",
+ "address_postal_code_check": "pass",
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 9,
+ "exp_year": 2025,
+ "extended_authorization": {
+ "status": "disabled"
+ },
+ "fingerprint": "NORMALIZED",
+ "funding": "credit",
+ "incremental_authorization": {
+ "status": "unavailable"
+ },
+ "installments": null,
+ "last4": "4242",
+ "mandate": null,
+ "multicapture": {
+ "status": "unavailable"
+ },
+ "network": "visa",
+ "network_token": {
+ "used": false
+ },
+ "overcapture": {
+ "maximum_amount_capturable": 48000,
+ "status": "unavailable"
+ },
+ "three_d_secure": null,
+ "wallet": null
+ },
+ "type": "card"
+ },
+ "receipt_email": "[email protected]",
+ "receipt_number": null,
+ "receipt_url": "https://pay.stripe.com/receipts/invoices/NORMALIZED?s=ap",
+ "refunded": false,
+ "refunds": {
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "total_count": 0,
+ "url": "/v1/charges/upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json/refunds"
+ },
+ "review": null,
+ "shipping": null,
+ "source": null,
+ "source_transfer": null,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "statement_descriptor_suffix": null,
+ "status": "succeeded",
+ "transfer_data": null,
+ "transfer_group": null
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/charges"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json
new file mode 100644
index 00000000000..c1b291d4bb2
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json
@@ -0,0 +1,33 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip (Zulip Dev)",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "invoice_prefix": "NORMALIZED",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": null,
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "realm_id": "1",
+ "realm_str": "zulip"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.modify.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.modify.1.json
new file mode 100644
index 00000000000..33742df37a6
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.modify.1.json
@@ -0,0 +1,33 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip (Zulip Dev)",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "invoice_prefix": "NORMALIZED",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": "pm_NORMALIZED",
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "realm_id": "1",
+ "realm_str": "zulip"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.1.json
new file mode 100644
index 00000000000..03644507538
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.1.json
@@ -0,0 +1,81 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip (Zulip Dev)",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "invoice_prefix": "NORMALIZED",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "allow_redisplay": "unspecified",
+ "billing_details": {
+ "address": {
+ "city": "San Francisco",
+ "country": "US",
+ "line1": "123 Main St",
+ "line2": null,
+ "postal_code": "94105",
+ "state": "CA"
+ },
+ "email": null,
+ "name": "John Doe",
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": "pass",
+ "address_postal_code_check": "pass",
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "display_brand": "visa",
+ "exp_month": 9,
+ "exp_year": 2025,
+ "fingerprint": "NORMALIZED",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1000000000,
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.1.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "realm_id": "1",
+ "realm_str": "zulip"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.2.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.2.json
new file mode 100644
index 00000000000..03644507538
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.2.json
@@ -0,0 +1,81 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip (Zulip Dev)",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "invoice_prefix": "NORMALIZED",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": {
+ "allow_redisplay": "unspecified",
+ "billing_details": {
+ "address": {
+ "city": "San Francisco",
+ "country": "US",
+ "line1": "123 Main St",
+ "line2": null,
+ "postal_code": "94105",
+ "state": "CA"
+ },
+ "email": null,
+ "name": "John Doe",
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": "pass",
+ "address_postal_code_check": "pass",
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "display_brand": "visa",
+ "exp_month": 9,
+ "exp_year": 2025,
+ "fingerprint": "NORMALIZED",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1000000000,
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.1.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+ },
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "realm_id": "1",
+ "realm_str": "zulip"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.1.json
new file mode 100644
index 00000000000..99118709f53
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.1.json
@@ -0,0 +1,60 @@
+{
+ "data": [
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip (Zulip Dev)",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "invoice_prefix": "NORMALIZED",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": "pm_NORMALIZED",
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "realm_id": "1",
+ "realm_str": "zulip"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+ },
+ "previous_attributes": {
+ "invoice_settings": {
+ "default_payment_method": null
+ }
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.1.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.1.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "customer.updated"
+ }
+ ],
+ "has_more": true,
+ "object": "list",
+ "url": "/v1/events"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json
new file mode 100644
index 00000000000..257ab29f173
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json
@@ -0,0 +1,1101 @@
+{
+ "data": [
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "amount": 48000,
+ "amount_capturable": 0,
+ "amount_details": {
+ "tip": {}
+ },
+ "amount_received": 48000,
+ "application": null,
+ "application_fee_amount": null,
+ "automatic_payment_methods": null,
+ "canceled_at": null,
+ "cancellation_reason": null,
+ "capture_method": "automatic",
+ "charges": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_captured": 48000,
+ "amount_refunded": 0,
+ "application": null,
+ "application_fee": null,
+ "application_fee_amount": null,
+ "balance_transaction": "txn_NORMALIZED",
+ "billing_details": {
+ "address": {
+ "city": "San Francisco",
+ "country": "US",
+ "line1": "123 Main St",
+ "line2": null,
+ "postal_code": "94105",
+ "state": "CA"
+ },
+ "email": null,
+ "name": "John Doe",
+ "phone": null
+ },
+ "calculated_statement_descriptor": "ZULIP CLOUD STANDARD",
+ "captured": true,
+ "created": 1000000000,
+ "currency": "usd",
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "description": "Payment for Invoice",
+ "destination": null,
+ "dispute": null,
+ "disputed": false,
+ "failure_balance_transaction": null,
+ "failure_code": null,
+ "failure_message": null,
+ "fraud_details": {},
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "charge",
+ "on_behalf_of": null,
+ "order": null,
+ "outcome": {
+ "network_status": "approved_by_network",
+ "reason": null,
+ "risk_level": "normal",
+ "risk_score": 0,
+ "seller_message": "Payment complete.",
+ "type": "authorized"
+ },
+ "paid": true,
+ "payment_intent": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "payment_method": "pm_NORMALIZED",
+ "payment_method_details": {
+ "card": {
+ "amount_authorized": 48000,
+ "authorization_code": null,
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": "pass",
+ "address_postal_code_check": "pass",
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 9,
+ "exp_year": 2025,
+ "extended_authorization": {
+ "status": "disabled"
+ },
+ "fingerprint": "NORMALIZED",
+ "funding": "credit",
+ "incremental_authorization": {
+ "status": "unavailable"
+ },
+ "installments": null,
+ "last4": "4242",
+ "mandate": null,
+ "multicapture": {
+ "status": "unavailable"
+ },
+ "network": "visa",
+ "network_token": {
+ "used": false
+ },
+ "overcapture": {
+ "maximum_amount_capturable": 48000,
+ "status": "unavailable"
+ },
+ "three_d_secure": null,
+ "wallet": null
+ },
+ "type": "card"
+ },
+ "receipt_email": "[email protected]",
+ "receipt_number": null,
+ "receipt_url": "https://pay.stripe.com/receipts/invoices/NORMALIZED?s=ap",
+ "refunded": false,
+ "refunds": {
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "total_count": 0,
+ "url": "/v1/charges/upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json/refunds"
+ },
+ "review": null,
+ "shipping": null,
+ "source": null,
+ "source_transfer": null,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "statement_descriptor_suffix": null,
+ "status": "succeeded",
+ "transfer_data": null,
+ "transfer_group": null
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/charges?payment_intent=upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json"
+ },
+ "client_secret": "NORMALIZED",
+ "confirmation_method": "automatic",
+ "created": 1000000000,
+ "currency": "usd",
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "description": "Payment for Invoice",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "last_payment_error": null,
+ "latest_charge": "upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json",
+ "livemode": false,
+ "metadata": {},
+ "next_action": null,
+ "object": "payment_intent",
+ "on_behalf_of": null,
+ "payment_method": "pm_NORMALIZED",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "installments": null,
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ },
+ "cashapp": {}
+ },
+ "payment_method_types": [
+ "card",
+ "cashapp"
+ ],
+ "processing": null,
+ "receipt_email": "[email protected]",
+ "review": null,
+ "setup_future_usage": null,
+ "shipping": null,
+ "source": null,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "statement_descriptor_suffix": null,
+ "status": "succeeded",
+ "transfer_data": null,
+ "transfer_group": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 2,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "payment_intent.succeeded"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "amount": 48000,
+ "amount_captured": 48000,
+ "amount_refunded": 0,
+ "application": null,
+ "application_fee": null,
+ "application_fee_amount": null,
+ "balance_transaction": "txn_NORMALIZED",
+ "billing_details": {
+ "address": {
+ "city": "San Francisco",
+ "country": "US",
+ "line1": "123 Main St",
+ "line2": null,
+ "postal_code": "94105",
+ "state": "CA"
+ },
+ "email": null,
+ "name": "John Doe",
+ "phone": null
+ },
+ "calculated_statement_descriptor": "ZULIP CLOUD STANDARD",
+ "captured": true,
+ "created": 1000000000,
+ "currency": "usd",
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "description": "Payment for Invoice",
+ "destination": null,
+ "dispute": null,
+ "disputed": false,
+ "failure_balance_transaction": null,
+ "failure_code": null,
+ "failure_message": null,
+ "fraud_details": {},
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "charge",
+ "on_behalf_of": null,
+ "order": null,
+ "outcome": {
+ "network_status": "approved_by_network",
+ "reason": null,
+ "risk_level": "normal",
+ "risk_score": 0,
+ "seller_message": "Payment complete.",
+ "type": "authorized"
+ },
+ "paid": true,
+ "payment_intent": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "payment_method": "pm_NORMALIZED",
+ "payment_method_details": {
+ "card": {
+ "amount_authorized": 48000,
+ "authorization_code": null,
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": "pass",
+ "address_postal_code_check": "pass",
+ "cvc_check": "pass"
+ },
+ "country": "US",
+ "exp_month": 9,
+ "exp_year": 2025,
+ "extended_authorization": {
+ "status": "disabled"
+ },
+ "fingerprint": "NORMALIZED",
+ "funding": "credit",
+ "incremental_authorization": {
+ "status": "unavailable"
+ },
+ "installments": null,
+ "last4": "4242",
+ "mandate": null,
+ "multicapture": {
+ "status": "unavailable"
+ },
+ "network": "visa",
+ "network_token": {
+ "used": false
+ },
+ "overcapture": {
+ "maximum_amount_capturable": 48000,
+ "status": "unavailable"
+ },
+ "three_d_secure": null,
+ "wallet": null
+ },
+ "type": "card"
+ },
+ "receipt_email": "[email protected]",
+ "receipt_number": null,
+ "receipt_url": "https://pay.stripe.com/receipts/invoices/NORMALIZED?s=ap",
+ "refunded": false,
+ "refunds": {
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "total_count": 0,
+ "url": "/v1/charges/upgrade_by_card_with_outdated_lower_seat_count--Charge.list.1.json/refunds"
+ },
+ "review": null,
+ "shipping": null,
+ "source": null,
+ "source_transfer": null,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "statement_descriptor_suffix": null,
+ "status": "succeeded",
+ "transfer_data": null,
+ "transfer_group": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 2,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "charge.succeeded"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 0,
+ "amount_remaining": 48000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "invoice.finalized"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 0,
+ "amount_remaining": 48000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+ },
+ "previous_attributes": {
+ "effective_at": null,
+ "ending_balance": null,
+ "hosted_invoice_url": null,
+ "invoice_pdf": null,
+ "number": null,
+ "payment_intent": null,
+ "rendering": {
+ "pdf": {
+ "page_size": "auto"
+ }
+ },
+ "status": "draft",
+ "status_transitions": {
+ "finalized_at": null
+ }
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "invoice.updated"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "amount": 48000,
+ "amount_capturable": 0,
+ "amount_details": {
+ "tip": {}
+ },
+ "amount_received": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "automatic_payment_methods": null,
+ "canceled_at": null,
+ "cancellation_reason": null,
+ "capture_method": "automatic",
+ "charges": {
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "total_count": 0,
+ "url": "/v1/charges?payment_intent=upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json"
+ },
+ "client_secret": "NORMALIZED",
+ "confirmation_method": "automatic",
+ "created": 1000000000,
+ "currency": "usd",
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "description": "Payment for Invoice",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "last_payment_error": null,
+ "latest_charge": null,
+ "livemode": false,
+ "metadata": {},
+ "next_action": null,
+ "object": "payment_intent",
+ "on_behalf_of": null,
+ "payment_method": null,
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "installments": null,
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ },
+ "cashapp": {}
+ },
+ "payment_method_types": [
+ "card",
+ "cashapp"
+ ],
+ "processing": null,
+ "receipt_email": "[email protected]",
+ "review": null,
+ "setup_future_usage": null,
+ "shipping": null,
+ "source": null,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "statement_descriptor_suffix": null,
+ "status": "requires_payment_method",
+ "transfer_data": null,
+ "transfer_group": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "payment_intent.created"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 0,
+ "amount_remaining": 48000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": null,
+ "ending_balance": null,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": null,
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": null,
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": null,
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "auto"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "status": "draft",
+ "status_transitions": {
+ "finalized_at": null,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "invoice.created"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "amount": 48000,
+ "currency": "usd",
+ "customer": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "date": 1000000000,
+ "description": "Zulip Cloud Standard",
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_rates": [],
+ "test_clock": null,
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "invoiceitem.created"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": "usd",
+ "default_currency": "usd",
+ "default_source": null,
+ "delinquent": false,
+ "description": "zulip (Zulip Dev)",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.create.1.json",
+ "invoice_prefix": "NORMALIZED",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": "pm_NORMALIZED",
+ "footer": null,
+ "rendering_options": null
+ },
+ "livemode": false,
+ "metadata": {
+ "realm_id": "1",
+ "realm_str": "zulip"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none",
+ "test_clock": null
+ },
+ "previous_attributes": {
+ "currency": null,
+ "default_currency": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "customer.updated"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/events"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.3.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.3.json
new file mode 100644
index 00000000000..a60c6229bfd
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.3.json
@@ -0,0 +1,586 @@
+{
+ "data": [
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 48000,
+ "amount_remaining": 0,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 1,
+ "attempted": true,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": "ch_NORMALIZED",
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "ii_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.3.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "invoice.payment_succeeded"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 48000,
+ "amount_remaining": 0,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 1,
+ "attempted": true,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": "ch_NORMALIZED",
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "ii_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.3.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "invoice.paid"
+ },
+ {
+ "api_version": "2020-08-27",
+ "created": 1000000000,
+ "data": {
+ "object": {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 48000,
+ "amount_remaining": 0,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 1,
+ "attempted": true,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": "ch_NORMALIZED",
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "ii_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+ },
+ "previous_attributes": {
+ "amount_paid": 0,
+ "amount_remaining": 48000,
+ "attempt_count": 0,
+ "attempted": false,
+ "charge": null,
+ "paid": false,
+ "status": "open",
+ "status_transitions": {
+ "paid_at": null
+ }
+ }
+ },
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.3.json",
+ "livemode": false,
+ "object": "event",
+ "pending_webhooks": 0,
+ "request": {
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "idempotency_key": "00000000-0000-0000-0000-000000000000"
+ },
+ "type": "invoice.updated"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/events"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.4.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.4.json
new file mode 100644
index 00000000000..6d922067afe
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Event.list.4.json
@@ -0,0 +1,6 @@
+{
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/events"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.create.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.create.1.json
new file mode 100644
index 00000000000..6af2e2ed136
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.create.1.json
@@ -0,0 +1,174 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 0,
+ "amount_remaining": 48000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": null,
+ "ending_balance": null,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": null,
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "ii_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": null,
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": null,
+ "payment_settings": {
+ "default_mandate": null,
+ "payment_method_options": null,
+ "payment_method_types": null
+ },
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "quote": null,
+ "receipt_number": null,
+ "rendering": {
+ "amount_tax_display": null,
+ "pdf": {
+ "page_size": "auto"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "rendering_options": null,
+ "shipping_cost": null,
+ "shipping_details": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Cloud Standard",
+ "status": "draft",
+ "status_transitions": {
+ "finalized_at": null,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subscription_details": {
+ "metadata": null
+ },
+ "subtotal": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.finalize_invoice.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.finalize_invoice.1.json
new file mode 100644
index 00000000000..df1d655abb0
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.finalize_invoice.1.json
@@ -0,0 +1,174 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 0,
+ "amount_remaining": 48000,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "ii_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.list.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.list.1.json
new file mode 100644
index 00000000000..e39960ab725
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.list.1.json
@@ -0,0 +1,6 @@
+{
+ "data": [],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/invoices"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.list.2.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.list.2.json
new file mode 100644
index 00000000000..ee6407444a3
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.list.2.json
@@ -0,0 +1,181 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 48000,
+ "amount_remaining": 0,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 1,
+ "attempted": true,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": "ch_NORMALIZED",
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "ii_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "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/upgrade_by_card_with_outdated_lower_seat_count--Invoice.pay.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.pay.1.json
new file mode 100644
index 00000000000..6e5ae3d46c7
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--Invoice.pay.1.json
@@ -0,0 +1,174 @@
+{
+ "account_country": "US",
+ "account_name": "Kandra Labs, Inc.",
+ "account_tax_ids": null,
+ "amount_due": 48000,
+ "amount_paid": 48000,
+ "amount_remaining": 0,
+ "amount_shipping": 0,
+ "application": null,
+ "application_fee_amount": null,
+ "attempt_count": 1,
+ "attempted": true,
+ "auto_advance": false,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "automatically_finalizes_at": null,
+ "billing_reason": "manual",
+ "charge": "ch_NORMALIZED",
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "effective_at": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "from_invoice": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED/test_NORMALIZED?s=ap",
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED/test_NORMALIZED/pdf?s=ap",
+ "issuer": {
+ "type": "self"
+ },
+ "last_finalization_error": null,
+ "latest_revision": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 48000,
+ "amount_excluding_tax": 48000,
+ "currency": "usd",
+ "description": "Zulip Cloud Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice_item": "ii_NORMALIZED",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "proration_details": {
+ "credited_items": null
+ },
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unit_amount_excluding_tax": "8000"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json/lines"
+ },
+ "livemode": false,
+ "metadata": {
+ "billing_schedule": "1",
+ "current_plan_id": "None",
+ "license_management": "automatic",
+ "licenses": "6",
+ "on_free_trial": "False",
+ "plan_tier": "1",
+ "user_id": "10"
+ },
+ "next_payment_attempt": null,
+ "number": "NORMALIZED",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": true,
+ "paid_out_of_band": false,
+ "payment_intent": "pi_NORMALIZED",
+ "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"
+ },
+ "template": null,
+ "template_version": null
+ },
+ "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": 48000,
+ "subtotal_excluding_tax": 48000,
+ "tax": null,
+ "test_clock": null,
+ "total": 48000,
+ "total_discount_amounts": [],
+ "total_excluding_tax": 48000,
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--InvoiceItem.create.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--InvoiceItem.create.1.json
new file mode 100644
index 00000000000..e3d4a77d232
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--InvoiceItem.create.1.json
@@ -0,0 +1,47 @@
+{
+ "amount": 48000,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED",
+ "date": 1000000000,
+ "description": "Zulip Cloud Standard",
+ "discountable": false,
+ "discounts": [],
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_unit_amount": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Event.list.2.json",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_rates": [],
+ "test_clock": null,
+ "unit_amount": 8000,
+ "unit_amount_decimal": "8000"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--PaymentMethod.create.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--PaymentMethod.create.1.json
new file mode 100644
index 00000000000..396a6a9540f
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--PaymentMethod.create.1.json
@@ -0,0 +1,49 @@
+{
+ "allow_redisplay": "unspecified",
+ "billing_details": {
+ "address": {
+ "city": "San Francisco",
+ "country": "US",
+ "line1": "123 Main St",
+ "line2": null,
+ "postal_code": "94105",
+ "state": "CA"
+ },
+ "email": null,
+ "name": "John Doe",
+ "phone": null
+ },
+ "card": {
+ "brand": "visa",
+ "checks": {
+ "address_line1_check": "unchecked",
+ "address_postal_code_check": "unchecked",
+ "cvc_check": "unchecked"
+ },
+ "country": "US",
+ "display_brand": "visa",
+ "exp_month": 9,
+ "exp_year": 2025,
+ "fingerprint": "NORMALIZED",
+ "funding": "credit",
+ "generated_from": null,
+ "last4": "4242",
+ "networks": {
+ "available": [
+ "visa"
+ ],
+ "preferred": null
+ },
+ "three_d_secure_usage": {
+ "supported": true
+ },
+ "wallet": null
+ },
+ "created": 1000000000,
+ "customer": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--Customer.retrieve.1.json",
+ "livemode": false,
+ "metadata": {},
+ "object": "payment_method",
+ "type": "card"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.create.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.create.1.json
new file mode 100644
index 00000000000..5f0a76c3e57
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.create.1.json
@@ -0,0 +1,34 @@
+{
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "NORMALIZED",
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED",
+ "description": null,
+ "flow_directions": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.create.1.json",
+ "last_setup_error": null,
+ "latest_attempt": "setatt_NORMALIZED",
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": "pm_NORMALIZED",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "succeeded",
+ "usage": "off_session"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.list.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.list.1.json
new file mode 100644
index 00000000000..279313766d5
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.list.1.json
@@ -0,0 +1,41 @@
+{
+ "data": [
+ {
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "NORMALIZED",
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED",
+ "description": null,
+ "flow_directions": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.list.1.json",
+ "last_setup_error": null,
+ "latest_attempt": null,
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": null,
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "requires_payment_method",
+ "usage": "off_session"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/setup_intents"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.retrieve.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.retrieve.1.json
new file mode 100644
index 00000000000..5f0a76c3e57
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.retrieve.1.json
@@ -0,0 +1,34 @@
+{
+ "application": null,
+ "automatic_payment_methods": null,
+ "cancellation_reason": null,
+ "client_secret": "NORMALIZED",
+ "created": 1000000000,
+ "customer": "cus_NORMALIZED",
+ "description": null,
+ "flow_directions": null,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--SetupIntent.create.1.json",
+ "last_setup_error": null,
+ "latest_attempt": "setatt_NORMALIZED",
+ "livemode": false,
+ "mandate": null,
+ "metadata": {},
+ "next_action": null,
+ "object": "setup_intent",
+ "on_behalf_of": null,
+ "payment_method": "pm_NORMALIZED",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "mandate_options": null,
+ "network": null,
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "single_use_mandate": null,
+ "status": "succeeded",
+ "usage": "off_session"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.create.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.create.1.json
new file mode 100644
index 00000000000..aa65d268206
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.create.1.json
@@ -0,0 +1,80 @@
+{
+ "after_expiration": null,
+ "allow_promotion_codes": null,
+ "amount_subtotal": null,
+ "amount_total": null,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_address_collection": "required",
+ "cancel_url": "http://zulip.testserver/upgrade/?manual_license_management=false&tier=1",
+ "client_reference_id": null,
+ "client_secret": null,
+ "consent": null,
+ "consent_collection": null,
+ "created": 1000000000,
+ "currency": null,
+ "currency_conversion": null,
+ "custom_fields": [],
+ "custom_text": {
+ "after_submit": null,
+ "shipping_address": null,
+ "submit": null,
+ "terms_of_service_acceptance": null
+ },
+ "customer": "cus_NORMALIZED",
+ "customer_creation": null,
+ "customer_details": {
+ "address": null,
+ "email": "[email protected]",
+ "name": null,
+ "phone": null,
+ "tax_exempt": null,
+ "tax_ids": null
+ },
+ "customer_email": null,
+ "expires_at": 1000000000,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.create.1.json",
+ "invoice": null,
+ "invoice_creation": null,
+ "livemode": false,
+ "locale": null,
+ "metadata": {
+ "type": "card_update",
+ "user_id": "10"
+ },
+ "mode": "setup",
+ "object": "checkout.session",
+ "payment_intent": null,
+ "payment_link": null,
+ "payment_method_collection": "always",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "payment_status": "no_payment_required",
+ "phone_number_collection": {
+ "enabled": false
+ },
+ "recovered_from": null,
+ "saved_payment_method_options": null,
+ "setup_intent": "seti_NORMALIZED",
+ "shipping": null,
+ "shipping_address_collection": null,
+ "shipping_options": [],
+ "shipping_rate": null,
+ "status": "open",
+ "submit_type": null,
+ "subscription": null,
+ "success_url": "http://zulip.testserver/billing/event_status/?stripe_session_id={CHECKOUT_SESSION_ID}",
+ "total_details": null,
+ "ui_mode": "hosted",
+ "url": "https://checkout.stripe.com/c/pay/cs_test_NORMALIZED"
+}
diff --git a/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.list.1.json b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.list.1.json
new file mode 100644
index 00000000000..9916555c1c3
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.list.1.json
@@ -0,0 +1,87 @@
+{
+ "data": [
+ {
+ "after_expiration": null,
+ "allow_promotion_codes": null,
+ "amount_subtotal": null,
+ "amount_total": null,
+ "automatic_tax": {
+ "enabled": false,
+ "liability": null,
+ "status": null
+ },
+ "billing_address_collection": "required",
+ "cancel_url": "http://zulip.testserver/upgrade/?manual_license_management=false&tier=1",
+ "client_reference_id": null,
+ "client_secret": null,
+ "consent": null,
+ "consent_collection": null,
+ "created": 1000000000,
+ "currency": null,
+ "currency_conversion": null,
+ "custom_fields": [],
+ "custom_text": {
+ "after_submit": null,
+ "shipping_address": null,
+ "submit": null,
+ "terms_of_service_acceptance": null
+ },
+ "customer": "cus_NORMALIZED",
+ "customer_creation": null,
+ "customer_details": {
+ "address": null,
+ "email": "[email protected]",
+ "name": null,
+ "phone": null,
+ "tax_exempt": null,
+ "tax_ids": null
+ },
+ "customer_email": null,
+ "expires_at": 1000000000,
+ "id": "upgrade_by_card_with_outdated_lower_seat_count--checkout.Session.create.1.json",
+ "invoice": null,
+ "invoice_creation": null,
+ "livemode": false,
+ "locale": null,
+ "metadata": {
+ "type": "card_update",
+ "user_id": "10"
+ },
+ "mode": "setup",
+ "object": "checkout.session",
+ "payment_intent": null,
+ "payment_link": null,
+ "payment_method_collection": "always",
+ "payment_method_configuration_details": null,
+ "payment_method_options": {
+ "card": {
+ "request_three_d_secure": "automatic"
+ }
+ },
+ "payment_method_types": [
+ "card"
+ ],
+ "payment_status": "no_payment_required",
+ "phone_number_collection": {
+ "enabled": false
+ },
+ "recovered_from": null,
+ "saved_payment_method_options": null,
+ "setup_intent": "seti_NORMALIZED",
+ "shipping": null,
+ "shipping_address_collection": null,
+ "shipping_options": [],
+ "shipping_rate": null,
+ "status": "open",
+ "submit_type": null,
+ "subscription": null,
+ "success_url": "http://zulip.testserver/billing/event_status/?stripe_session_id={CHECKOUT_SESSION_ID}",
+ "total_details": null,
+ "ui_mode": "hosted",
+ "url": "https://checkout.stripe.com/c/pay/cs_test_NORMALIZED"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/checkout/sessions"
+}
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 6e1edf59ca3..9a7f5247724 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -1962,6 +1962,7 @@ class StripeTest(StripeTestCase):
def test_upgrade_by_card_with_outdated_seat_count(self, *mocks: Mock) -> None:
hamlet = self.example_user("hamlet")
self.login_user(hamlet)
+ # Higher than original seat count
new_seat_count = 23
initial_upgrade_request = InitialUpgradeRequest(
manual_license_management=False,
@@ -1972,8 +1973,12 @@ class StripeTest(StripeTestCase):
_, context_when_upgrade_page_is_rendered = billing_session.get_initial_upgrade_context(
initial_upgrade_request
)
- # Change the seat count while the user is going through the upgrade flow
+ # Change the seat count in upgrade flow: after do_upgrade, during process_initial_upgrade
with (
+ patch(
+ "corporate.lib.stripe.BillingSession.stale_seat_count_check",
+ return_value=self.seat_count,
+ ),
patch("corporate.lib.stripe.get_latest_seat_count", return_value=new_seat_count),
patch(
"corporate.lib.stripe.RealmBillingSession.get_initial_upgrade_context",
@@ -2006,6 +2011,65 @@ class StripeTest(StripeTestCase):
self.assertEqual(ledger_entry.licenses, new_seat_count)
self.assertEqual(ledger_entry.licenses_at_next_renewal, new_seat_count)
+ @mock_stripe()
+ def test_upgrade_by_card_with_outdated_lower_seat_count(self, *mocks: Mock) -> None:
+ hamlet = self.example_user("hamlet")
+ self.login_user(hamlet)
+ new_seat_count = self.seat_count - 1
+ initial_upgrade_request = InitialUpgradeRequest(
+ manual_license_management=False,
+ tier=CustomerPlan.TIER_CLOUD_STANDARD,
+ billing_modality="charge_automatically",
+ )
+ billing_session = RealmBillingSession(hamlet)
+ _, context_when_upgrade_page_is_rendered = billing_session.get_initial_upgrade_context(
+ initial_upgrade_request
+ )
+ # Change the seat count in upgrade flow: after do_upgrade, during process_initial_upgrade
+ with (
+ patch(
+ "corporate.lib.stripe.BillingSession.stale_seat_count_check",
+ return_value=self.seat_count,
+ ),
+ patch("corporate.lib.stripe.get_latest_seat_count", return_value=new_seat_count),
+ patch(
+ "corporate.lib.stripe.RealmBillingSession.get_initial_upgrade_context",
+ return_value=(_, context_when_upgrade_page_is_rendered),
+ ),
+ ):
+ self.add_card_and_upgrade(hamlet)
+
+ customer = Customer.objects.first()
+ assert customer is not None
+ stripe_customer_id: str = assert_is_not_none(customer.stripe_customer_id)
+ # Check that the Charge used the old quantity, not new_seat_count
+ [charge] = iter(stripe.Charge.list(customer=stripe_customer_id))
+ self.assertEqual(8000 * self.seat_count, charge.amount)
+ [upgrade_invoice] = iter(stripe.Invoice.list(customer=stripe_customer_id))
+ self.assertEqual(
+ [8000 * self.seat_count],
+ [item.amount for item in upgrade_invoice.lines],
+ )
+ # Check LicenseLedger has the reduced license count at renewal
+ ledger_entry = LicenseLedger.objects.last()
+ assert ledger_entry is not None
+ self.assertEqual(ledger_entry.licenses, self.seat_count)
+ self.assertEqual(ledger_entry.licenses_at_next_renewal, new_seat_count)
+
+ # Check that we informed the support team about the potential billing error.
+ from django.core.mail import outbox
+
+ self.assert_length(outbox, 1)
+
+ for message in outbox:
+ self.assert_length(message.to, 1)
+ self.assertEqual(message.to[0], "[email protected]")
+ self.assertEqual(
+ message.subject,
+ f"Check initial licenses invoiced for {billing_session.billing_entity_display_name}",
+ )
+ self.assertEqual(self.email_envelope_from(message), settings.NOREPLY_EMAIL_ADDRESS)
+
def test_upgrade_with_tampered_seat_count(self) -> None:
hamlet = self.example_user("hamlet")
self.login_user(hamlet)
diff --git a/templates/zerver/emails/internal_billing_notice.html b/templates/zerver/emails/internal_billing_notice.html
index 7974db47b21..2d72ad0e69e 100644
--- a/templates/zerver/emails/internal_billing_notice.html
+++ b/templates/zerver/emails/internal_billing_notice.html
@@ -11,6 +11,10 @@
<b>Last data upload</b>: {{ last_audit_log_update }}
{% elif notice_reason == "locally_deleted_realm_on_paid_plan" %}
<p>Investigate why remote realm is marked as locally deleted when it's on a paid plan.</p>
+{% elif notice_reason == "license_discrepancy" %}
+<p>Discrepancy in licenses when upgraded to current plan.</p>
+<b>Licenses paid for</b>: {{ paid_licenses }}.
+<b>Reported licenses in use</b>: {{ current_licenses }}.
{% endif %}
<br /><br />
diff --git a/templates/zerver/emails/internal_billing_notice.subject.txt b/templates/zerver/emails/internal_billing_notice.subject.txt
index fccafcf395e..e7e88645856 100644
--- a/templates/zerver/emails/internal_billing_notice.subject.txt
+++ b/templates/zerver/emails/internal_billing_notice.subject.txt
@@ -4,4 +4,6 @@ Fixed-price plan for {{ billing_entity }} ends on {{ end_date }}
Invoice overdue for {{ billing_entity }} due to stale data
{% elif notice_reason == "locally_deleted_realm_on_paid_plan" %}
{{ billing_entity }} on paid plan marked as locally deleted
+{% elif notice_reason == "license_discrepancy" %}
+Check initial licenses invoiced for {{ billing_entity }}
{% endif %}
diff --git a/templates/zerver/emails/internal_billing_notice.txt b/templates/zerver/emails/internal_billing_notice.txt
index b08c566969c..3cdf9b219cb 100644
--- a/templates/zerver/emails/internal_billing_notice.txt
+++ b/templates/zerver/emails/internal_billing_notice.txt
@@ -8,6 +8,11 @@ Recent invoice is overdue for payment.
Last data upload: {{ last_audit_log_update }}
{% elif notice_reason == "locally_deleted_realm_on_paid_plan" %}
Investigate why remote realm is marked as locally deleted when it's on a paid plan.
+{% elif notice_reason == "license_discrepancy" %}
+Discrepancy in licenses when upgraded to current plan.
+
+Licenses paid for: {{ paid_licenses }}.
+Reported licenses in use: {{ current_licenses }}.
{% endif %}
Support URL: {{ support_url }}