Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stripe: Add test to verify charge for new users during free trial.
Aman Agrawal9d643ba31b9c
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex 9c264893170..a8470b172ab 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -3046,7 +3046,7 @@ class BillingSession(ABC):licenses = update_plan_request.licensesif licenses is not None:- if plan.is_free_trial(): # nocoverage+ if plan.is_free_trial():raise JsonableError(_("Cannot update licenses in the current billing period for free trial plan."))diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.create.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.create.1.jsonnew file mode 100644index 00000000000..af4adf54e84--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.create.1.json@@ -0,0 +1,32 @@+{+ "address": null,+ "balance": 0,+ "created": 1000000000,+ "currency": null,+ "default_source": null,+ "delinquent": false,+ "description": "zulip (Zulip Dev)",+ "discount": null,+ "email": "[email protected]",+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.1.jsonnew file mode 100644index 00000000000..af4adf54e84--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.1.json@@ -0,0 +1,32 @@+{+ "address": null,+ "balance": 0,+ "created": 1000000000,+ "currency": null,+ "default_source": null,+ "delinquent": false,+ "description": "zulip (Zulip Dev)",+ "discount": null,+ "email": "[email protected]",+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.2.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.2.jsonnew file mode 100644index 00000000000..f1935165ffc--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.2.json@@ -0,0 +1,32 @@+{+ "address": null,+ "balance": 0,+ "created": 1000000000,+ "currency": "usd",+ "default_source": null,+ "delinquent": false,+ "description": "zulip (Zulip Dev)",+ "discount": null,+ "email": "[email protected]",+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 2,+ "object": "customer",+ "phone": null,+ "preferred_locales": [],+ "shipping": null,+ "tax_exempt": "none",+ "test_clock": null+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.3.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.3.jsonnew file mode 100644index 00000000000..f1935165ffc--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.3.json@@ -0,0 +1,32 @@+{+ "address": null,+ "balance": 0,+ "created": 1000000000,+ "currency": "usd",+ "default_source": null,+ "delinquent": false,+ "description": "zulip (Zulip Dev)",+ "discount": null,+ "email": "[email protected]",+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 2,+ "object": "customer",+ "phone": null,+ "preferred_locales": [],+ "shipping": null,+ "tax_exempt": "none",+ "test_clock": null+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.4.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.4.jsonnew file mode 100644index 00000000000..f1935165ffc--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Customer.retrieve.4.json@@ -0,0 +1,32 @@+{+ "address": null,+ "balance": 0,+ "created": 1000000000,+ "currency": "usd",+ "default_source": null,+ "delinquent": false,+ "description": "zulip (Zulip Dev)",+ "discount": null,+ "email": "[email protected]",+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 2,+ "object": "customer",+ "phone": null,+ "preferred_locales": [],+ "shipping": null,+ "tax_exempt": "none",+ "test_clock": null+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.jsonnew file mode 100644index 00000000000..4fda3fe4602--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.json@@ -0,0 +1,168 @@+{+ "data": [+ {+ "api_version": "2025-04-30.basil",+ "created": 1000000000,+ "data": {+ "object": {+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 16000,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 16000,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.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": 16000,+ "currency": "usd",+ "description": "Additional license (Mar 2, 2012 - Mar 2, 2013)",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 2,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.json/lines"+ },+ "livemode": false,+ "metadata": {},+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 16000,+ "subtotal_excluding_tax": 16000,+ "test_clock": null,+ "total": 16000,+ "total_discount_amounts": [],+ "total_excluding_tax": 16000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+ }+ },+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.1.json",+ "livemode": false,+ "object": "event",+ "pending_webhooks": 0,+ "request": {+ "id": null,+ "idempotency_key": null+ },+ "type": "invoice.sent"+ }+ ],+ "has_more": true,+ "object": "list",+ "url": "/v1/events"+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.jsonnew file mode 100644index 00000000000..72e00bb84fa--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json@@ -0,0 +1,176 @@+{+ "data": [+ {+ "api_version": "2025-04-30.basil",+ "created": 1000000000,+ "data": {+ "object": {+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 984000,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 984000,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 984000,+ "currency": "usd",+ "description": "Zulip Cloud Standard",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 123,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 984000,+ "subtotal_excluding_tax": 984000,+ "test_clock": null,+ "total": 984000,+ "total_discount_amounts": [],+ "total_excluding_tax": 984000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+ }+ },+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "object": "event",+ "pending_webhooks": 0,+ "request": {+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "idempotency_key": "00000000-0000-0000-0000-000000000000"+ },+ "type": "invoice.finalized"+ }+ ],+ "has_more": true,+ "object": "list",+ "url": "/v1/events"+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.jsonnew file mode 100644index 00000000000..9d80b4c2a72--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json@@ -0,0 +1,425 @@+{+ "data": [+ {+ "api_version": "2025-04-30.basil",+ "created": 1000000000,+ "data": {+ "object": {+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 984000,+ "amount_overpaid": 0,+ "amount_paid": 984000,+ "amount_remaining": 0,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": false,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 984000,+ "currency": "usd",+ "description": "Zulip Cloud Standard",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 123,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 984000,+ "subtotal_excluding_tax": 984000,+ "test_clock": null,+ "total": 984000,+ "total_discount_amounts": [],+ "total_excluding_tax": 984000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+ }+ },+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json",+ "livemode": false,+ "object": "event",+ "pending_webhooks": 0,+ "request": {+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json",+ "idempotency_key": "00000000-0000-0000-0000-000000000000"+ },+ "type": "invoice.paid"+ },+ {+ "api_version": "2025-04-30.basil",+ "created": 1000000000,+ "data": {+ "object": {+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 984000,+ "amount_overpaid": 0,+ "amount_paid": 984000,+ "amount_remaining": 0,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": false,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 984000,+ "currency": "usd",+ "description": "Zulip Cloud Standard",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 123,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 984000,+ "subtotal_excluding_tax": 984000,+ "test_clock": null,+ "total": 984000,+ "total_discount_amounts": [],+ "total_excluding_tax": 984000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+ },+ "previous_attributes": {+ "amount_paid": 0,+ "amount_remaining": 984000,+ "auto_advance": true,+ "status": "open",+ "status_transitions": {+ "paid_at": null+ }+ }+ },+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json",+ "livemode": false,+ "object": "event",+ "pending_webhooks": 0,+ "request": {+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json",+ "idempotency_key": "00000000-0000-0000-0000-000000000000"+ },+ "type": "invoice.updated"+ },+ {+ "api_version": "2025-04-30.basil",+ "created": 1000000000,+ "data": {+ "object": {+ "amount": 984000,+ "amount_capturable": 0,+ "amount_details": {+ "tip": {}+ },+ "amount_received": 0,+ "application": null,+ "application_fee_amount": null,+ "automatic_payment_methods": null,+ "canceled_at": 1000000000,+ "cancellation_reason": "requested_by_customer",+ "capture_method": "automatic",+ "client_secret": "NORMALIZED",+ "confirmation_method": "automatic",+ "created": 1000000000,+ "currency": "usd",+ "customer": "cus_NORMALIZED",+ "description": "Payment for Invoice",+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.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"+ },+ "link": {+ "persistent_token": null+ }+ },+ "payment_method_types": [+ "card",+ "link"+ ],+ "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": "canceled",+ "transfer_data": null,+ "transfer_group": null+ }+ },+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json",+ "livemode": false,+ "object": "event",+ "pending_webhooks": 1,+ "request": {+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.3.json",+ "idempotency_key": "00000000-0000-0000-0000-000000000000"+ },+ "type": "payment_intent.canceled"+ }+ ],+ "has_more": false,+ "object": "list",+ "url": "/v1/events"+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.4.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.4.jsonnew file mode 100644index 00000000000..6d922067afe--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.4.json@@ -0,0 +1,6 @@+{+ "data": [],+ "has_more": false,+ "object": "list",+ "url": "/v1/events"+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.1.jsonnew file mode 100644index 00000000000..1fb980cb89b--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.1.json@@ -0,0 +1,113 @@+{+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 0,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 0,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": 1000000000,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "effective_at": null,+ "ending_balance": null,+ "footer": null,+ "from_invoice": null,+ "hosted_invoice_url": null,+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice_pdf": null,+ "issuer": {+ "type": "self"+ },+ "last_finalization_error": null,+ "latest_revision": null,+ "lines": {+ "data": [],+ "has_more": false,+ "object": "list",+ "total_count": 0,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": null,+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "auto"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 0,+ "subtotal_excluding_tax": 0,+ "test_clock": null,+ "total": 0,+ "total_discount_amounts": [],+ "total_excluding_tax": 0,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": null+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.jsonnew file mode 100644index 00000000000..a5d5a1d4dd8--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json@@ -0,0 +1,105 @@+{+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 0,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 0,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": 1000000000,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "effective_at": null,+ "ending_balance": null,+ "footer": null,+ "from_invoice": null,+ "hosted_invoice_url": null,+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json",+ "invoice_pdf": null,+ "issuer": {+ "type": "self"+ },+ "last_finalization_error": null,+ "latest_revision": null,+ "lines": {+ "data": [],+ "has_more": false,+ "object": "list",+ "total_count": 0,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json/lines"+ },+ "livemode": false,+ "metadata": {},+ "next_payment_attempt": null,+ "number": null,+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "auto"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 0,+ "subtotal_excluding_tax": 0,+ "test_clock": null,+ "total": 0,+ "total_discount_amounts": [],+ "total_excluding_tax": 0,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": null+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.1.jsonnew file mode 100644index 00000000000..9a0639c7d14--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.1.json@@ -0,0 +1,154 @@+{+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 984000,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 984000,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 984000,+ "currency": "usd",+ "description": "Zulip Cloud Standard",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 123,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 984000,+ "subtotal_excluding_tax": 984000,+ "test_clock": null,+ "total": 984000,+ "total_discount_amounts": [],+ "total_excluding_tax": 984000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.2.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.2.jsonnew file mode 100644index 00000000000..c85491cdd6d--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.2.json@@ -0,0 +1,146 @@+{+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 16000,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 16000,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.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": 16000,+ "currency": "usd",+ "description": "Additional license (Mar 2, 2012 - Mar 2, 2013)",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 2,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json/lines"+ },+ "livemode": false,+ "metadata": {},+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 16000,+ "subtotal_excluding_tax": 16000,+ "test_clock": null,+ "total": 16000,+ "total_discount_amounts": [],+ "total_excluding_tax": 16000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.list.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.list.1.jsonnew file mode 100644index 00000000000..316f2decfc8--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.list.1.json@@ -0,0 +1,161 @@+{+ "data": [+ {+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 984000,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 984000,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 984000,+ "currency": "usd",+ "description": "Zulip Cloud Standard",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 123,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 984000,+ "subtotal_excluding_tax": 984000,+ "test_clock": null,+ "total": 984000,+ "total_discount_amounts": [],+ "total_excluding_tax": 984000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+ }+ ],+ "has_more": false,+ "object": "list",+ "url": "/v1/invoices"+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.list.2.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.list.2.jsonnew file mode 100644index 00000000000..f3f06d95c1d--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.list.2.json@@ -0,0 +1,307 @@+{+ "data": [+ {+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 16000,+ "amount_overpaid": 0,+ "amount_paid": 0,+ "amount_remaining": 16000,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": true,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.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": 16000,+ "currency": "usd",+ "description": "Additional license (Mar 2, 2012 - Mar 2, 2013)",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.finalize_invoice.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 2,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.create.2.json/lines"+ },+ "livemode": false,+ "metadata": {},+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 16000,+ "subtotal_excluding_tax": 16000,+ "test_clock": null,+ "total": 16000,+ "total_discount_amounts": [],+ "total_excluding_tax": 16000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+ },+ {+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 984000,+ "amount_overpaid": 0,+ "amount_paid": 984000,+ "amount_remaining": 0,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": false,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 984000,+ "currency": "usd",+ "description": "Zulip Cloud Standard",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 123,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 984000,+ "subtotal_excluding_tax": 984000,+ "test_clock": null,+ "total": 984000,+ "total_discount_amounts": [],+ "total_excluding_tax": 984000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+ }+ ],+ "has_more": false,+ "object": "list",+ "url": "/v1/invoices"+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.pay.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.pay.1.jsonnew file mode 100644index 00000000000..668bdf85d96--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Invoice.pay.1.json@@ -0,0 +1,154 @@+{+ "account_country": "US",+ "account_name": "NORMALIZED",+ "account_tax_ids": null,+ "amount_due": 984000,+ "amount_overpaid": 0,+ "amount_paid": 984000,+ "amount_remaining": 0,+ "amount_shipping": 0,+ "application": null,+ "attempt_count": 0,+ "attempted": false,+ "auto_advance": false,+ "automatic_tax": {+ "disabled_reason": null,+ "enabled": false,+ "liability": null,+ "provider": null,+ "status": null+ },+ "automatically_finalizes_at": null,+ "billing_reason": "manual",+ "collection_method": "send_invoice",+ "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,+ "discounts": [],+ "due_date": 1000000000,+ "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": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--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": 984000,+ "currency": "usd",+ "description": "Zulip Cloud Standard",+ "discount_amounts": [],+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "invoice": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json",+ "livemode": false,+ "metadata": {},+ "object": "line_item",+ "parent": {+ "invoice_item_details": {+ "invoice_item": "ii_NORMALIZED",+ "proration": false,+ "proration_details": {+ "credited_items": null+ },+ "subscription": null+ },+ "subscription_item_details": null,+ "type": "invoice_item_details"+ },+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pretax_credit_amounts": [],+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "quantity": 123,+ "taxes": []+ }+ ],+ "has_more": false,+ "object": "list",+ "total_count": 1,+ "url": "/v1/invoices/free_trial_upgrade_by_invoice_with_additional_users_after_payment--Event.list.2.json/lines"+ },+ "livemode": false,+ "metadata": {+ "billing_schedule": "1",+ "current_plan_id": "1",+ "license_management": "manual",+ "licenses": "123",+ "on_free_trial": "True",+ "plan_tier": "1",+ "user_id": "10"+ },+ "next_payment_attempt": null,+ "number": "NORMALIZED",+ "object": "invoice",+ "on_behalf_of": null,+ "parent": 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,+ "receipt_number": null,+ "rendering": {+ "amount_tax_display": null,+ "pdf": {+ "page_size": "letter"+ },+ "template": null,+ "template_version": 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+ },+ "subtotal": 984000,+ "subtotal_excluding_tax": 984000,+ "test_clock": null,+ "total": 984000,+ "total_discount_amounts": [],+ "total_excluding_tax": 984000,+ "total_pretax_credit_amounts": [],+ "total_taxes": [],+ "webhooks_delivered_at": 1000000000+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.1.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.1.jsonnew file mode 100644index 00000000000..be35f80950e--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.1.json@@ -0,0 +1,31 @@+{+ "amount": 984000,+ "currency": "usd",+ "customer": "cus_NORMALIZED",+ "date": 1000000000,+ "description": "Zulip Cloud Standard",+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.1.json",+ "invoice": "in_NORMALIZED",+ "livemode": false,+ "metadata": {},+ "object": "invoiceitem",+ "parent": null,+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "proration": false,+ "quantity": 123,+ "tax_rates": [],+ "test_clock": null+}diff --git a/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.2.json b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.2.jsonnew file mode 100644index 00000000000..8191328eaef--- /dev/null+++ b/corporate/tests/stripe_fixtures/free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.2.json@@ -0,0 +1,31 @@+{+ "amount": 16000,+ "currency": "usd",+ "customer": "cus_NORMALIZED",+ "date": 1000000000,+ "description": "Additional license (Mar 2, 2012 - Mar 2, 2013)",+ "discountable": false,+ "discounts": [],+ "id": "free_trial_upgrade_by_invoice_with_additional_users_after_payment--InvoiceItem.create.2.json",+ "invoice": "in_NORMALIZED",+ "livemode": false,+ "metadata": {},+ "object": "invoiceitem",+ "parent": null,+ "period": {+ "end": 1362193445,+ "start": 1330657445+ },+ "pricing": {+ "price_details": {+ "price": "price_NORMALIZED",+ "product": "prod_NORMALIZED"+ },+ "type": "price_details",+ "unit_amount_decimal": "8000"+ },+ "proration": false,+ "quantity": 2,+ "tax_rates": [],+ "test_clock": null+}diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex 05105f69b01..14281733ff6 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -85,6 +85,7 @@ from zerver.actions.create_user import ()from zerver.actions.realm_settings import do_deactivate_realm, do_reactivate_realmfrom zerver.actions.users import change_user_is_active, do_change_user_role, do_deactivate_user+from zerver.lib.exceptions import JsonableErrorfrom zerver.lib.remote_server import send_server_data_to_push_bouncerfrom zerver.lib.test_classes import ZulipTestCasefrom zerver.lib.test_helpers import activate_push_notification_service@@ -1831,6 +1832,213 @@ class StripeTest(StripeTestCase):# No additional ledger entries are created.self.assertEqual(before_ledger_count, after_ledger_count)+ @mock_stripe(tested_timestamp_fields=["created"])+ def test_free_trial_upgrade_by_invoice_with_additional_users_after_payment(+ self, *mocks: Mock+ ) -> None:+ user = self.example_user("hamlet")+ self.login_user(user)++ free_trial_end_date = self.now + timedelta(days=60)+ with self.settings(CLOUD_FREE_TRIAL_DAYS=60):+ response = self.client_get("/upgrade/")++ self.assert_in_success_response(+ ["Your card will not be charged", "free trial", "60-day"], response+ )+ self.assertNotEqual(user.realm.plan_type, Realm.PLAN_TYPE_STANDARD)+ self.assertFalse(Customer.objects.filter(realm=user.realm).exists())++ with time_machine.travel(self.now, tick=False):+ self.upgrade(invoice=True)++ stripe_customer = stripe_get_customer(+ assert_is_not_none(Customer.objects.get(realm=user.realm).stripe_customer_id)+ )+ self.assertEqual(stripe_customer.discount, None)+ self.assertEqual(stripe_customer.email, user.delivery_email)+ assert stripe_customer.metadata is not None+ metadata_dict = dict(stripe_customer.metadata)+ self.assertEqual(metadata_dict["realm_str"], "zulip")+ try:+ int(metadata_dict["realm_id"])+ except ValueError: # nocoverage+ raise AssertionError("realm_id is not a number")++ [invoice] = iter(stripe.Invoice.list(customer=stripe_customer.id))+ invoice_params = {+ "amount_due": 123 * 80 * 100,+ "amount_paid": 0,+ "amount_remaining": 123 * 80 * 100,+ "auto_advance": True,+ "collection_method": "send_invoice",+ "customer_email": self.example_email("hamlet"),+ "discount": None,+ "status": "open",+ }+ for key, value in invoice_params.items():+ self.assertEqual(invoice.get(key), value)++ customer = Customer.objects.get(stripe_customer_id=stripe_customer.id, realm=user.realm)+ plan = CustomerPlan.objects.get(+ customer=customer,+ automanage_licenses=False,+ price_per_license=8000,+ fixed_price=None,+ discount=None,+ billing_cycle_anchor=self.now,+ billing_schedule=CustomerPlan.BILLING_SCHEDULE_ANNUAL,+ invoiced_through=LicenseLedger.objects.first(),+ next_invoice_date=free_trial_end_date,+ tier=CustomerPlan.TIER_CLOUD_STANDARD,+ status=CustomerPlan.FREE_TRIAL,+ # For invoice billing.+ charge_automatically=False,+ )++ LicenseLedger.objects.get(+ plan=plan,+ is_renewal=True,+ event_time=self.now,+ licenses=123,+ licenses_at_next_renewal=123,+ )+ audit_log_entries = list(+ RealmAuditLog.objects.filter(acting_user=user)+ .values_list("event_type", "event_time")+ .order_by("id")+ )+ self.assertEqual(+ audit_log_entries[:3],+ [+ (+ AuditLogEventType.STRIPE_CUSTOMER_CREATED,+ timestamp_to_datetime(stripe_customer.created),+ ),+ (AuditLogEventType.CUSTOMER_PLAN_CREATED, self.now),+ (AuditLogEventType.REALM_PLAN_TYPE_CHANGED, self.now),+ ],+ )+ self.assertEqual(audit_log_entries[2][0], AuditLogEventType.REALM_PLAN_TYPE_CHANGED)+ first_audit_log_entry = (+ RealmAuditLog.objects.filter(event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED)+ .values_list("extra_data", flat=True)+ .first()+ )+ assert first_audit_log_entry is not None+ self.assertFalse(first_audit_log_entry["automanage_licenses"])++ realm = get_realm("zulip")+ self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_STANDARD)+ self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)++ with time_machine.travel(self.now, tick=False):+ response = self.client_get("/billing/")+ self.assert_not_in_success_response(["Pay annually"], response)+ for substring in [+ "Zulip Cloud Standard <i>(free trial)</i>",+ str(self.seat_count),+ "Number of licenses for next billing period",+ f"{self.seat_count} in use",+ "To ensure continuous access",+ "please pay",+ "before the end of your trial",+ "March 2, 2012",+ "Invoice",+ ]:+ self.assert_in_response(substring, response)++ [invoice_item] = iter(invoice.lines)+ invoice_item_params = {+ "amount": 123 * 80 * 100,+ "description": "Zulip Cloud Standard",+ "quantity": 123,+ "discountable": False,+ "period": {+ "start": datetime_to_timestamp(free_trial_end_date),+ "end": datetime_to_timestamp(add_months(free_trial_end_date, 12)),+ },+ }+ for key, value in invoice_item_params.items():+ self.assertEqual(invoice_item[key], value)++ with patch("corporate.lib.stripe.BillingSession.invoice_plan") as mocked:+ invoice_plans_as_needed(self.next_month)+ mocked.assert_not_called()+ mocked.reset_mock()+ customer_plan = CustomerPlan.objects.get(customer=customer)+ self.assertEqual(customer_plan.status, CustomerPlan.FREE_TRIAL)+ self.assertEqual(customer_plan.next_invoice_date, free_trial_end_date)++ [last_event] = iter(stripe.Event.list(limit=1))+ # Customer pays the invoice+ assert invoice.id is not None+ stripe.Invoice.pay(invoice.id, paid_out_of_band=True)+ self.send_stripe_webhook_events(last_event)++ with time_machine.travel(self.now, tick=False):+ response = self.client_get("/billing/")++ self.assert_in_success_response(["You have no outstanding invoices."], response)++ update_plan_request = UpdatePlanRequest(+ status=None,+ licenses=125,+ licenses_at_next_renewal=None,+ schedule=None,+ toggle_license_management=False,+ )+ # Customer cannot update licenses while in free trial.+ with time_machine.travel(self.now, tick=False), self.assertRaises(JsonableError) as exc:+ self.billing_session.do_update_plan(update_plan_request)+ self.assertEqual(+ str(exc.exception),+ "Cannot update licenses in the current billing period for free trial plan.",+ )++ # Customer paid the invoice and then added 2 new users for the next renewal period.+ update_plan_request = UpdatePlanRequest(+ status=None,+ licenses=None,+ licenses_at_next_renewal=125,+ schedule=None,+ toggle_license_management=False,+ )+ self.assertEqual(+ LicenseLedger.objects.filter(plan=plan).latest("id").licenses_at_next_renewal, 123+ )+ with time_machine.travel(self.now, tick=False):+ self.billing_session.do_update_plan(update_plan_request)+ self.assertEqual(+ LicenseLedger.objects.filter(plan=plan).latest("id").licenses_at_next_renewal, 125+ )++ invoice_plans_as_needed(free_trial_end_date)+ customer_plan.refresh_from_db()+ realm.refresh_from_db()+ plan.refresh_from_db()+ self.assertEqual(customer_plan.status, CustomerPlan.ACTIVE)+ self.assertEqual(customer_plan.next_invoice_date, add_months(free_trial_end_date, 1))+ self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_STANDARD)+ self.assertEqual(customer_plan.billing_cycle_anchor, free_trial_end_date)++ [additional_license_invoice, renewal_invoice] = iter(+ stripe.Invoice.list(customer=stripe_customer.id)+ )+ self.assertEqual(renewal_invoice.id, invoice.id)+ invoice_params = {+ "amount_due": 2 * 80 * 100,+ "amount_paid": 0,+ "amount_remaining": 2 * 80 * 100,+ "auto_advance": True,+ "collection_method": "send_invoice",+ "customer_email": self.example_email("hamlet"),+ "discount": None,+ "status": "open",+ }+ for key, value in invoice_params.items():+ self.assertEqual(additional_license_invoice.get(key), value)+@mock_stripe()def test_free_trial_upgrade_by_invoice_customer_fails_to_pay(self, *mocks: Mock) -> None:user = self.example_user("hamlet")