Skip to content

Commit

Permalink
Add explicit CRUDL method implementations and child classes
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Sep 8, 2023
1 parent 45bc31e commit ef87efd
Show file tree
Hide file tree
Showing 87 changed files with 4,944 additions and 69 deletions.
61 changes: 60 additions & 1 deletion stripe/api_resources/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from stripe.api_resources.list_object import ListObject
from stripe.stripe_object import StripeObject
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, cast
from typing_extensions import Literal
from urllib.parse import quote_plus

Expand Down Expand Up @@ -80,6 +80,65 @@ class Account(
tos_acceptance: StripeObject
type: str

@classmethod
def create(
cls,
api_key=None,
idempotency_key=None,
stripe_version=None,
stripe_account=None,
**params
) -> "Account":
return cast(
"Account",
cls._static_request(
"post",
cls.class_url(),
api_key,
idempotency_key,
stripe_version,
stripe_account,
params,
),
)

@classmethod
def _cls_delete(cls, sid, **params) -> "Account":
url = "%s/%s" % (cls.class_url(), quote_plus(sid))
return cast(
"Account",
cls._static_request("delete", url, params=params),
)

@util.class_method_variant("_cls_delete")
def delete(self, **params) -> "Account":
return self._request_and_refresh(
"delete",
self.instance_url(),
params=params,
)

@classmethod
def list(
cls, api_key=None, stripe_version=None, stripe_account=None, **params
) -> ListObject["Account"]:
result = cls._static_request(
"get",
cls.class_url(),
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
params=params,
)
if not isinstance(result, ListObject):

raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)

return result

@classmethod
def _cls_persons(
cls,
Expand Down
23 changes: 23 additions & 0 deletions stripe/api_resources/account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import absolute_import, division, print_function

from stripe.api_resources.abstract import CreateableAPIResource
from typing import cast
from typing_extensions import Literal


Expand All @@ -19,3 +20,25 @@ class AccountLink(CreateableAPIResource["AccountLink"]):
expires_at: str
object: Literal["account_link"]
url: str

@classmethod
def create(
cls,
api_key=None,
idempotency_key=None,
stripe_version=None,
stripe_account=None,
**params
) -> "AccountLink":
return cast(
"AccountLink",
cls._static_request(
"post",
cls.class_url(),
api_key,
idempotency_key,
stripe_version,
stripe_account,
params,
),
)
23 changes: 23 additions & 0 deletions stripe/api_resources/account_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from stripe.api_resources.abstract import CreateableAPIResource
from stripe.stripe_object import StripeObject
from typing import cast
from typing_extensions import Literal


Expand All @@ -25,3 +26,25 @@ class AccountSession(CreateableAPIResource["AccountSession"]):
expires_at: str
livemode: bool
object: Literal["account_session"]

@classmethod
def create(
cls,
api_key=None,
idempotency_key=None,
stripe_version=None,
stripe_account=None,
**params
) -> "AccountSession":
return cast(
"AccountSession",
cls._static_request(
"post",
cls.class_url(),
api_key,
idempotency_key,
stripe_version,
stripe_account,
params,
),
)
69 changes: 69 additions & 0 deletions stripe/api_resources/apple_pay_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
# File generated from our OpenAPI spec
from __future__ import absolute_import, division, print_function

from stripe import util
from stripe.api_resources.abstract import (
CreateableAPIResource,
DeletableAPIResource,
ListableAPIResource,
)
from stripe.api_resources.list_object import ListObject
from typing import cast
from typing_extensions import Literal
from urllib.parse import quote_plus


class ApplePayDomain(
Expand All @@ -22,6 +26,71 @@ class ApplePayDomain(
livemode: bool
object: Literal["apple_pay_domain"]

@classmethod
def create(
cls,
api_key=None,
idempotency_key=None,
stripe_version=None,
stripe_account=None,
**params
) -> "ApplePayDomain":
return cast(
"ApplePayDomain",
cls._static_request(
"post",
cls.class_url(),
api_key,
idempotency_key,
stripe_version,
stripe_account,
params,
),
)

@classmethod
def _cls_delete(cls, sid, **params) -> "ApplePayDomain":
url = "%s/%s" % (cls.class_url(), quote_plus(sid))
return cast(
"ApplePayDomain",
cls._static_request("delete", url, params=params),
)

@util.class_method_variant("_cls_delete")
def delete(self, **params) -> "ApplePayDomain":
return self._request_and_refresh(
"delete",
self.instance_url(),
params=params,
)

@classmethod
def list(
cls, api_key=None, stripe_version=None, stripe_account=None, **params
) -> ListObject["ApplePayDomain"]:
result = cls._static_request(
"get",
cls.class_url(),
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
params=params,
)
if not isinstance(result, ListObject):

raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)

return result

@classmethod
def retrieve(cls, id, api_key=None, **params) -> "ApplePayDomain":
instance = cls(id, api_key, **params)
instance.refresh()
return instance

@classmethod
def class_url(cls):
return "/v1/apple_pay/domains"
27 changes: 27 additions & 0 deletions stripe/api_resources/application_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ class ApplicationFee(ListableAPIResource["ApplicationFee"]):
refunded: bool
refunds: ListObject["ApplicationFeeRefund"]

@classmethod
def list(
cls, api_key=None, stripe_version=None, stripe_account=None, **params
) -> ListObject["ApplicationFee"]:
result = cls._static_request(
"get",
cls.class_url(),
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
params=params,
)
if not isinstance(result, ListObject):

raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)

return result

@classmethod
def _cls_refund(
cls,
Expand Down Expand Up @@ -75,3 +96,9 @@ def refund(self, idempotency_key=None, **params):
idempotency_key=idempotency_key,
params=params,
)

@classmethod
def retrieve(cls, id, api_key=None, **params) -> "ApplicationFee":
instance = cls(id, api_key, **params)
instance.refresh()
return instance
46 changes: 45 additions & 1 deletion stripe/api_resources/apps/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
CreateableAPIResource,
ListableAPIResource,
)
from stripe.api_resources.list_object import ListObject
from stripe.stripe_object import StripeObject
from typing import Optional
from typing import Optional, cast
from typing_extensions import Literal


