Skip to content

Commit

Permalink
Stubs for stripe (python#5770)
Browse files Browse the repository at this point in the history
A library that provides convenient access to the Stripe API from applications. 
It includes a pre-defined set of classes for API resources that initialize themselves 
dynamically from API responses.

I started with stubgen, then cleaned up to address missing functions. Testing plan 
is to keep an eye on CI and fix any issues that arise.
  • Loading branch information
exemplary-citizen authored Jul 13, 2021
1 parent 80f61d2 commit 0cd4ee3
Show file tree
Hide file tree
Showing 124 changed files with 1,403 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
"stubs/Werkzeug",
"stubs/beautifulsoup4",
"stubs/slumber",
"stubs/oauthlib"
"stubs/oauthlib",
"stubs/stripe"
],
"typeCheckingMode": "basic",
"strictListInference": true,
Expand Down
1 change: 1 addition & 0 deletions stubs/stripe/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "2.59"
22 changes: 22 additions & 0 deletions stubs/stripe/stripe/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from typing import Any

from stripe.api_resources import *
from stripe.oauth import OAuth as OAuth
from stripe.webhook import Webhook as Webhook, WebhookSignature as WebhookSignature

api_key: Any
client_id: Any
api_base: str
connect_api_base: str
upload_api_base: str
api_version: Any
verify_ssl_certs: bool
proxy: Any
default_http_client: Any
app_info: Any
enable_telemetry: bool
max_network_retries: int
ca_bundle_path: Any
log: Any

def set_app_info(name, partner_id: Any | None = ..., url: Any | None = ..., version: Any | None = ...) -> None: ...
32 changes: 32 additions & 0 deletions stubs/stripe/stripe/api_requestor.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import Any

from stripe import error as error, http_client as http_client, oauth_error as oauth_error, version as version
from stripe.multipart_data_generator import MultipartDataGenerator as MultipartDataGenerator
from stripe.stripe_response import StripeResponse as StripeResponse, StripeStreamResponse as StripeStreamResponse

