Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta: codegenned async methods on resources #1171

Merged
merged 9 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
526 changes: 524 additions & 2 deletions stripe/_account.py

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions stripe/_account_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,19 @@ def create(
params=params,
),
)

@classmethod
async def create_async(
cls, **params: Unpack["AccountLink.CreateParams"]
) -> "AccountLink":
"""
Creates an AccountLink object that includes a single-use Stripe URL that the platform can redirect their user to in order to take them through the Connect Onboarding flow.
"""
return cast(
"AccountLink",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)
49 changes: 49 additions & 0 deletions stripe/_account_notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,27 @@ def list(

return result

@classmethod
async def list_async(
cls, **params: Unpack["AccountNotice.ListParams"]
) -> ListObject["AccountNotice"]:
"""
Retrieves a list of AccountNotice objects. The objects are sorted in descending order by creation date, with the most-recently-created object appearing first.
"""
result = await cls._static_request_async(
"get",
cls.class_url(),
params=params,
)
if not isinstance(result, ListObject):

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

return result

@classmethod
def modify(
cls, id: str, **params: Unpack["AccountNotice.ModifyParams"]
Expand All @@ -200,6 +221,23 @@ def modify(
),
)

@classmethod
async def modify_async(
cls, id: str, **params: Unpack["AccountNotice.ModifyParams"]
) -> "AccountNotice":
"""
Updates an AccountNotice object.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(id))
return cast(
"AccountNotice",
await cls._static_request_async(
"post",
url,
params=params,
),
)

@classmethod
def retrieve(
cls, id: str, **params: Unpack["AccountNotice.RetrieveParams"]
Expand All @@ -211,4 +249,15 @@ def retrieve(
instance.refresh()
return instance

@classmethod
async def retrieve_async(
cls, id: str, **params: Unpack["AccountNotice.RetrieveParams"]
) -> "AccountNotice":
"""
Retrieves an AccountNotice object.
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance

_inner_class_types = {"email": Email, "linked_objects": LinkedObjects}
16 changes: 16 additions & 0 deletions stripe/_account_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,20 @@ def create(
),
)

@classmethod
async def create_async(
cls, **params: Unpack["AccountSession.CreateParams"]
) -> "AccountSession":
"""
Creates a AccountSession object that includes a single-use token that the platform can use on their front-end to grant client-side API access.
"""
return cast(
"AccountSession",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)

_inner_class_types = {"components": Components}
97 changes: 97 additions & 0 deletions stripe/_apple_pay_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ def create(
),
)

@classmethod
async def create_async(
cls, **params: Unpack["ApplePayDomain.CreateParams"]
) -> "ApplePayDomain":
"""
Create an apple pay domain.
"""
return cast(
"ApplePayDomain",
await cls._static_request_async(
"post",
cls.class_url(),
params=params,
),
)

@classmethod
def _cls_delete(
cls, sid: str, **params: Unpack["ApplePayDomain.DeleteParams"]
Expand Down Expand Up @@ -139,6 +155,55 @@ def delete( # pyright: ignore[reportGeneralTypeIssues]
params=params,
)

@classmethod
async def _cls_delete_async(
cls, sid: str, **params: Unpack["ApplePayDomain.DeleteParams"]
) -> "ApplePayDomain":
"""
Delete an apple pay domain.
"""
url = "%s/%s" % (cls.class_url(), sanitize_id(sid))
return cast(
"ApplePayDomain",
await cls._static_request_async(
"delete",
url,
params=params,
),
)

@overload
@staticmethod
async def delete_async(
sid: str, **params: Unpack["ApplePayDomain.DeleteParams"]
) -> "ApplePayDomain":
"""
Delete an apple pay domain.
"""
...

@overload
async def delete_async(
self, **params: Unpack["ApplePayDomain.DeleteParams"]
) -> "ApplePayDomain":
"""
Delete an apple pay domain.
"""
...

@class_method_variant("_cls_delete_async")
async def delete_async( # pyright: ignore[reportGeneralTypeIssues]
self, **params: Unpack["ApplePayDomain.DeleteParams"]
) -> "ApplePayDomain":
"""
Delete an apple pay domain.
"""
return await self._request_and_refresh_async(
"delete",
self.instance_url(),
params=params,
)

@classmethod
def list(
cls, **params: Unpack["ApplePayDomain.ListParams"]
Expand All @@ -160,6 +225,27 @@ def list(

return result

@classmethod
async def list_async(
cls, **params: Unpack["ApplePayDomain.ListParams"]
) -> ListObject["ApplePayDomain"]:
"""
List apple pay domains.
"""
result = await cls._static_request_async(
"get",
cls.class_url(),
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: str, **params: Unpack["ApplePayDomain.RetrieveParams"]
Expand All @@ -171,6 +257,17 @@ def retrieve(
instance.refresh()
return instance

@classmethod
async def retrieve_async(
cls, id: str, **params: Unpack["ApplePayDomain.RetrieveParams"]
) -> "ApplePayDomain":
"""
Retrieve an apple pay domain.
"""
instance = cls(id, **params)
await instance.refresh_async()
return instance

@classmethod
def class_url(cls):
return "/v1/apple_pay/domains"
Loading
Loading