Expand Down Expand Up @@ -35,6 +36,28 @@ class Secret(CreateableAPIResource["Secret"], ListableAPIResource["Secret"]):
payload: Optional[str]
scope: StripeObject

@classmethod
def create(
cls,
api_key=None,
idempotency_key=None,
stripe_version=None,
stripe_account=None,
**params
) -> "Secret":
return cast(
"Secret",
cls._static_request(
"post",
cls.class_url(),
api_key,
idempotency_key,
stripe_version,
stripe_account,
params,
),
)

@classmethod
def delete_where(
cls, api_key=None, stripe_version=None, stripe_account=None, **params
Expand All @@ -60,3 +83,24 @@ def find(
stripe_account=stripe_account,
params=params,
)

@classmethod
def list(
cls, api_key=None, stripe_version=None, stripe_account=None, **params
) -> ListObject["Secret"]:
result = cls._static_request(
"get",
cls.class_url(),
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
params=params,
)
if not isinstance(result, ListObject):

raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)

return result
6 changes: 6 additions & 0 deletions stripe/api_resources/balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Balance(SingletonAPIResource["Balance"]):
object: Literal["balance"]
pending: List[StripeObject]

@classmethod
def retrieve(cls, **params) -> "Balance":
instance = cls(None, **params)
instance.refresh()
return instance

@classmethod
def class_url(cls):
return "/v1/balance"
28 changes: 28 additions & 0 deletions stripe/api_resources/balance_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from stripe.api_resources.abstract import ListableAPIResource
from stripe.api_resources.expandable_field import ExpandableField
from stripe.api_resources.list_object import ListObject
from stripe.stripe_object import StripeObject
from typing import Any, List, Optional
from typing_extensions import Literal
Expand Down Expand Up @@ -33,3 +34,30 @@ class BalanceTransaction(ListableAPIResource["BalanceTransaction"]):
source: Optional[ExpandableField[Any]]
status: str
type: str

@classmethod
def list(
cls, api_key=None, stripe_version=None, stripe_account=None, **params
) -> ListObject["BalanceTransaction"]:
result = cls._static_request(
"get",
cls.class_url(),
api_key=api_key,
stripe_version=stripe_version,
stripe_account=stripe_account,
params=params,
)
if not isinstance(result, ListObject):

raise TypeError(
"Expected list object from API, got %s"
% (type(result).__name__)
)

return result

@classmethod
def retrieve(cls, id, api_key=None, **params) -> "BalanceTransaction":
instance = cls(id, api_key, **params)
instance.refresh()
return instance
Loading

0 comments on commit ef87efd

Please sign in to comment.