class APIRequestor:
api_base: Any
api_key: Any
api_version: Any
stripe_account: Any
def __init__(
self,
key: Any | None = ...,
client: Any | None = ...,
api_base: Any | None = ...,
api_version: Any | None = ...,
account: Any | None = ...,
) -> None: ...
@classmethod
def format_app_info(cls, info): ...
def request(self, method, url, params: Any | None = ..., headers: Any | None = ...): ...
def request_stream(self, method, url, params: Any | None = ..., headers: Any | None = ...): ...
def handle_error_response(self, rbody, rcode, resp, rheaders) -> None: ...
def specific_api_error(self, rbody, rcode, resp, rheaders, error_data): ...
def specific_oauth_error(self, rbody, rcode, resp, rheaders, error_code): ...
def request_headers(self, api_key, method): ...
def request_raw(
self, method, url, params: Any | None = ..., supplied_headers: Any | None = ..., is_streaming: bool = ...
): ...
def interpret_response(self, rbody, rcode, rheaders): ...
def interpret_streaming_response(self, stream, rcode, rheaders): ...
79 changes: 79 additions & 0 deletions stubs/stripe/stripe/api_resources/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from stripe.api_resources import (
billing_portal as billing_portal,
checkout as checkout,
identity as identity,
issuing as issuing,
radar as radar,
reporting as reporting,
sigma as sigma,
terminal as terminal,
)
from stripe.api_resources.account import Account as Account
from stripe.api_resources.account_link import AccountLink as AccountLink
from stripe.api_resources.alipay_account import AlipayAccount as AlipayAccount
from stripe.api_resources.apple_pay_domain import ApplePayDomain as ApplePayDomain
from stripe.api_resources.application_fee import ApplicationFee as ApplicationFee
from stripe.api_resources.application_fee_refund import ApplicationFeeRefund as ApplicationFeeRefund
from stripe.api_resources.balance import Balance as Balance
from stripe.api_resources.balance_transaction import BalanceTransaction as BalanceTransaction
from stripe.api_resources.bank_account import BankAccount as BankAccount
from stripe.api_resources.bitcoin_receiver import BitcoinReceiver as BitcoinReceiver
from stripe.api_resources.bitcoin_transaction import BitcoinTransaction as BitcoinTransaction
from stripe.api_resources.capability import Capability as Capability
from stripe.api_resources.card import Card as Card
from stripe.api_resources.charge import Charge as Charge
from stripe.api_resources.country_spec import CountrySpec as CountrySpec
from stripe.api_resources.coupon import Coupon as Coupon
from stripe.api_resources.credit_note import CreditNote as CreditNote
from stripe.api_resources.credit_note_line_item import CreditNoteLineItem as CreditNoteLineItem
from stripe.api_resources.customer import Customer as Customer
from stripe.api_resources.customer_balance_transaction import CustomerBalanceTransaction as CustomerBalanceTransaction
from stripe.api_resources.dispute import Dispute as Dispute
from stripe.api_resources.ephemeral_key import EphemeralKey as EphemeralKey
from stripe.api_resources.error_object import ErrorObject as ErrorObject, OAuthErrorObject as OAuthErrorObject
from stripe.api_resources.event import Event as Event
from stripe.api_resources.exchange_rate import ExchangeRate as ExchangeRate
from stripe.api_resources.file import File as File, FileUpload as FileUpload
from stripe.api_resources.file_link import FileLink as FileLink
from stripe.api_resources.invoice import Invoice as Invoice
from stripe.api_resources.invoice_item import InvoiceItem as InvoiceItem
from stripe.api_resources.invoice_line_item import InvoiceLineItem as InvoiceLineItem
from stripe.api_resources.issuer_fraud_record import IssuerFraudRecord as IssuerFraudRecord
from stripe.api_resources.line_item import LineItem as LineItem
from stripe.api_resources.list_object import ListObject as ListObject
from stripe.api_resources.login_link import LoginLink as LoginLink
from stripe.api_resources.mandate import Mandate as Mandate
from stripe.api_resources.order import Order as Order
from stripe.api_resources.order_return import OrderReturn as OrderReturn
from stripe.api_resources.payment_intent import PaymentIntent as PaymentIntent
from stripe.api_resources.payment_method import PaymentMethod as PaymentMethod
from stripe.api_resources.payout import Payout as Payout
from stripe.api_resources.person import Person as Person
from stripe.api_resources.plan import Plan as Plan
from stripe.api_resources.price import Price as Price
from stripe.api_resources.product import Product as Product
from stripe.api_resources.promotion_code import PromotionCode as PromotionCode
from stripe.api_resources.quote import Quote as Quote
from stripe.api_resources.recipient import Recipient as Recipient
from stripe.api_resources.recipient_transfer import RecipientTransfer as RecipientTransfer
from stripe.api_resources.refund import Refund as Refund
from stripe.api_resources.reversal import Reversal as Reversal
from stripe.api_resources.review import Review as Review
from stripe.api_resources.setup_attempt import SetupAttempt as SetupAttempt
from stripe.api_resources.setup_intent import SetupIntent as SetupIntent
from stripe.api_resources.sku import SKU as SKU
from stripe.api_resources.source import Source as Source
from stripe.api_resources.source_transaction import SourceTransaction as SourceTransaction
from stripe.api_resources.subscription import Subscription as Subscription
from stripe.api_resources.subscription_item import SubscriptionItem as SubscriptionItem
from stripe.api_resources.subscription_schedule import SubscriptionSchedule as SubscriptionSchedule
from stripe.api_resources.tax_code import TaxCode as TaxCode
from stripe.api_resources.tax_id import TaxId as TaxId
from stripe.api_resources.tax_rate import TaxRate as TaxRate
from stripe.api_resources.three_d_secure import ThreeDSecure as ThreeDSecure
from stripe.api_resources.token import Token as Token
from stripe.api_resources.topup import Topup as Topup
from stripe.api_resources.transfer import Transfer as Transfer
from stripe.api_resources.usage_record import UsageRecord as UsageRecord
from stripe.api_resources.usage_record_summary import UsageRecordSummary as UsageRecordSummary
from stripe.api_resources.webhook_endpoint import WebhookEndpoint as WebhookEndpoint
11 changes: 11 additions & 0 deletions stubs/stripe/stripe/api_resources/abstract/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from stripe.api_resources.abstract.api_resource import APIResource as APIResource
from stripe.api_resources.abstract.createable_api_resource import CreateableAPIResource as CreateableAPIResource
from stripe.api_resources.abstract.custom_method import custom_method as custom_method
from stripe.api_resources.abstract.deletable_api_resource import DeletableAPIResource as DeletableAPIResource
from stripe.api_resources.abstract.listable_api_resource import ListableAPIResource as ListableAPIResource
from stripe.api_resources.abstract.nested_resource_class_methods import (
nested_resource_class_methods as nested_resource_class_methods,
)
from stripe.api_resources.abstract.singleton_api_resource import SingletonAPIResource as SingletonAPIResource
from stripe.api_resources.abstract.updateable_api_resource import UpdateableAPIResource as UpdateableAPIResource
from stripe.api_resources.abstract.verify_mixin import VerifyMixin as VerifyMixin
12 changes: 12 additions & 0 deletions stubs/stripe/stripe/api_resources/abstract/api_resource.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Any

