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.

billing: Make attach discount update the current price per license.

Vishnu KSbd2642a7b877
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 569e684c082..4151abb6aae 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -589,6 +589,11 @@ def invoice_plans_as_needed(event_time: datetime=timezone_now()) -> None:
def attach_discount_to_realm(realm: Realm, discount: Decimal) -> None:
Customer.objects.update_or_create(realm=realm, defaults={'default_discount': discount})
+ plan = get_current_plan_by_realm(realm)
+ if plan is not None:
+ plan.price_per_license = get_price_per_license(plan.tier, plan.billing_schedule, discount)
+ plan.discount = discount
+ plan.save(update_fields=["price_per_license", "discount"])
def update_sponsorship_status(realm: Realm, sponsorship_pending: bool) -> None:
customer, _ = Customer.objects.get_or_create(realm=realm)
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.1.json
index 2620a392d88..273b484f2cd 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.1.json
@@ -1,5 +1,6 @@
{
"amount": 7200,
+ "amount_captured": 7200,
"amount_refunded": 0,
"application": null,
"application_fee": null,
@@ -18,6 +19,7 @@
"name": "Ada Starr",
"phone": null
},
+ "calculated_statement_descriptor": "ZULIP STANDARD",
"captured": true,
"created": 1000000000,
"currency": "usd",
@@ -25,6 +27,7 @@
"description": "Upgrade to Zulip Standard, $12.0 x 6",
"destination": null,
"dispute": null,
+ "disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
@@ -59,7 +62,9 @@
"exp_year": 2033,
"fingerprint": "NORMALIZED000001",
"funding": "credit",
+ "installments": null,
"last4": "4242",
+ "network": "visa",
"three_d_secure": null,
"wallet": null
},
@@ -105,7 +110,7 @@
},
"source_transfer": null,
"statement_descriptor": "Zulip Standard",
- "statement_descriptor_suffix": "Zulip Standard",
+ "statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.2.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.2.json
index 35fcca7f6ec..3c278054f67 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.2.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.create.2.json
@@ -1,5 +1,6 @@
{
"amount": 36000,
+ "amount_captured": 36000,
"amount_refunded": 0,
"application": null,
"application_fee": null,
@@ -18,6 +19,7 @@
"name": "Ada Starr",
"phone": null
},
+ "calculated_statement_descriptor": "ZULIP STANDARD",
"captured": true,
"created": 1000000000,
"currency": "usd",
@@ -25,6 +27,7 @@
"description": "Upgrade to Zulip Standard, $60.0 x 6",
"destination": null,
"dispute": null,
+ "disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
@@ -59,7 +62,9 @@
"exp_year": 2033,
"fingerprint": "NORMALIZED000001",
"funding": "credit",
+ "installments": null,
"last4": "4242",
+ "network": "visa",
"three_d_secure": null,
"wallet": null
},
@@ -105,7 +110,7 @@
},
"source_transfer": null,
"statement_descriptor": "Zulip Standard",
- "statement_descriptor_suffix": "Zulip Standard",
+ "statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.1.json
index 7313a2152a0..2a0c257612e 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.1.json
@@ -2,6 +2,7 @@
"data": [
{
"amount": 7200,
+ "amount_captured": 7200,
"amount_refunded": 0,
"application": null,
"application_fee": null,
@@ -20,6 +21,7 @@
"name": "Ada Starr",
"phone": null
},
+ "calculated_statement_descriptor": "ZULIP STANDARD",
"captured": true,
"created": 1000000000,
"currency": "usd",
@@ -27,6 +29,7 @@
"description": "Upgrade to Zulip Standard, $12.0 x 6",
"destination": null,
"dispute": null,
+ "disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
@@ -61,7 +64,9 @@
"exp_year": 2033,
"fingerprint": "NORMALIZED000001",
"funding": "credit",
+ "installments": null,
"last4": "4242",
+ "network": "visa",
"three_d_secure": null,
"wallet": null
},
@@ -101,7 +106,7 @@
},
"source_transfer": null,
"statement_descriptor": "Zulip Standard",
- "statement_descriptor_suffix": "Zulip Standard",
+ "statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.2.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.2.json
index 6f79a5756ed..2df0a47ee68 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.2.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Charge.list.2.json
@@ -2,6 +2,7 @@
"data": [
{
"amount": 36000,
+ "amount_captured": 36000,
"amount_refunded": 0,
"application": null,
"application_fee": null,
@@ -20,6 +21,7 @@
"name": "Ada Starr",
"phone": null
},
+ "calculated_statement_descriptor": "ZULIP STANDARD",
"captured": true,
"created": 1000000000,
"currency": "usd",
@@ -27,6 +29,7 @@
"description": "Upgrade to Zulip Standard, $60.0 x 6",
"destination": null,
"dispute": null,
+ "disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
@@ -61,7 +64,9 @@
"exp_year": 2033,
"fingerprint": "NORMALIZED000001",
"funding": "credit",
+ "installments": null,
"last4": "4242",
+ "network": "visa",
"three_d_secure": null,
"wallet": null
},
@@ -101,13 +106,14 @@
},
"source_transfer": null,
"statement_descriptor": "Zulip Standard",
- "statement_descriptor_suffix": "Zulip Standard",
+ "statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
},
{
"amount": 7200,
+ "amount_captured": 7200,
"amount_refunded": 0,
"application": null,
"application_fee": null,
@@ -126,6 +132,7 @@
"name": "Ada Starr",
"phone": null
},
+ "calculated_statement_descriptor": "ZULIP STANDARD",
"captured": true,
"created": 1000000000,
"currency": "usd",
@@ -133,6 +140,7 @@
"description": "Upgrade to Zulip Standard, $12.0 x 6",
"destination": null,
"dispute": null,
+ "disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {},
@@ -167,7 +175,9 @@
"exp_year": 2033,
"fingerprint": "NORMALIZED000001",
"funding": "credit",
+ "installments": null,
"last4": "4242",
+ "network": "visa",
"three_d_secure": null,
"wallet": null
},
@@ -207,7 +217,7 @@
},
"source_transfer": null,
"statement_descriptor": "Zulip Standard",
- "statement_descriptor_suffix": "Zulip Standard",
+ "statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.create.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.create.1.json
index 5828b5becfc..1e87c2923cd 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.create.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.create.1.json
@@ -22,6 +22,7 @@
"realm_str": "zulip"
},
"name": null,
+ "next_invoice_sequence": 1,
"object": "customer",
"phone": null,
"preferred_locales": [],
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.retrieve.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.retrieve.1.json
index 15ba5b56984..17d00481138 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.retrieve.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.retrieve.1.json
@@ -46,6 +46,7 @@
"realm_str": "zulip"
},
"name": null,
+ "next_invoice_sequence": 2,
"object": "customer",
"phone": null,
"preferred_locales": [],
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.save.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.save.1.json
index ce6e5c4653a..e15c65677be 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.save.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Customer.save.1.json
@@ -22,6 +22,7 @@
"realm_str": "zulip"
},
"name": null,
+ "next_invoice_sequence": 2,
"object": "customer",
"phone": null,
"preferred_locales": [],
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.1.json
index fbe7ee2862e..73eba385be7 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.1.json
@@ -1,10 +1,11 @@
{
"account_country": "US",
- "account_name": "Dev account",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
"amount_due": 0,
"amount_paid": 0,
"amount_remaining": 0,
- "application_fee_amount": null,
+ "application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
@@ -23,24 +24,30 @@
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
+ "date": 1000000000,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
- "description": "",
+ "description": null,
"discount": null,
+ "discounts": [],
"due_date": null,
"ending_balance": null,
+ "finalized_at": null,
"footer": null,
"hosted_invoice_url": null,
"id": "in_NORMALIZED00000000000001",
"invoice_pdf": null,
+ "last_finalization_error": null,
"lines": {
"data": [
{
"amount": 7200,
"currency": "usd",
"description": "Zulip Standard",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000001",
"invoice_item": "ii_NORMALIZED00000000000001",
"livemode": false,
@@ -51,18 +58,40 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhsD2X8vgpBNGtyNs4AI9",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh67i06KRHwdX",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1200,
+ "unit_amount_decimal": "1200"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhsD2X8vgpBNGtA08rM3i"
},
{
"amount": -7200,
"currency": "usd",
"description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000002",
"invoice_item": "ii_NORMALIZED00000000000002",
"livemode": false,
@@ -73,12 +102,32 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhrD2X8vgpBNGD9sFn8tJ",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pGP4ldOFFV",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -7200,
+ "unit_amount_decimal": "-7200"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhrD2X8vgpBNGf4QcWhh8"
}
],
"has_more": false,
@@ -112,6 +161,8 @@
"tax": null,
"tax_percent": null,
"total": 0,
+ "total_discount_amounts": [],
"total_tax_amounts": [],
+ "transfer_data": null,
"webhooks_delivered_at": null
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.2.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.2.json
index 24357e19730..ad972d1b156 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.2.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.2.json
@@ -1,10 +1,11 @@
{
"account_country": "US",
- "account_name": "Dev account",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
"amount_due": 0,
"amount_paid": 0,
"amount_remaining": 0,
- "application_fee_amount": null,
+ "application_fee": null,
"attempt_count": 0,
"attempted": false,
"auto_advance": true,
@@ -23,46 +24,74 @@
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
+ "date": 1000000000,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
- "description": "",
+ "description": null,
"discount": null,
+ "discounts": [],
"due_date": null,
"ending_balance": null,
+ "finalized_at": null,
"footer": null,
"hosted_invoice_url": null,
"id": "in_NORMALIZED00000000000002",
"invoice_pdf": null,
+ "last_finalization_error": null,
"lines": {
"data": [
{
"amount": 36000,
"currency": "usd",
"description": "Zulip Standard",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000003",
"invoice_item": "ii_NORMALIZED00000000000003",
"livemode": false,
"metadata": {},
"object": "line_item",
"period": {
- "end": 1000000000,
- "start": 1000000000
+ "end": 1357095845,
+ "start": 1325473445
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhzD2X8vgpBNGlpQImV07",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6VKlEd957ap",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 6000,
+ "unit_amount_decimal": "6000"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhzD2X8vgpBNGwPaEObnC"
},
{
"amount": -36000,
"currency": "usd",
"description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000004",
"invoice_item": "ii_NORMALIZED00000000000004",
"livemode": false,
@@ -73,12 +102,32 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhyD2X8vgpBNG58auoETW",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6Yrwv6xv7Bm",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -36000,
+ "unit_amount_decimal": "-36000"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhyD2X8vgpBNGQAOpJ22e"
}
],
"has_more": false,
@@ -112,6 +161,8 @@
"tax": null,
"tax_percent": null,
"total": 0,
+ "total_discount_amounts": [],
"total_tax_amounts": [],
+ "transfer_data": null,
"webhooks_delivered_at": null
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.3.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.3.json
new file mode 100644
index 00000000000..ab63d5de42f
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.create.3.json
@@ -0,0 +1,124 @@
+{
+ "account_country": "US",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
+ "amount_due": 24000,
+ "amount_paid": 0,
+ "amount_remaining": 24000,
+ "application_fee": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "billing": "charge_automatically",
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "date": 1000000000,
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "ending_balance": null,
+ "finalized_at": null,
+ "footer": null,
+ "hosted_invoice_url": null,
+ "id": "in_NORMALIZED00000000000003",
+ "invoice_pdf": null,
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 24000,
+ "currency": "usd",
+ "description": "Zulip Standard - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000005",
+ "invoice_item": "ii_NORMALIZED00000000000005",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1388631845,
+ "start": 1357095845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1Hufi2D2X8vgpBNGLrDQYzwi",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pB9D73emPf",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 4000,
+ "unit_amount_decimal": "4000"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unique_id": "il_1Hufi2D2X8vgpBNGj13daEPu"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000003/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1000000000,
+ "number": "NORMALI-0003",
+ "object": "invoice",
+ "paid": false,
+ "payment_intent": null,
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "receipt_number": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Standard",
+ "status": "draft",
+ "status_transitions": {
+ "finalized_at": null,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 24000,
+ "tax": null,
+ "tax_percent": null,
+ "total": 24000,
+ "total_discount_amounts": [],
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.1.json
index efab3b8fb04..64eb5442ccc 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.1.json
@@ -1,10 +1,11 @@
{
"account_country": "US",
- "account_name": "Dev account",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
"amount_due": 0,
"amount_paid": 0,
"amount_remaining": 0,
- "application_fee_amount": null,
+ "application_fee": null,
"attempt_count": 0,
"attempted": true,
"auto_advance": false,
@@ -23,24 +24,30 @@
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
+ "date": 1000000000,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
- "description": "",
+ "description": null,
"discount": null,
- "due_date": 1000000000,
+ "discounts": [],
+ "due_date": null,
"ending_balance": 0,
+ "finalized_at": 1000000000,
"footer": null,
- "hosted_invoice_url": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000001",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq",
"id": "in_NORMALIZED00000000000001",
- "invoice_pdf": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000001/pdf",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq/pdf",
+ "last_finalization_error": null,
"lines": {
"data": [
{
"amount": 7200,
"currency": "usd",
"description": "Zulip Standard",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000001",
"invoice_item": "ii_NORMALIZED00000000000001",
"livemode": false,
@@ -51,18 +58,40 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhsD2X8vgpBNGtyNs4AI9",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh67i06KRHwdX",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1200,
+ "unit_amount_decimal": "1200"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhsD2X8vgpBNGtA08rM3i"
},
{
"amount": -7200,
"currency": "usd",
"description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000002",
"invoice_item": "ii_NORMALIZED00000000000002",
"livemode": false,
@@ -73,12 +102,32 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhrD2X8vgpBNGD9sFn8tJ",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pGP4ldOFFV",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -7200,
+ "unit_amount_decimal": "-7200"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhrD2X8vgpBNGf4QcWhh8"
}
],
"has_more": false,
@@ -112,6 +161,8 @@
"tax": null,
"tax_percent": null,
"total": 0,
+ "total_discount_amounts": [],
"total_tax_amounts": [],
- "webhooks_delivered_at": 1000000000
+ "transfer_data": null,
+ "webhooks_delivered_at": null
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.2.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.2.json
index ed04f0e832c..3266fdddb14 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.2.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.2.json
@@ -1,10 +1,11 @@
{
"account_country": "US",
- "account_name": "Dev account",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
"amount_due": 0,
"amount_paid": 0,
"amount_remaining": 0,
- "application_fee_amount": null,
+ "application_fee": null,
"attempt_count": 0,
"attempted": true,
"auto_advance": false,
@@ -23,46 +24,74 @@
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
+ "date": 1000000000,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
- "description": "",
+ "description": null,
"discount": null,
- "due_date": 1000000000,
+ "discounts": [],
+ "due_date": null,
"ending_balance": 0,
+ "finalized_at": 1000000000,
"footer": null,
- "hosted_invoice_url": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000002",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED0000000000000002TO6zL",
"id": "in_NORMALIZED00000000000002",
- "invoice_pdf": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000002/pdf",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED0000000000000002TO6zL/pdf",
+ "last_finalization_error": null,
"lines": {
"data": [
{
"amount": 36000,
"currency": "usd",
"description": "Zulip Standard",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000003",
"invoice_item": "ii_NORMALIZED00000000000003",
"livemode": false,
"metadata": {},
"object": "line_item",
"period": {
- "end": 1000000000,
- "start": 1000000000
+ "end": 1357095845,
+ "start": 1325473445
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhzD2X8vgpBNGlpQImV07",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6VKlEd957ap",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 6000,
+ "unit_amount_decimal": "6000"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhzD2X8vgpBNGwPaEObnC"
},
{
"amount": -36000,
"currency": "usd",
"description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000004",
"invoice_item": "ii_NORMALIZED00000000000004",
"livemode": false,
@@ -73,12 +102,32 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhyD2X8vgpBNG58auoETW",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6Yrwv6xv7Bm",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -36000,
+ "unit_amount_decimal": "-36000"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhyD2X8vgpBNGQAOpJ22e"
}
],
"has_more": false,
@@ -112,6 +161,8 @@
"tax": null,
"tax_percent": null,
"total": 0,
+ "total_discount_amounts": [],
"total_tax_amounts": [],
- "webhooks_delivered_at": 1000000000
+ "transfer_data": null,
+ "webhooks_delivered_at": null
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.3.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.3.json
new file mode 100644
index 00000000000..fe307718afe
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.finalize_invoice.3.json
@@ -0,0 +1,124 @@
+{
+ "account_country": "US",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
+ "amount_due": 24000,
+ "amount_paid": 0,
+ "amount_remaining": 24000,
+ "application_fee": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "billing": "charge_automatically",
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "date": 1000000000,
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "ending_balance": 0,
+ "finalized_at": 1000000000,
+ "footer": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED00000000000000039Nm5X",
+ "id": "in_NORMALIZED00000000000003",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED00000000000000039Nm5X/pdf",
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 24000,
+ "currency": "usd",
+ "description": "Zulip Standard - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000005",
+ "invoice_item": "ii_NORMALIZED00000000000005",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1388631845,
+ "start": 1357095845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1Hufi2D2X8vgpBNGLrDQYzwi",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pB9D73emPf",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 4000,
+ "unit_amount_decimal": "4000"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unique_id": "il_1Hufi2D2X8vgpBNGj13daEPu"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000003/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1000000000,
+ "number": "NORMALI-0003",
+ "object": "invoice",
+ "paid": false,
+ "payment_intent": "pi_1Hufi3D2X8vgpBNGmAdVFaWD",
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "receipt_number": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 24000,
+ "tax": null,
+ "tax_percent": null,
+ "total": 24000,
+ "total_discount_amounts": [],
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.1.json
index d5a7c6c2628..acdd6e51e89 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.1.json
@@ -2,11 +2,12 @@
"data": [
{
"account_country": "US",
- "account_name": "Dev account",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
"amount_due": 0,
"amount_paid": 0,
"amount_remaining": 0,
- "application_fee_amount": null,
+ "application_fee": null,
"attempt_count": 0,
"attempted": true,
"auto_advance": false,
@@ -25,24 +26,30 @@
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
+ "date": 1000000000,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
- "description": "",
+ "description": null,
"discount": null,
- "due_date": 1000000000,
+ "discounts": [],
+ "due_date": null,
"ending_balance": 0,
+ "finalized_at": 1000000000,
"footer": null,
- "hosted_invoice_url": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000001",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq",
"id": "in_NORMALIZED00000000000001",
- "invoice_pdf": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000001/pdf",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq/pdf",
+ "last_finalization_error": null,
"lines": {
"data": [
{
"amount": 7200,
"currency": "usd",
"description": "Zulip Standard",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000001",
"invoice_item": "ii_NORMALIZED00000000000001",
"livemode": false,
@@ -53,18 +60,40 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhsD2X8vgpBNGtyNs4AI9",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh67i06KRHwdX",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1200,
+ "unit_amount_decimal": "1200"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhsD2X8vgpBNGtA08rM3i"
},
{
"amount": -7200,
"currency": "usd",
"description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000002",
"invoice_item": "ii_NORMALIZED00000000000002",
"livemode": false,
@@ -75,12 +104,32 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhrD2X8vgpBNGD9sFn8tJ",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pGP4ldOFFV",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -7200,
+ "unit_amount_decimal": "-7200"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhrD2X8vgpBNGf4QcWhh8"
}
],
"has_more": false,
@@ -114,7 +163,9 @@
"tax": null,
"tax_percent": null,
"total": 0,
+ "total_discount_amounts": [],
"total_tax_amounts": [],
+ "transfer_data": null,
"webhooks_delivered_at": 1000000000
}
],
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.2.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.2.json
index 3fa8b786ad8..0fe097a5661 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.2.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.2.json
@@ -2,11 +2,12 @@
"data": [
{
"account_country": "US",
- "account_name": "Dev account",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
"amount_due": 0,
"amount_paid": 0,
"amount_remaining": 0,
- "application_fee_amount": null,
+ "application_fee": null,
"attempt_count": 0,
"attempted": true,
"auto_advance": false,
@@ -25,46 +26,74 @@
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
+ "date": 1000000000,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
- "description": "",
+ "description": null,
"discount": null,
- "due_date": 1000000000,
+ "discounts": [],
+ "due_date": null,
"ending_balance": 0,
+ "finalized_at": 1000000000,
"footer": null,
- "hosted_invoice_url": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000002",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED0000000000000002TO6zL",
"id": "in_NORMALIZED00000000000002",
- "invoice_pdf": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000002/pdf",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED0000000000000002TO6zL/pdf",
+ "last_finalization_error": null,
"lines": {
"data": [
{
"amount": 36000,
"currency": "usd",
"description": "Zulip Standard",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000003",
"invoice_item": "ii_NORMALIZED00000000000003",
"livemode": false,
"metadata": {},
"object": "line_item",
"period": {
- "end": 1000000000,
- "start": 1000000000
+ "end": 1357095845,
+ "start": 1325473445
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhzD2X8vgpBNGlpQImV07",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6VKlEd957ap",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 6000,
+ "unit_amount_decimal": "6000"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhzD2X8vgpBNGwPaEObnC"
},
{
"amount": -36000,
"currency": "usd",
"description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000004",
"invoice_item": "ii_NORMALIZED00000000000004",
"livemode": false,
@@ -75,12 +104,32 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhyD2X8vgpBNG58auoETW",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6Yrwv6xv7Bm",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -36000,
+ "unit_amount_decimal": "-36000"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhyD2X8vgpBNGQAOpJ22e"
}
],
"has_more": false,
@@ -114,16 +163,19 @@
"tax": null,
"tax_percent": null,
"total": 0,
+ "total_discount_amounts": [],
"total_tax_amounts": [],
- "webhooks_delivered_at": 1000000000
+ "transfer_data": null,
+ "webhooks_delivered_at": null
},
{
"account_country": "US",
- "account_name": "Dev account",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
"amount_due": 0,
"amount_paid": 0,
"amount_remaining": 0,
- "application_fee_amount": null,
+ "application_fee": null,
"attempt_count": 0,
"attempted": true,
"auto_advance": false,
@@ -142,24 +194,30 @@
"customer_shipping": null,
"customer_tax_exempt": "none",
"customer_tax_ids": [],
+ "date": 1000000000,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [],
- "description": "",
+ "description": null,
"discount": null,
- "due_date": 1000000000,
+ "discounts": [],
+ "due_date": null,
"ending_balance": 0,
+ "finalized_at": 1000000000,
"footer": null,
- "hosted_invoice_url": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000001",
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq",
"id": "in_NORMALIZED00000000000001",
- "invoice_pdf": "https://pay.stripe.com/invoice/invst_NORMALIZED0000000000000001/pdf",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq/pdf",
+ "last_finalization_error": null,
"lines": {
"data": [
{
"amount": 7200,
"currency": "usd",
"description": "Zulip Standard",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000001",
"invoice_item": "ii_NORMALIZED00000000000001",
"livemode": false,
@@ -170,18 +228,40 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhsD2X8vgpBNGtyNs4AI9",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh67i06KRHwdX",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1200,
+ "unit_amount_decimal": "1200"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhsD2X8vgpBNGtA08rM3i"
},
{
"amount": -7200,
"currency": "usd",
"description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000002",
"invoice_item": "ii_NORMALIZED00000000000002",
"livemode": false,
@@ -192,12 +272,32 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhrD2X8vgpBNGD9sFn8tJ",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pGP4ldOFFV",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -7200,
+ "unit_amount_decimal": "-7200"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_amounts": [],
"tax_rates": [],
- "type": "invoiceitem"
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhrD2X8vgpBNGf4QcWhh8"
}
],
"has_more": false,
@@ -231,7 +331,9 @@
"tax": null,
"tax_percent": null,
"total": 0,
+ "total_discount_amounts": [],
"total_tax_amounts": [],
+ "transfer_data": null,
"webhooks_delivered_at": 1000000000
}
],
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.3.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.3.json
new file mode 100644
index 00000000000..b4c33382282
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--Invoice.list.3.json
@@ -0,0 +1,467 @@
+{
+ "data": [
+ {
+ "account_country": "US",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
+ "amount_due": 24000,
+ "amount_paid": 0,
+ "amount_remaining": 24000,
+ "application_fee": null,
+ "attempt_count": 0,
+ "attempted": false,
+ "auto_advance": true,
+ "billing": "charge_automatically",
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "date": 1000000000,
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "ending_balance": 0,
+ "finalized_at": 1000000000,
+ "footer": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED00000000000000039Nm5X",
+ "id": "in_NORMALIZED00000000000003",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED00000000000000039Nm5X/pdf",
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 24000,
+ "currency": "usd",
+ "description": "Zulip Standard - renewal",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000005",
+ "invoice_item": "ii_NORMALIZED00000000000005",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1388631845,
+ "start": 1357095845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1Hufi2D2X8vgpBNGLrDQYzwi",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pB9D73emPf",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 4000,
+ "unit_amount_decimal": "4000"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unique_id": "il_1Hufi2D2X8vgpBNGj13daEPu"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 1,
+ "url": "/v1/invoices/in_NORMALIZED00000000000003/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": 1000000000,
+ "number": "NORMALI-0003",
+ "object": "invoice",
+ "paid": false,
+ "payment_intent": "pi_1Hufi3D2X8vgpBNGmAdVFaWD",
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "receipt_number": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Standard",
+ "status": "open",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": null,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 24000,
+ "tax": null,
+ "tax_percent": null,
+ "total": 24000,
+ "total_discount_amounts": [],
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": null
+ },
+ {
+ "account_country": "US",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
+ "amount_due": 0,
+ "amount_paid": 0,
+ "amount_remaining": 0,
+ "application_fee": null,
+ "attempt_count": 0,
+ "attempted": true,
+ "auto_advance": false,
+ "billing": "charge_automatically",
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "date": 1000000000,
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "ending_balance": 0,
+ "finalized_at": 1000000000,
+ "footer": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED0000000000000002TO6zL",
+ "id": "in_NORMALIZED00000000000002",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED0000000000000002TO6zL/pdf",
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 36000,
+ "currency": "usd",
+ "description": "Zulip Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000003",
+ "invoice_item": "ii_NORMALIZED00000000000003",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1357095845,
+ "start": 1325473445
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhzD2X8vgpBNGlpQImV07",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6VKlEd957ap",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 6000,
+ "unit_amount_decimal": "6000"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhzD2X8vgpBNGwPaEObnC"
+ },
+ {
+ "amount": -36000,
+ "currency": "usd",
+ "description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000004",
+ "invoice_item": "ii_NORMALIZED00000000000004",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhyD2X8vgpBNG58auoETW",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6Yrwv6xv7Bm",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -36000,
+ "unit_amount_decimal": "-36000"
+ },
+ "proration": false,
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhyD2X8vgpBNGQAOpJ22e"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_NORMALIZED00000000000002/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0002",
+ "object": "invoice",
+ "paid": true,
+ "payment_intent": null,
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "receipt_number": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Standard",
+ "status": "paid",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": 1000000000,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 0,
+ "tax": null,
+ "tax_percent": null,
+ "total": 0,
+ "total_discount_amounts": [],
+ "total_tax_amounts": [],
+ "transfer_data": null,
+ "webhooks_delivered_at": 1000000000
+ },
+ {
+ "account_country": "US",
+ "account_name": "Vishnu Test",
+ "account_tax_ids": null,
+ "amount_due": 0,
+ "amount_paid": 0,
+ "amount_remaining": 0,
+ "application_fee": null,
+ "attempt_count": 0,
+ "attempted": true,
+ "auto_advance": false,
+ "billing": "charge_automatically",
+ "billing_reason": "manual",
+ "charge": null,
+ "collection_method": "charge_automatically",
+ "created": 1000000000,
+ "currency": "usd",
+ "custom_fields": null,
+ "customer": "cus_NORMALIZED0001",
+ "customer_address": null,
+ "customer_email": "[email protected]",
+ "customer_name": null,
+ "customer_phone": null,
+ "customer_shipping": null,
+ "customer_tax_exempt": "none",
+ "customer_tax_ids": [],
+ "date": 1000000000,
+ "default_payment_method": null,
+ "default_source": null,
+ "default_tax_rates": [],
+ "description": null,
+ "discount": null,
+ "discounts": [],
+ "due_date": null,
+ "ending_balance": 0,
+ "finalized_at": 1000000000,
+ "footer": null,
+ "hosted_invoice_url": "https://invoice.stripe.com/i/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq",
+ "id": "in_NORMALIZED00000000000001",
+ "invoice_pdf": "https://pay.stripe.com/invoice/acct_NORMALIZED000001/invst_NORMALIZED0000000000000001jwmXq/pdf",
+ "last_finalization_error": null,
+ "lines": {
+ "data": [
+ {
+ "amount": 7200,
+ "currency": "usd",
+ "description": "Zulip Standard",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_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_1HufhsD2X8vgpBNGtyNs4AI9",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh67i06KRHwdX",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1200,
+ "unit_amount_decimal": "1200"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhsD2X8vgpBNGtA08rM3i"
+ },
+ {
+ "amount": -7200,
+ "currency": "usd",
+ "description": "Payment (Card ending in 4242)",
+ "discount_amounts": [],
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000002",
+ "invoice_item": "ii_NORMALIZED00000000000002",
+ "livemode": false,
+ "metadata": {},
+ "object": "line_item",
+ "period": {
+ "end": 1000000000,
+ "start": 1000000000
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhrD2X8vgpBNGD9sFn8tJ",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pGP4ldOFFV",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -7200,
+ "unit_amount_decimal": "-7200"
+ },
+ "proration": false,
+ "quantity": 1,
+ "subscription": null,
+ "tax_amounts": [],
+ "tax_rates": [],
+ "type": "invoiceitem",
+ "unique_id": "il_1HufhrD2X8vgpBNGf4QcWhh8"
+ }
+ ],
+ "has_more": false,
+ "object": "list",
+ "total_count": 2,
+ "url": "/v1/invoices/in_NORMALIZED00000000000001/lines"
+ },
+ "livemode": false,
+ "metadata": {},
+ "next_payment_attempt": null,
+ "number": "NORMALI-0001",
+ "object": "invoice",
+ "paid": true,
+ "payment_intent": null,
+ "period_end": 1000000000,
+ "period_start": 1000000000,
+ "post_payment_credit_notes_amount": 0,
+ "pre_payment_credit_notes_amount": 0,
+ "receipt_number": null,
+ "starting_balance": 0,
+ "statement_descriptor": "Zulip Standard",
+ "status": "paid",
+ "status_transitions": {
+ "finalized_at": 1000000000,
+ "marked_uncollectible_at": null,
+ "paid_at": 1000000000,
+ "voided_at": null
+ },
+ "subscription": null,
+ "subtotal": 0,
+ "tax": null,
+ "tax_percent": null,
+ "total": 0,
+ "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/attach_discount_to_realm--InvoiceItem.create.1.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.1.json
index e88a681240f..4c81ac4cb9b 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.1.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.1.json
@@ -5,6 +5,7 @@
"date": 1000000000,
"description": "Payment (Card ending in 4242)",
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000002",
"invoice": null,
"livemode": false,
@@ -15,9 +16,29 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhrD2X8vgpBNGD9sFn8tJ",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pGP4ldOFFV",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -7200,
+ "unit_amount_decimal": "-7200"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_rates": [],
- "unit_amount": -7200
+ "unit_amount": -7200,
+ "unit_amount_decimal": "-7200"
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.2.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.2.json
index a3baff2625d..047cc89ffd9 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.2.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.2.json
@@ -5,6 +5,7 @@
"date": 1000000000,
"description": "Zulip Standard",
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000001",
"invoice": null,
"livemode": false,
@@ -15,9 +16,29 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhsD2X8vgpBNGtyNs4AI9",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh67i06KRHwdX",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 1200,
+ "unit_amount_decimal": "1200"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_rates": [],
- "unit_amount": 1200
+ "unit_amount": 1200,
+ "unit_amount_decimal": "1200"
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.3.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.3.json
index d6f3b3dbff0..03119d59cc6 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.3.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.3.json
@@ -5,6 +5,7 @@
"date": 1000000000,
"description": "Payment (Card ending in 4242)",
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000004",
"invoice": null,
"livemode": false,
@@ -15,9 +16,29 @@
"start": 1000000000
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhyD2X8vgpBNG58auoETW",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6Yrwv6xv7Bm",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": -36000,
+ "unit_amount_decimal": "-36000"
+ },
"proration": false,
"quantity": 1,
"subscription": null,
"tax_rates": [],
- "unit_amount": -36000
+ "unit_amount": -36000,
+ "unit_amount_decimal": "-36000"
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.4.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.4.json
index cef488c7832..7274176f8b8 100644
--- a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.4.json
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.4.json
@@ -5,19 +5,40 @@
"date": 1000000000,
"description": "Zulip Standard",
"discountable": false,
+ "discounts": [],
"id": "ii_NORMALIZED00000000000003",
"invoice": null,
"livemode": false,
"metadata": {},
"object": "invoiceitem",
"period": {
- "end": 1000000000,
- "start": 1000000000
+ "end": 1357095845,
+ "start": 1325473445
},
"plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1HufhzD2X8vgpBNGlpQImV07",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6VKlEd957ap",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 6000,
+ "unit_amount_decimal": "6000"
+ },
"proration": false,
"quantity": 6,
"subscription": null,
"tax_rates": [],
- "unit_amount": 6000
+ "unit_amount": 6000,
+ "unit_amount_decimal": "6000"
}
diff --git a/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.5.json b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.5.json
new file mode 100644
index 00000000000..7b09fad905f
--- /dev/null
+++ b/corporate/tests/stripe_fixtures/attach_discount_to_realm--InvoiceItem.create.5.json
@@ -0,0 +1,44 @@
+{
+ "amount": 24000,
+ "currency": "usd",
+ "customer": "cus_NORMALIZED0001",
+ "date": 1000000000,
+ "description": "Zulip Standard - renewal",
+ "discountable": false,
+ "discounts": [],
+ "id": "ii_NORMALIZED00000000000005",
+ "invoice": null,
+ "livemode": false,
+ "metadata": {},
+ "object": "invoiceitem",
+ "period": {
+ "end": 1388631845,
+ "start": 1357095845
+ },
+ "plan": null,
+ "price": {
+ "active": false,
+ "billing_scheme": "per_unit",
+ "created": 1000000000,
+ "currency": "usd",
+ "id": "price_1Hufi2D2X8vgpBNGLrDQYzwi",
+ "livemode": false,
+ "lookup_key": null,
+ "metadata": {},
+ "nickname": null,
+ "object": "price",
+ "product": "prod_IVh6pB9D73emPf",
+ "recurring": null,
+ "tiers_mode": null,
+ "transform_quantity": null,
+ "type": "one_time",
+ "unit_amount": 4000,
+ "unit_amount_decimal": "4000"
+ },
+ "proration": false,
+ "quantity": 6,
+ "subscription": null,
+ "tax_rates": [],
+ "unit_amount": 4000,
+ "unit_amount_decimal": "4000"
+}
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index fd63e6ca937..1ca62aa08e6 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -1244,10 +1244,10 @@ class StripeTest(StripeTestCase):
self.assert_in_success_response(['85'], self.client_get("/upgrade/"))
# Check that the customer was charged the discounted amount
self.upgrade()
- stripe_customer_id = Customer.objects.values_list('stripe_customer_id', flat=True).first()
- [charge] = stripe.Charge.list(customer=stripe_customer_id)
+ customer = Customer.objects.first()
+ [charge] = stripe.Charge.list(customer=customer.stripe_customer_id)
self.assertEqual(1200 * self.seat_count, charge.amount)
- [invoice] = stripe.Invoice.list(customer=stripe_customer_id)
+ [invoice] = stripe.Invoice.list(customer=customer.stripe_customer_id)
self.assertEqual([1200 * self.seat_count, -1200 * self.seat_count],
[item.amount for item in invoice.lines])
# Check CustomerPlan reflects the discount
@@ -1257,14 +1257,26 @@ class StripeTest(StripeTestCase):
plan.status = CustomerPlan.ENDED
plan.save(update_fields=['status'])
attach_discount_to_realm(user.realm, Decimal(25))
- process_initial_upgrade(user, self.seat_count, True, CustomerPlan.ANNUAL, stripe_create_token().id)
- [charge0, charge1] = stripe.Charge.list(customer=stripe_customer_id)
- self.assertEqual(6000 * self.seat_count, charge0.amount)
- [invoice0, invoice1] = stripe.Invoice.list(customer=stripe_customer_id)
+ with patch('corporate.lib.stripe.timezone_now', return_value=self.now):
+ process_initial_upgrade(user, self.seat_count, True, CustomerPlan.ANNUAL, stripe_create_token().id)
+ [charge, _] = stripe.Charge.list(customer=customer.stripe_customer_id)
+ self.assertEqual(6000 * self.seat_count, charge.amount)
+ [invoice, _] = stripe.Invoice.list(customer=customer.stripe_customer_id)
self.assertEqual([6000 * self.seat_count, -6000 * self.seat_count],
- [item.amount for item in invoice0.lines])
+ [item.amount for item in invoice.lines])
plan = CustomerPlan.objects.get(price_per_license=6000, discount=Decimal(25))
+ attach_discount_to_realm(user.realm, Decimal(50))
+ plan.refresh_from_db()
+ self.assertEqual(plan.price_per_license, 4000)
+ self.assertEqual(plan.discount, 50)
+ customer.refresh_from_db()
+ self.assertEqual(customer.default_discount, 50)
+ invoice_plans_as_needed(self.next_year + timedelta(days=10))
+ [invoice, _, _] = stripe.Invoice.list(customer=customer.stripe_customer_id)
+ self.assertEqual([4000 * self.seat_count],
+ [item.amount for item in invoice.lines])
+
def test_get_discount_for_realm(self) -> None:
user = self.example_user('hamlet')
self.assertEqual(get_discount_for_realm(user.realm), None)