mirror of https://github.com/zulip/zulip.git
mypy: Add types-stripe.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
de1df81ef6
commit
8d9fe9cfb0
|
@ -15,6 +15,7 @@ from unittest.mock import Mock, patch
|
|||
import orjson
|
||||
import responses
|
||||
import stripe
|
||||
import stripe.util
|
||||
from django.conf import settings
|
||||
from django.core import signing
|
||||
from django.http import HttpResponse
|
||||
|
@ -190,7 +191,7 @@ def read_stripe_fixture(
|
|||
requestor.interpret_response(
|
||||
fixture["http_body"], fixture["http_status"], fixture["headers"]
|
||||
)
|
||||
return stripe.util.convert_to_stripe_object(fixture)
|
||||
return stripe.util.convert_to_stripe_object(fixture) # type: ignore[attr-defined] # missing from stubs
|
||||
|
||||
return _read_stripe_fixture
|
||||
|
||||
|
@ -3773,9 +3774,7 @@ class StripeTest(StripeTestCase):
|
|||
# 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
|
||||
)
|
||||
_, cb_txn = stripe.Customer.list_balance_transactions(stripe_customer_id)
|
||||
self.assertEqual(cb_txn.amount, -7200)
|
||||
self.assertEqual(
|
||||
cb_txn.description,
|
||||
|
|
|
@ -2016,6 +2016,10 @@ types-six==1.16.10 \
|
|||
# via
|
||||
# -r requirements/mypy.in
|
||||
# types-boto
|
||||
types-stripe==2.59.4 \
|
||||
--hash=sha256:4c83320ff7b5f88eb2fec94114709d6af6439bdb31a2fc1ec2f4b197b1716e30 \
|
||||
--hash=sha256:e38aaba73806ec5ab4b0861ec43e4d24cec94793d80bdef9e414a7268ae2aef1
|
||||
# via -r requirements/mypy.in
|
||||
types-urllib3==1.26.7 \
|
||||
--hash=sha256:3adcf2cb5981809091dbff456e6999fe55f201652d8c360f99997de5ac2f556e \
|
||||
--hash=sha256:cfd1fbbe4ba9a605ed148294008aac8a7b8b7472651d1cc357d507ae5962e3d2
|
||||
|
|
|
@ -28,5 +28,6 @@ types-PyYAML
|
|||
types-redis
|
||||
types-requests
|
||||
types-six
|
||||
types-stripe
|
||||
|
||||
importlib-metadata;python_version<"3.10" # for sqlalchemy
|
||||
|
|
|
@ -274,6 +274,10 @@ types-six==1.16.10 \
|
|||
# via
|
||||
# -r requirements/mypy.in
|
||||
# types-boto
|
||||
types-stripe==2.59.4 \
|
||||
--hash=sha256:4c83320ff7b5f88eb2fec94114709d6af6439bdb31a2fc1ec2f4b197b1716e30 \
|
||||
--hash=sha256:e38aaba73806ec5ab4b0861ec43e4d24cec94793d80bdef9e414a7268ae2aef1
|
||||
# via -r requirements/mypy.in
|
||||
types-urllib3==1.26.7 \
|
||||
--hash=sha256:3adcf2cb5981809091dbff456e6999fe55f201652d8c360f99997de5ac2f556e \
|
||||
--hash=sha256:cfd1fbbe4ba9a605ed148294008aac8a7b8b7472651d1cc357d507ae5962e3d2
|
||||
|
|
|
@ -1,334 +0,0 @@
|
|||
# See https://zulip.readthedocs.io/en/latest/testing/mypy.html#mypy-stubs-for-third-party-modules
|
||||
# for notes on how we manage mypy stubs.
|
||||
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
import stripe.api_requestor as api_requestor
|
||||
import stripe.error as error
|
||||
import stripe.util as util
|
||||
from stripe.api_resources.list_object import SubscriptionListObject
|
||||
from stripe.checkout import Session
|
||||
from typing_extensions import Literal
|
||||
|
||||
api_key: Optional[str]
|
||||
|
||||
class InvoiceSettings:
|
||||
custom_field: List[str]
|
||||
default_payment_method: Optional[PaymentMethod]
|
||||
footer: str
|
||||
|
||||
class Customer:
|
||||
default_source: Union[Card, Source]
|
||||
created: int
|
||||
id: str
|
||||
source: str
|
||||
sources: List[Union[Card, Source]]
|
||||
subscriptions: SubscriptionListObject
|
||||
coupon: str
|
||||
balance: int
|
||||
email: str
|
||||
description: str
|
||||
discount: Optional[Discount]
|
||||
metadata: Dict[str, str]
|
||||
invoice_settings: InvoiceSettings
|
||||
@staticmethod
|
||||
def retrieve(customer_id: str = ..., expand: Optional[List[str]] = ...) -> Customer: ...
|
||||
@staticmethod
|
||||
def create(
|
||||
description: str = ...,
|
||||
email: str = ...,
|
||||
metadata: Dict[str, Any] = ...,
|
||||
payment_method: Optional[str] = ...,
|
||||
coupon: Optional[str] = ...,
|
||||
) -> Customer: ...
|
||||
@staticmethod
|
||||
def modify(customer_id: str, invoice_settings: Dict[str, Any]) -> Customer:
|
||||
pass
|
||||
@staticmethod
|
||||
def save(customer: Customer) -> Customer: ...
|
||||
@staticmethod
|
||||
def delete_discount(customer: Customer) -> None: ...
|
||||
@staticmethod
|
||||
def list(limit: Optional[int] = ...) -> List[Customer]: ...
|
||||
@staticmethod
|
||||
def create_balance_transaction(
|
||||
customer_id: str, amount: int, currency: str, description: str
|
||||
) -> None: ...
|
||||
def refresh(self, customer: Customer) -> Customer: ...
|
||||
|
||||
class Invoice:
|
||||
id: str
|
||||
auto_advance: bool
|
||||
amount_due: int
|
||||
collection_method: str
|
||||
billing_reason: str
|
||||
default_source: Source
|
||||
due_date: int
|
||||
lines: List[InvoiceLineItem]
|
||||
status: str
|
||||
status_transitions: Any
|
||||
total: int
|
||||
@staticmethod
|
||||
def upcoming(
|
||||
customer: str = ...,
|
||||
subscription: str = ...,
|
||||
subscription_items: List[Dict[str, Union[str, int]]] = ...,
|
||||
) -> Invoice: ...
|
||||
@staticmethod
|
||||
def list(
|
||||
collection_method: str = ...,
|
||||
customer: str = ...,
|
||||
status: str = ...,
|
||||
limit: Optional[int] = ...,
|
||||
starting_after: Optional[Invoice] = ...,
|
||||
) -> List[Invoice]: ...
|
||||
@staticmethod
|
||||
def create(
|
||||
auto_advance: bool = ...,
|
||||
collection_method: str = ...,
|
||||
customer: str = ...,
|
||||
days_until_due: Optional[int] = ...,
|
||||
statement_descriptor: str = ...,
|
||||
) -> Invoice: ...
|
||||
@staticmethod
|
||||
def finalize_invoice(invoice: Invoice) -> Invoice: ...
|
||||
@staticmethod
|
||||
def pay(invoice: Invoice, paid_out_of_band: bool = False) -> Invoice: ...
|
||||
@staticmethod
|
||||
def void_invoice(id: str) -> None: ...
|
||||
def get(self, key: str) -> Any: ...
|
||||
def refresh(self, invoice: Invoice) -> Invoice: ...
|
||||
|
||||
class Subscription:
|
||||
created: int
|
||||
status: str
|
||||
canceled_at: int
|
||||
cancel_at_period_end: bool
|
||||
days_until_due: Optional[int]
|
||||
proration_date: int
|
||||
quantity: int
|
||||
@staticmethod
|
||||
def create(
|
||||
customer: str = ...,
|
||||
collection_method: str = ...,
|
||||
days_until_due: Optional[int] = ...,
|
||||
items: List[Dict[str, Any]] = ...,
|
||||
prorate: bool = ...,
|
||||
tax_percent: float = ...,
|
||||
) -> Subscription: ...
|
||||
@staticmethod
|
||||
def save(subscription: Subscription, idempotency_key: str = ...) -> Subscription: ...
|
||||
@staticmethod
|
||||
def delete(subscription: Subscription) -> Subscription: ...
|
||||
@staticmethod
|
||||
def retrieve(subscription_id: str) -> Subscription: ...
|
||||
|
||||
class Source:
|
||||
id: str
|
||||
object: str
|
||||
type: str
|
||||
|
||||
class Card:
|
||||
id: str
|
||||
brand: str
|
||||
last4: str
|
||||
object: str
|
||||
|
||||
class Plan:
|
||||
id: str
|
||||
@staticmethod
|
||||
def create(
|
||||
currency: str = ...,
|
||||
interval: str = ...,
|
||||
product: str = ...,
|
||||
amount: int = ...,
|
||||
billing_scheme: str = ...,
|
||||
nickname: str = ...,
|
||||
usage_type: str = ...,
|
||||
) -> Plan: ...
|
||||
|
||||
class Product:
|
||||
id: str
|
||||
@staticmethod
|
||||
def create(
|
||||
name: str = ..., type: str = ..., statement_descriptor: str = ..., unit_label: str = ...
|
||||
) -> Product: ...
|
||||
|
||||
class Discount:
|
||||
coupon: Coupon
|
||||
|
||||
class Coupon:
|
||||
id: str
|
||||
percent_off: int
|
||||
@staticmethod
|
||||
def create(duration: str = ..., name: str = ..., percent_off: int = ...) -> Coupon: ...
|
||||
|
||||
class Token:
|
||||
id: str
|
||||
@staticmethod
|
||||
def create(card: Dict[str, Any]) -> Token: ...
|
||||
|
||||
class Charge:
|
||||
amount: int
|
||||
description: str
|
||||
failure_code: str
|
||||
receipt_email: str
|
||||
source: Source
|
||||
statement_descriptor: str
|
||||
payment_method_details: PaymentMethod
|
||||
@staticmethod
|
||||
def list(customer: Optional[str]) -> List[Charge]: ...
|
||||
@staticmethod
|
||||
def create(
|
||||
amount: int = ...,
|
||||
currency: str = ...,
|
||||
customer: str = ...,
|
||||
description: str = ...,
|
||||
receipt_email: str = ...,
|
||||
statement_descriptor: str = ...,
|
||||
) -> Charge: ...
|
||||
|
||||
class InvoiceItem:
|
||||
@staticmethod
|
||||
def create(
|
||||
amount: int = ...,
|
||||
currency: str = ...,
|
||||
customer: str = ...,
|
||||
description: str = ...,
|
||||
discountable: bool = ...,
|
||||
period: Dict[str, int] = ...,
|
||||
quantity: int = ...,
|
||||
unit_amount: int = ...,
|
||||
idempotency_key: Optional[str] = ...,
|
||||
) -> InvoiceItem: ...
|
||||
@staticmethod
|
||||
def list(customer: Optional[str]) -> List[InvoiceItem]: ...
|
||||
|
||||
class InvoiceLineItem:
|
||||
amount: int
|
||||
def get(self, key: str) -> Any: ...
|
||||
|
||||
class SetupIntent:
|
||||
id: str
|
||||
|
||||
customer: str
|
||||
metadata: Dict[str, Any]
|
||||
payment_method: str
|
||||
payment_method_types: List[str]
|
||||
usage: str
|
||||
@staticmethod
|
||||
def create(
|
||||
confirm: bool = ...,
|
||||
usage: str = ...,
|
||||
customer: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
payment_method: Optional[str] = None,
|
||||
payment_method_types: List[str] = ...,
|
||||
) -> SetupIntent: ...
|
||||
@staticmethod
|
||||
def list(limit: int = ...) -> List[SetupIntent]: ...
|
||||
@staticmethod
|
||||
def retrieve(setup_intent_id: str, expand: Optional[List[str]] = ...) -> SetupIntent: ...
|
||||
|
||||
PaymentIntentStatuses = Literal[
|
||||
"requires_payment_method",
|
||||
"requires_confirmation",
|
||||
"requires_action",
|
||||
"processing",
|
||||
"requires_capture",
|
||||
"canceled",
|
||||
"succeeded",
|
||||
]
|
||||
|
||||
class LastPaymentError:
|
||||
def get(self, key: Literal["code", "message", "type", "param"]) -> Optional[str]: ...
|
||||
|
||||
class PaymentIntent:
|
||||
id: str
|
||||
amount: int
|
||||
charges: List[Charge]
|
||||
customer: str
|
||||
metadata: Dict[str, str]
|
||||
status: PaymentIntentStatuses
|
||||
last_payment_error: LastPaymentError
|
||||
@staticmethod
|
||||
def create(
|
||||
amount: int,
|
||||
currency: str,
|
||||
confirm: bool = ...,
|
||||
customer: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
payment_method: Optional[str] = None,
|
||||
off_session: Optional[bool] = None,
|
||||
receipt_email: Optional[str] = None,
|
||||
statement_descriptor: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
) -> PaymentMethod: ...
|
||||
@staticmethod
|
||||
def confirm(
|
||||
payment_intent_id: str,
|
||||
payment_method: Optional[str] = None,
|
||||
off_session: Optional[bool] = None,
|
||||
) -> PaymentIntent: ...
|
||||
@staticmethod
|
||||
def list(limit: int = ...) -> List[PaymentIntent]: ...
|
||||
@staticmethod
|
||||
def retrieve(payment_intent_id: str) -> PaymentIntent: ...
|
||||
|
||||
PaymentMethodTypes = Literal[
|
||||
"acss_debit",
|
||||
"afterpay_clearpay",
|
||||
"alipay",
|
||||
"au_becs_debit",
|
||||
"bacs_debit",
|
||||
"bancontact",
|
||||
"boleto",
|
||||
"card",
|
||||
"eps",
|
||||
"fpx",
|
||||
"giropay",
|
||||
"grabpay",
|
||||
"ideal",
|
||||
"oxxo",
|
||||
"p24",
|
||||
"sepa_debit",
|
||||
"sofort",
|
||||
"wechat_pay",
|
||||
]
|
||||
|
||||
class PaymentMethod:
|
||||
id: str
|
||||
status: str
|
||||
card: Card
|
||||
type: PaymentMethodTypes
|
||||
@staticmethod
|
||||
def create(
|
||||
type: PaymentMethodTypes, card: Optional[Dict[str, Any]] = None
|
||||
) -> PaymentMethod: ...
|
||||
@staticmethod
|
||||
def detach(payment_method_id: str) -> PaymentMethod: ...
|
||||
@staticmethod
|
||||
def list(customer: Customer, type: str, limit: int = ...) -> List[PaymentMethod]: ...
|
||||
|
||||
EventTypes = Literal[
|
||||
"checkout.session.completed", "payment_intent.succeeded", "payment_intent.payment_failed"
|
||||
]
|
||||
|
||||
class EventData:
|
||||
object: Union[Session, PaymentIntent]
|
||||
|
||||
class Event:
|
||||
id: str
|
||||
api_version: str
|
||||
type: EventTypes
|
||||
data: EventData
|
||||
@staticmethod
|
||||
def construct_from(values: Dict[Any, Any], key: Optional[str]) -> Event: ...
|
||||
@staticmethod
|
||||
def list(limit: int = ..., ending_before: Optional[Event] = None) -> List[Event]: ...
|
||||
def to_dict_recursive(self) -> Dict[str, Any]: ...
|
||||
|
||||
class Webhook:
|
||||
@staticmethod
|
||||
def construct_event(payload: bytes, request_signature: str, webhook_secret: str) -> Event: ...
|
|
@ -1,6 +0,0 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
class APIRequestor:
|
||||
def interpret_response(
|
||||
self, http_body: str, http_status: int, http_headers: Dict[str, Any]
|
||||
) -> None: ...
|
|
@ -1,7 +0,0 @@
|
|||
from typing import Any, Dict, Iterator, List, Optional
|
||||
|
||||
from stripe import Subscription
|
||||
|
||||
class SubscriptionListObject:
|
||||
data: List[Subscription]
|
||||
def __iter__(self) -> Iterator[Subscription]: ...
|
|
@ -1,22 +0,0 @@
|
|||
from typing import Any, Dict, List, Optional
|
||||
|
||||
class Session:
|
||||
id: str
|
||||
|
||||
customer: str
|
||||
metadata: Dict[str, Any]
|
||||
setup_intent: str
|
||||
url: str
|
||||
@staticmethod
|
||||
def create(
|
||||
cancel_url: str,
|
||||
success_url: str,
|
||||
mode: str,
|
||||
payment_method_types: List[str],
|
||||
customer: Optional[str] = None,
|
||||
metadata: Optional[Dict[str, Any]] = None,
|
||||
setup_intent_data: Optional[Dict[str, Any]] = None,
|
||||
) -> Session: ...
|
||||
@staticmethod
|
||||
def list(limit: int = ...) -> List[Session]: ...
|
||||
def to_dict_recursive(self) -> Dict[str, Any]: ...
|
|
@ -1,59 +0,0 @@
|
|||
from typing import Any, Dict, Optional
|
||||
|
||||
# List of StripeError's from https://stripe.com/docs/api/python#error_handling
|
||||
# and https://github.com/stripe/stripe-python/blob/master/stripe/error.py
|
||||
|
||||
class StripeError(Exception):
|
||||
def __init__(
|
||||
self,
|
||||
message: Optional[str] = None,
|
||||
http_body: Optional[str] = None,
|
||||
http_status: Optional[int] = None,
|
||||
json_body: Optional[Dict[str, Any]] = None,
|
||||
headers: Optional[Dict[str, Any]] = None,
|
||||
code: Optional[str] = None,
|
||||
) -> None: ...
|
||||
http_status: str
|
||||
json_body: Dict[str, Any]
|
||||
|
||||
class CardError(StripeError):
|
||||
def __init__(
|
||||
self,
|
||||
message: str,
|
||||
param: str,
|
||||
code: str,
|
||||
http_body: Optional[str] = None,
|
||||
http_status: Optional[int] = None,
|
||||
json_body: Optional[Dict[str, Any]] = None,
|
||||
headers: Optional[Dict[str, Any]] = None,
|
||||
) -> None: ...
|
||||
|
||||
class RateLimitError(StripeError): ...
|
||||
|
||||
class InvalidRequestError(StripeError):
|
||||
def __init__(
|
||||
self,
|
||||
message: str,
|
||||
param: str,
|
||||
code: str,
|
||||
http_body: Optional[str] = None,
|
||||
http_status: Optional[int] = None,
|
||||
json_body: Optional[Dict[str, Any]] = None,
|
||||
headers: Optional[Dict[str, Any]] = None,
|
||||
) -> None: ...
|
||||
|
||||
class AuthenticationError(StripeError): ...
|
||||
|
||||
class APIConnectionError(StripeError):
|
||||
def __init__(
|
||||
self,
|
||||
message: Optional[str] = None,
|
||||
http_body: Optional[str] = None,
|
||||
http_status: Optional[int] = None,
|
||||
json_body: Optional[Dict[str, Any]] = None,
|
||||
headers: Optional[Dict[str, Any]] = None,
|
||||
code: Optional[str] = None,
|
||||
should_retry: bool = False,
|
||||
) -> None: ...
|
||||
|
||||
class SignatureVerificationError(StripeError): ...
|
|
@ -1,3 +0,0 @@
|
|||
from typing import Any, Dict
|
||||
|
||||
def convert_to_stripe_object(fixture_data: Dict[Any, Any]) -> Any: ...
|
|
@ -48,4 +48,4 @@ API_FEATURE_LEVEL = 113
|
|||
# historical commits sharing the same major version, in which case a
|
||||
# minor version bump suffices.
|
||||
|
||||
PROVISION_VERSION = "170.0"
|
||||
PROVISION_VERSION = "171.0"
|
||||
|
|
Loading…
Reference in New Issue