from stripe import api_requestor as api_requestor, error as error
from stripe.stripe_object import StripeObject as StripeObject

class APIResource(StripeObject):
@classmethod
def retrieve(cls, id, api_key: Any | None = ..., **params): ...
def refresh(self): ...
@classmethod
def class_url(cls): ...
def instance_url(self): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Any

from stripe import api_requestor as api_requestor
from stripe.api_resources.abstract.api_resource import APIResource as APIResource

class CreateableAPIResource(APIResource):
@classmethod
def create(
cls,
api_key: Any | None = ...,
idempotency_key: Any | None = ...,
stripe_version: Any | None = ...,
stripe_account: Any | None = ...,
**params,
): ...
3 changes: 3 additions & 0 deletions stubs/stripe/stripe/api_resources/abstract/custom_method.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from typing import Any

def custom_method(name, http_verb, http_path: Any | None = ..., is_streaming: bool = ...): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from stripe.api_resources.abstract.api_resource import APIResource as APIResource

class DeletableAPIResource(APIResource):
def delete(self, **params): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Any

from stripe import api_requestor as api_requestor
from stripe.api_resources.abstract.api_resource import APIResource as APIResource

class ListableAPIResource(APIResource):
@classmethod
def auto_paging_iter(cls, *args, **params): ...
@classmethod
def list(cls, api_key: Any | None = ..., stripe_version: Any | None = ..., stripe_account: Any | None = ..., **params): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import Any

from stripe import api_requestor as api_requestor

def nested_resource_class_methods(
resource, path: Any | None = ..., operations: Any | None = ..., resource_plural: Any | None = ...
): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from stripe.api_resources.abstract.api_resource import APIResource as APIResource

class SingletonAPIResource(APIResource):
@classmethod
def retrieve(cls, **params): ...
@classmethod
def class_url(cls): ...
def instance_url(self): ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from typing import Any

from stripe.api_resources.abstract.api_resource import APIResource as APIResource

class UpdateableAPIResource(APIResource):
@classmethod
def modify(cls, sid, **params): ...
def save(self, idempotency_key: Any | None = ...): ...
4 changes: 4 additions & 0 deletions stubs/stripe/stripe/api_resources/abstract/verify_mixin.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from typing import Any

class VerifyMixin:
def verify(self, idempotency_key: Any | None = ..., **params): ...
23 changes: 23 additions & 0 deletions stubs/stripe/stripe/api_resources/account.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from typing import Any

from stripe import oauth as oauth
from stripe.api_resources.abstract import (
CreateableAPIResource as CreateableAPIResource,
DeletableAPIResource as DeletableAPIResource,
ListableAPIResource as ListableAPIResource,
UpdateableAPIResource as UpdateableAPIResource,
custom_method as custom_method,
nested_resource_class_methods as nested_resource_class_methods,
)

class Account(CreateableAPIResource, DeletableAPIResource, ListableAPIResource):
OBJECT_NAME: str
def reject(self, idempotency_key: Any | None = ..., **params): ...
@classmethod
def retrieve(cls, id: Any | None = ..., api_key: Any | None = ..., **params): ...
@classmethod
def modify(cls, id: Any | None = ..., **params): ...
def instance_url(self): ...
def persons(self, **params): ...
def deauthorize(self, **params): ...
def serialize(self, previous): ...
4 changes: 4 additions & 0 deletions stubs/stripe/stripe/api_resources/account_link.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from stripe.api_resources.abstract import CreateableAPIResource as CreateableAPIResource

class AccountLink(CreateableAPIResource):
OBJECT_NAME: str
17 changes: 17 additions & 0 deletions stubs/stripe/stripe/api_resources/alipay_account.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from typing import Any

from stripe.api_resources.abstract import (
DeletableAPIResource as DeletableAPIResource,
UpdateableAPIResource as UpdateableAPIResource,
)
from stripe.api_resources.customer import Customer as Customer

class AlipayAccount(DeletableAPIResource, UpdateableAPIResource):
OBJECT_NAME: str
def instance_url(self): ...
@classmethod
def modify(cls, customer, id, **params): ...
@classmethod
def retrieve(
cls, id, api_key: Any | None = ..., stripe_version: Any | None = ..., stripe_account: Any | None = ..., **params
) -> None: ...
10 changes: 10 additions & 0 deletions stubs/stripe/stripe/api_resources/apple_pay_domain.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from stripe.api_resources.abstract import (
CreateableAPIResource as CreateableAPIResource,
DeletableAPIResource as DeletableAPIResource,
ListableAPIResource as ListableAPIResource,
)

