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: Improve testing for switching from Standard to Plus.

Eeshan Gargf60b8ccedc0d
diff --git a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.create.1.json b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.create.1.json
new file mode 100644
index 00000000000..0eddc80a49d
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.create.1.json
@@ -0,0 +1,30 @@
+{
+ "address": null,
+ "balance": 0,
+ "created": 1000000000,
+ "currency": null,
+ "default_source": null,
+ "delinquent": false,
+ "description": "lear (Lear & Co.)",
+ "discount": null,
+ "email": "[email protected]",
+ "id": "cus_NORMALIZED0001",
+ "invoice_prefix": "NORMA01",
+ "invoice_settings": {
+ "custom_fields": null,
+ "default_payment_method": null,
+ "footer": null
+ },
+ "livemode": false,
+ "metadata": {
+ "realm_id": "1",
+ "realm_str": "lear"
+ },
+ "name": null,
+ "next_invoice_sequence": 1,
+ "object": "customer",
+ "phone": null,
+ "preferred_locales": [],
+ "shipping": null,
+ "tax_exempt": "none"
+}
diff --git a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.create_balance_transaction.1.json b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.create_balance_transaction.1.json
index 68a55480a80..cfd38627ace 100644
--- a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.create_balance_transaction.1.json
+++ b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.create_balance_transaction.1.json
@@ -1,16 +1,15 @@
{
- "id": "cbtxn_1JkZzGHSaWXyvFpKI1U7dskx",
- "object": "customer_balance_transaction",
- "amount": -7200,
- "created": 1634241190,
- "credit_note": null,
- "currency": "usd",
- "customer": "cus_12345",
- "description": "Credit from early termination of Standard plan",
- "ending_balance": -7200,
- "invoice": null,
- "livemode": false,
- "metadata": {
- },
- "type": "adjustment"
+ "amount": -7200,
+ "created": 1000000000,
+ "credit_note": null,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED0001",
+ "description": "Credit from early termination of Standard plan",
+ "ending_balance": -7200,
+ "id": "cbtxn_NORMALIZED00000000000001",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "customer_balance_transaction",
+ "type": "adjustment"
}
diff --git a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.list_balance_transactions.1.json b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.list_balance_transactions.1.json
new file mode 100644
index 00000000000..07d1d8cb4d6
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Customer.list_balance_transactions.1.json
@@ -0,0 +1,37 @@
+{
+ "data": [
+ {
+ "amount": 7200,
+ "created": 1000000000,
+ "credit_note": null,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED0001",
+ "description": null,
+ "ending_balance": 0,
+ "id": "cbtxn_NORMALIZED00000000000002",
+ "invoice": "in_NORMALIZED00000000000001",
+ "livemode": false,
+ "metadata": {},
+ "object": "customer_balance_transaction",
+ "type": "applied_to_invoice"
+ },
+ {
+ "amount": -7200,
+ "created": 1000000000,
+ "credit_note": null,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED0001",
+ "description": "Credit from early termination of Standard plan",
+ "ending_balance": -7200,
+ "id": "cbtxn_NORMALIZED00000000000001",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "customer_balance_transaction",
+ "type": "adjustment"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "url": "/v1/customers/cus_NORMALIZED0001/balance_transactions"
+}
diff --git a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.create.1.json b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.create.1.json
index 4a3c8a2fdb8..0d1f93f3765 100644
--- a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.create.1.json
+++ b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.create.1.json
@@ -1,142 +1,130 @@
{
- "id": "in_1JkZzHHSaWXyvFpKS2T8uAoF",
- "object": "invoice",
- "account_country": "US",
- "account_name": "Random Tech Company Inc",
- "account_tax_ids": null,
- "amount_due": 7200,
- "amount_paid": 0,
- "amount_remaining": 7200,
- "application_fee_amount": null,
- "attempt_count": 0,
- "attempted": false,
- "auto_advance": true,
- "automatic_tax": {
- "enabled": false,
- "status": null
- },
- "billing_reason": "manual",
- "charge": null,
- "collection_method": "charge_automatically",
- "created": 1634241191,
- "currency": "usd",
- "custom_fields": null,
- "customer": "cus_12345",
- "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,
- "ending_balance": null,
- "footer": null,
- "hosted_invoice_url": null,
- "invoice_pdf": null,
- "last_finalization_error": null,
- "lines": {
- "object": "list",
- "data": [
- {
- "id": "il_1JkZzGHSaWXyvFpKhn6ouXWE",
- "object": "line_item",
- "amount": 14400,
+ "account_country": "US",
+ "account_name": "NORMALIZED-1",
+ "account_tax_ids": null,
+ "amount_due": 7200,
+ "amount_paid": 0,
+ "amount_remaining": 7200,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": 1000000000,
+ "ending_balance": null,
+ "footer": null,
+ "hosted_invoice_url": null,
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": null,
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 14400,
+ "currency": "usd",
+ "description": "Zulip Plus - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000001",
+ "invoice_item": "ii_NORMALIZED00000000000001",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
"currency": "usd",
- "description": "Zulip Plus - renewal",
- "discount_amounts": [
- ],
- "discountable": false,
- "discounts": [
- ],
- "invoice_item": "ii_1JkZzGHSaWXyvFpKltjY9eDZ",
+ "id": "price_NORMALIZED00000000000001",
"livemode": false,
- "metadata": {
- },
- "period": {
- "end": 1636919590,
- "start": 1634241190
- },
- "plan": null,
- "price": {
- "id": "price_1JkZzGHSaWXyvFpK2ipHpRqs",
- "object": "price",
- "active": false,
- "billing_scheme": "per_unit",
- "created": 1634241190,
- "currency": "usd",
- "livemode": false,
- "lookup_key": null,
- "metadata": {
- },
- "nickname": null,
- "product": "prod_KPOmOPVZ6YxUJA",
- "recurring": null,
- "tax_behavior": "unspecified",
- "tiers_mode": null,
- "transform_quantity": null,
- "type": "one_time",
- "unit_amount": 1600,
- "unit_amount_decimal": "1600"
- },
- "proration": false,
- "quantity": 9,
- "subscription": null,
- "tax_amounts": [
- ],
- "tax_rates": [
- ],
- "type": "invoiceitem"
- }
- ],
- "has_more": false,
- "total_count": 1,
- "url": "/v1/invoices/in_1JkZzHHSaWXyvFpKS2T8uAoF/lines"
- },
- "livemode": false,
- "metadata": {
- },
- "next_payment_attempt": 1634244791,
- "number": null,
- "on_behalf_of": null,
- "paid": false,
- "payment_intent": null,
- "payment_settings": {
- "payment_method_options": null,
- "payment_method_types": null
- },
- "period_end": 1634241191,
- "period_start": 1634241191,
- "post_payment_credit_notes_amount": 0,
- "pre_payment_credit_notes_amount": 0,
- "quote": null,
- "receipt_number": null,
- "starting_balance": -7200,
- "statement_descriptor": "Zulip Plus",
- "status": "draft",
- "status_transitions": {
- "finalized_at": null,
- "marked_uncollectible_at": null,
- "paid_at": null,
- "voided_at": null
- },
- "subscription": null,
- "subtotal": 14400,
- "tax": null,
- "total": 14400,
- "total_discount_amounts": [
- ],
- "total_tax_amounts": [
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1600,
+ "unit_amount_decimal": "1600"
+ },
+ "proration": false,
+ "quantity": 9,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem"
+ }
],
- "transfer_data": null,
- "webhooks_delivered_at": null
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": null,
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "payment_intent": null,
+ "payment_settings": {
+ "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,
+ "starting_balance": -7200,
+ "statement_descriptor": "Zulip Plus",
+ "status": "draft",
+ "status_transitions": {
+ "finalized_at": null,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 14400,
+ "tax": null,
+ "total": 14400,
+ "total_discount_amounts": [],
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
}
diff --git a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.finalize_invoice.1.json b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.finalize_invoice.1.json
index 8ca53812001..dc4f1c7ec6c 100644
--- a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.finalize_invoice.1.json
+++ b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.finalize_invoice.1.json
@@ -1,142 +1,130 @@
{
- "id": "in_1JkZzHHSaWXyvFpKS2T8uAoF",
- "object": "invoice",
- "account_country": "US",
- "account_name": "Random Tech Company Inc",
- "account_tax_ids": null,
- "amount_due": 7200,
- "amount_paid": 0,
- "amount_remaining": 7200,
- "application_fee_amount": null,
- "attempt_count": 0,
- "attempted": false,
- "auto_advance": true,
- "automatic_tax": {
- "enabled": false,
- "status": null
- },
- "billing_reason": "manual",
- "charge": null,
- "collection_method": "charge_automatically",
- "created": 1634241191,
- "currency": "usd",
- "custom_fields": null,
- "customer": "cus_12345",
- "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,
- "ending_balance": 0,
- "footer": null,
- "hosted_invoice_url": "https://invoice.stripe.com/i/acct_1CGwp5HSaWXyvFpK/test_YWNjdF8xQ0d3cDVIU2FXWHl2RnBLLF9LUE9tRk8wd3o0cDVoeTV3VDUycmt2MVRuT2xjZzlC0100uIwzi9rE",
- "invoice_pdf": "https://pay.stripe.com/invoice/acct_1CGwp5HSaWXyvFpK/test_YWNjdF8xQ0d3cDVIU2FXWHl2RnBLLF9LUE9tRk8wd3o0cDVoeTV3VDUycmt2MVRuT2xjZzlC0100uIwzi9rE/pdf",
- "last_finalization_error": null,
- "lines": {
- "object": "list",
- "data": [
- {
- "id": "il_1JkZzGHSaWXyvFpKhn6ouXWE",
- "object": "line_item",
- "amount": 14400,
+ "account_country": "US",
+ "account_name": "NORMALIZED-1",
+ "account_tax_ids": null,
+ "amount_due": 7200,
+ "amount_paid": 0,
+ "amount_remaining": 7200,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01cDVIU2FXWHl2RnBLLF9LVkpRNFVqTkNycnpjV1dyR2lZY1hhT2RQdWgzV1NS0100Df6GFlHS",
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01cDVIU2FXWHl2RnBLLF9LVkpRNFVqTkNycnpjV1dyR2lZY1hhT2RQdWgzV1NS0100Df6GFlHS/pdf",
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 14400,
+ "currency": "usd",
+ "description": "Zulip Plus - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000001",
+ "invoice_item": "ii_NORMALIZED00000000000001",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
"currency": "usd",
- "description": "Zulip Plus - renewal",
- "discount_amounts": [
- ],
- "discountable": false,
- "discounts": [
- ],
- "invoice_item": "ii_1JkZzGHSaWXyvFpKltjY9eDZ",
+ "id": "price_NORMALIZED00000000000001",
"livemode": false,
- "metadata": {
- },
- "period": {
- "end": 1636919590,
- "start": 1634241190
- },
- "plan": null,
- "price": {
- "id": "price_1JkZzGHSaWXyvFpK2ipHpRqs",
- "object": "price",
- "active": false,
- "billing_scheme": "per_unit",
- "created": 1634241190,
- "currency": "usd",
- "livemode": false,
- "lookup_key": null,
- "metadata": {
- },
- "nickname": null,
- "product": "prod_KPOmOPVZ6YxUJA",
- "recurring": null,
- "tax_behavior": "unspecified",
- "tiers_mode": null,
- "transform_quantity": null,
- "type": "one_time",
- "unit_amount": 1600,
- "unit_amount_decimal": "1600"
- },
- "proration": false,
- "quantity": 9,
- "subscription": null,
- "tax_amounts": [
- ],
- "tax_rates": [
- ],
- "type": "invoiceitem"
- }
- ],
- "has_more": false,
- "total_count": 1,
- "url": "/v1/invoices/in_1JkZzHHSaWXyvFpKS2T8uAoF/lines"
- },
- "livemode": false,
- "metadata": {
- },
- "next_payment_attempt": 1634244791,
- "number": "C17F3DE7-0002",
- "on_behalf_of": null,
- "paid": false,
- "payment_intent": "pi_3JkZzIHSaWXyvFpK1vzlINnH",
- "payment_settings": {
- "payment_method_options": null,
- "payment_method_types": null
- },
- "period_end": 1634241191,
- "period_start": 1634241191,
- "post_payment_credit_notes_amount": 0,
- "pre_payment_credit_notes_amount": 0,
- "quote": null,
- "receipt_number": null,
- "starting_balance": -7200,
- "statement_descriptor": "Zulip Plus",
- "status": "open",
- "status_transitions": {
- "finalized_at": 1634241191,
- "marked_uncollectible_at": null,
- "paid_at": null,
- "voided_at": null
- },
- "subscription": null,
- "subtotal": 14400,
- "tax": null,
- "total": 14400,
- "total_discount_amounts": [
- ],
- "total_tax_amounts": [
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1600,
+ "unit_amount_decimal": "1600"
+ },
+ "proration": false,
+ "quantity": 9,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem"
+ }
],
- "transfer_data": null,
- "webhooks_delivered_at": null
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "payment_intent": "pi_NORMALIZED00000000000001",
+ "payment_settings": {
+ "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,
+ "starting_balance": -7200,
+ "statement_descriptor": "Zulip Plus",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 14400,
+ "tax": null,
+ "total": 14400,
+ "total_discount_amounts": [],
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
}
diff --git a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.list.1.json b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.list.1.json
new file mode 100644
index 00000000000..9db33b4ce21
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--Invoice.list.1.json
@@ -0,0 +1,137 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "NORMALIZED-1",
+ "account_tax_ids": null,
+ "amount_due": 7200,
+ "amount_paid": 0,
+ "amount_remaining": 7200,
+ "application_fee_amount": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "automatic_tax": {
+ "enabled": false,
+ "status": null
+ },
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "send_invoice",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": 1000000000,
+ "ending_balance": 0,
+ "footer": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/test_NORMALIZED01cDVIU2FXWHl2RnBLLF9LVkpRNFVqTkNycnpjV1dyR2lZY1hhT2RQdWgzV1NS0100Df6GFlHS",
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/test_NORMALIZED01cDVIU2FXWHl2RnBLLF9LVkpRNFVqTkNycnpjV1dyR2lZY1hhT2RQdWgzV1NS0100Df6GFlHS/pdf",
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 14400,
+ "currency": "usd",
+ "description": "Zulip Plus - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "il_NORMALIZED00000000000001",
+ "invoice_item": "ii_NORMALIZED00000000000001",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_NORMALIZED00000000000001",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1600,
+ "unit_amount_decimal": "1600"
+ },
+ "proration": false,
+ "quantity": 9,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0001",
+ "object": "invoice",
+ "on_behalf_of": null,
+ "paid": false,
+ "payment_intent": "pi_NORMALIZED00000000000001",
+ "payment_settings": {
+ "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,
+ "starting_balance": -7200,
+ "statement_descriptor": "Zulip Plus",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 14400,
+ "tax": null,
+ "total": 14400,
+ "total_discount_amounts": [],
+ "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/switch_realm_from_standard_to_plus_plan--InvoiceItem.create.1.json b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--InvoiceItem.create.1.json
index 1d6d11ea4cd..f67f3a76987 100644
--- a/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--InvoiceItem.create.1.json
+++ b/corporate/tests/stripe_fixtures/switch_realm_from_standard_to_plus_plan--InvoiceItem.create.1.json
@@ -1,49 +1,45 @@
{
- "id": "ii_1JkZzGHSaWXyvFpKltjY9eDZ",
- "object": "invoiceitem",
- "amount": 14400,
+ "amount": 14400,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED0001",
+ "date": 1000000000,
+ "description": "Zulip Plus - renewal",
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000001",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
"currency": "usd",
- "customer": "cus_12345",
- "date": 1634241190,
- "description": "Zulip Plus - renewal",
- "discountable": false,
- "discounts": [
- ],
- "invoice": null,
+ "id": "price_NORMALIZED00000000000001",
"livemode": false,
- "metadata": {
- },
- "period": {
- "end": 1636919590,
- "start": 1634241190
- },
- "plan": null,
- "price": {
- "id": "price_1JkZzGHSaWXyvFpK2ipHpRqs",
- "object": "price",
- "active": false,
- "billing_scheme": "per_unit",
- "created": 1634241190,
- "currency": "usd",
- "livemode": false,
- "lookup_key": null,
- "metadata": {
- },
- "nickname": null,
- "product": "prod_KPOmOPVZ6YxUJA",
- "recurring": null,
- "tax_behavior": "unspecified",
- "tiers_mode": null,
- "transform_quantity": null,
- "type": "one_time",
- "unit_amount": 1600,
- "unit_amount_decimal": "1600"
- },
- "proration": false,
- "quantity": 9,
- "subscription": null,
- "tax_rates": [
- ],
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_NORMALIZED0001",
+ "recurring": null,
+ "tax_behavior": "unspecified",
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
"unit_amount": 1600,
"unit_amount_decimal": "1600"
+ },
+ "proration": false,
+ "quantity": 9,
+ "subscription": null,
+ "tax_rates": [],
+ "unit_amount": 1600,
+ "unit_amount_decimal": "1600"
}
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index faf1253eeae..4163a9d284d 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -300,6 +300,7 @@ MOCKED_STRIPE_FUNCTION_NAMES = [
"Coupon.create",
"Customer.create",
"Customer.create_balance_transaction",
+ "Customer.list_balance_transactions",
"Customer.retrieve",
"Customer.save",
"Invoice.create",
@@ -2982,7 +2983,8 @@ class StripeTest(StripeTestCase):
@mock_stripe()
def test_switch_realm_from_standard_to_plus_plan(self, *mock: Mock) -> None:
- realm = get_realm("zulip")
+ iago = self.example_user("iago")
+ realm = iago.realm
# Test upgrading to Plus when realm has no Standard subscription
with self.assertRaises(BillingError) as billing_context:
@@ -3002,12 +3004,28 @@ class StripeTest(StripeTestCase):
"Organization missing Stripe customer.", billing_context.exception.error_description
)
- plan.customer.stripe_customer_id = "cus_12345"
- plan.customer.save(update_fields=["stripe_customer_id"])
- plan.price_per_license = get_price_per_license(CustomerPlan.STANDARD, CustomerPlan.MONTHLY)
- plan.automanage_licenses = True
+ king = self.lear_user("king")
+ realm = king.realm
+ customer = update_or_create_stripe_customer(king)
+ plan = CustomerPlan.objects.create(
+ customer=customer,
+ automanage_licenses=True,
+ billing_cycle_anchor=timezone_now(),
+ billing_schedule=CustomerPlan.MONTHLY,
+ tier=CustomerPlan.STANDARD,
+ )
+ ledger = LicenseLedger.objects.create(
+ plan=plan,
+ is_renewal=True,
+ event_time=timezone_now(),
+ licenses=9,
+ licenses_at_next_renewal=9,
+ )
+ realm.plan_type = Realm.PLAN_TYPE_STANDARD
+ realm.save(update_fields=["plan_type"])
plan.invoiced_through = ledger
- plan.save(update_fields=["price_per_license", "automanage_licenses", "invoiced_through"])
+ plan.price_per_license = get_price_per_license(CustomerPlan.STANDARD, CustomerPlan.MONTHLY)
+ plan.save(update_fields=["invoiced_through", "price_per_license"])
switch_realm_from_standard_to_plus_plan(realm)
@@ -3018,6 +3036,29 @@ class StripeTest(StripeTestCase):
self.assertEqual(plus_plan.tier, CustomerPlan.PLUS)
self.assertEqual(LicenseLedger.objects.filter(plan=plus_plan).count(), 1)
+ # There are 9 licenses and the realm is on the Standard monthly plan.
+ # Therefore, the customer has already paid 800 * 9 = 7200 = $72 for
+ # the month. Once they upgrade to Plus, the new price for their 9
+ # licenses will be 1600 * 9 = 14400 = $144. Since the customer has
+ # already paid $72 for a month, -7200 = -$72 will be credited to the
+ # customer's balance.
+ stripe_customer_id = customer.stripe_customer_id
+ assert stripe_customer_id is not None
+ _, cb_txn = stripe.Customer.list_balance_transactions( # type: ignore[attr-defined] # mypy seems to incorrectly think that this function doesn't exist
+ stripe_customer_id
+ )
+ self.assertEqual(cb_txn.amount, -7200)
+ self.assertEqual(
+ cb_txn.description,
+ "Credit from early termination of Standard plan",
+ )
+ self.assertEqual(cb_txn.type, "adjustment")
+
+ # The customer now only pays the difference 14400 - 7200 = 7200 = $72,
+ # since the unused proration is for the whole month.
+ (invoice,) = stripe.Invoice.list(customer=stripe_customer_id)
+ self.assertEqual(invoice.amount_due, 7200)
+
def test_update_billing_method_of_current_plan(self) -> None:
realm = get_realm("zulip")
customer = Customer.objects.create(realm=realm, stripe_customer_id="cus_12345")