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.

stripe: Add assertions to fix errors flagged by mypy 1.10.

Anders Kaseorg31c7b2bfd7f9
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 4b6d71fa1da..62cae5239da 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -3092,6 +3092,7 @@ class BillingSession(ABC):
licenses_base = ledger_entry.licenses
if invoice_item_created:
+ assert invoice_period is not None
flat_discount, flat_discounted_months = self.get_flat_discount_info(plan.customer)
if plan.fixed_price is None and flat_discounted_months > 0:
num_months = (
@@ -3442,14 +3443,19 @@ class BillingSession(ABC):
# the updated quantity.
stripe_invoice = stripe.Invoice.retrieve(last_sent_invoice.stripe_invoice_id)
assert stripe_invoice.status == "open"
+ assert isinstance(stripe_invoice.customer, str)
+ assert stripe_invoice.statement_descriptor is not None
+ assert stripe_invoice.metadata is not None
invoice_items = stripe_invoice.lines.data
# Stripe does something weird and puts the discount item first, so we need to reverse the order here.
invoice_items.reverse()
for invoice_item in invoice_items:
+ assert invoice_item.description is not None
price_args: PriceArgs = {}
# If amount is positive, this must be non-discount item we need to update.
if invoice_item.amount > 0:
assert invoice_item.price is not None
+ assert invoice_item.price.unit_amount is not None
price_args = {
"quantity": licenses,
"unit_amount": invoice_item.price.unit_amount,
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 8da4e41ac9e..bbb546e9ad5 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -16,6 +16,7 @@ from typing import (
Callable,
Dict,
List,
+ Literal,
Mapping,
Optional,
Sequence,
@@ -524,13 +525,19 @@ class StripeTestCase(ZulipTestCase):
},
},
)
+ assert isinstance(checkout_setup_intent.customer, str)
+ assert checkout_setup_intent.metadata is not None
+ assert checkout_setup_intent.usage in {"off_session", "on_session"}
+ usage = cast(
+ Literal["off_session", "on_session"], checkout_setup_intent.usage
+ ) # https://github.com/python/mypy/issues/12535
stripe_setup_intent = stripe.SetupIntent.create(
payment_method=payment_method.id,
confirm=True,
payment_method_types=checkout_setup_intent.payment_method_types,
customer=checkout_setup_intent.customer,
metadata=checkout_setup_intent.metadata,
- usage=checkout_setup_intent.usage,
+ usage=usage,
)
[stripe_session] = iter(stripe.checkout.Session.list(customer=customer_stripe_id, limit=1))
stripe_session_dict = orjson.loads(orjson.dumps(stripe_session))