class ApplePayDomain(CreateableAPIResource, DeletableAPIResource, ListableAPIResource):
OBJECT_NAME: str
@classmethod
def class_url(cls): ...
10 changes: 10 additions & 0 deletions stubs/stripe/stripe/api_resources/application_fee.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Any

from stripe.api_resources.abstract import (
ListableAPIResource as ListableAPIResource,
nested_resource_class_methods as nested_resource_class_methods,
)

class ApplicationFee(ListableAPIResource):
OBJECT_NAME: str
def refund(self, idempotency_key: Any | None = ..., **params): ...
12 changes: 12 additions & 0 deletions stubs/stripe/stripe/api_resources/application_fee_refund.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Any

from stripe.api_resources import ApplicationFee as ApplicationFee
from stripe.api_resources.abstract import UpdateableAPIResource as UpdateableAPIResource

class ApplicationFeeRefund(UpdateableAPIResource):
OBJECT_NAME: str
@classmethod
def modify(cls, fee, sid, **params): ...
def instance_url(self): ...
@classmethod
def retrieve(cls, id, api_key: Any | None = ..., **params) -> None: ...
4 changes: 4 additions & 0 deletions stubs/stripe/stripe/api_resources/balance.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from stripe.api_resources.abstract import SingletonAPIResource as SingletonAPIResource

class Balance(SingletonAPIResource):
OBJECT_NAME: str
4 changes: 4 additions & 0 deletions stubs/stripe/stripe/api_resources/balance_transaction.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from stripe.api_resources.abstract import ListableAPIResource as ListableAPIResource

class BalanceTransaction(ListableAPIResource):
OBJECT_NAME: str
20 changes: 20 additions & 0 deletions stubs/stripe/stripe/api_resources/bank_account.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Any

from stripe import error as error
from stripe.api_resources.abstract import (
DeletableAPIResource as DeletableAPIResource,
UpdateableAPIResource as UpdateableAPIResource,
VerifyMixin as VerifyMixin,
)
from stripe.api_resources.account import Account as Account
from stripe.api_resources.customer import Customer as Customer

class BankAccount(DeletableAPIResource, UpdateableAPIResource, VerifyMixin):
OBJECT_NAME: str
def instance_url(self): ...
@classmethod
def modify(cls, sid, **params) -> None: ...
@classmethod
def retrieve(
cls, id, api_key: Any | None = ..., stripe_version: Any | None = ..., stripe_account: Any | None = ..., **params
) -> None: ...
2 changes: 2 additions & 0 deletions stubs/stripe/stripe/api_resources/billing_portal/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from stripe.api_resources.billing_portal.configuration import Configuration as Configuration
from stripe.api_resources.billing_portal.session import Session as Session
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from stripe.api_resources.abstract import (
CreateableAPIResource as CreateableAPIResource,
ListableAPIResource as ListableAPIResource,
UpdateableAPIResource as UpdateableAPIResource,
)

class Configuration(CreateableAPIResource, ListableAPIResource, UpdateableAPIResource):
OBJECT_NAME: str
4 changes: 4 additions & 0 deletions stubs/stripe/stripe/api_resources/billing_portal/session.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from stripe.api_resources.abstract import CreateableAPIResource as CreateableAPIResource

class Session(CreateableAPIResource):
OBJECT_NAME: str
8 changes: 8 additions & 0 deletions stubs/stripe/stripe/api_resources/bitcoin_receiver.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from stripe.api_resources.abstract import ListableAPIResource as ListableAPIResource
from stripe.api_resources.customer import Customer as Customer

class BitcoinReceiver(ListableAPIResource):
OBJECT_NAME: str
def instance_url(self): ...
@classmethod
def class_url(cls): ...
4 changes: 4 additions & 0 deletions stubs/stripe/stripe/api_resources/bitcoin_transaction.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from stripe.stripe_object import StripeObject as StripeObject

class BitcoinTransaction(StripeObject):
OBJECT_NAME: str
12 changes: 12 additions & 0 deletions stubs/stripe/stripe/api_resources/capability.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Any

from stripe.api_resources.abstract import UpdateableAPIResource as UpdateableAPIResource
from stripe.api_resources.account import Account as Account

class Capability(UpdateableAPIResource):
OBJECT_NAME: str
def instance_url(self): ...
@classmethod
def modify(cls, sid, **params) -> None: ...
@classmethod
def retrieve(cls, id, api_key: Any | None = ..., **params) -> None: ...
Loading

0 comments on commit 0cd4ee3

Please sign in to comment.