mirror of https://github.com/zulip/zulip.git
stripe: Add assertions to fix errors flagged by mypy 1.10.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
b195dc5a89
commit
31c7b2bfd7
|
@ -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,
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue