From 4047dca195c8afbb7e55570926e0187aa80a1822 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 28 Mar 2022 10:14:08 -0700 Subject: [PATCH 1/3] Codegen for openapi 2956fca --- stripe/api_resources/charge.py | 14 +++++++++++++- stripe/api_resources/customer.py | 10 ++++++++++ stripe/api_resources/invoice.py | 10 ++++++++++ stripe/api_resources/payment_intent.py | 12 ++++++++++++ stripe/api_resources/price.py | 16 +++++++++++++++- stripe/api_resources/product.py | 10 ++++++++++ stripe/api_resources/subscription.py | 12 ++++++++++++ 7 files changed, 82 insertions(+), 2 deletions(-) diff --git a/stripe/api_resources/charge.py b/stripe/api_resources/charge.py index d77411f6c..d8562b7dd 100644 --- a/stripe/api_resources/charge.py +++ b/stripe/api_resources/charge.py @@ -5,13 +5,17 @@ from stripe import util from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import SearchableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import custom_method @custom_method("capture", http_verb="post") class Charge( - CreateableAPIResource, ListableAPIResource, UpdateableAPIResource + CreateableAPIResource, + ListableAPIResource, + SearchableAPIResource, + UpdateableAPIResource, ): OBJECT_NAME = "charge" @@ -21,6 +25,14 @@ def capture(self, idempotency_key=None, **params): self.refresh_from(self.request("post", url, params, headers)) return self + @classmethod + def search(cls, *args, **kwargs): + return cls._search(search_url="/v1/charges/search", *args, **kwargs) + + @classmethod + def search_auto_paging_iter(cls, *args, **kwargs): + return cls.search(*args, **kwargs).auto_paging_iter() + def refund(self, idempotency_key=None, **params): url = self.instance_url() + "/refund" headers = util.populate_headers(idempotency_key) diff --git a/stripe/api_resources/customer.py b/stripe/api_resources/customer.py index 5aab5b69c..81682cec3 100644 --- a/stripe/api_resources/customer.py +++ b/stripe/api_resources/customer.py @@ -6,6 +6,7 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import SearchableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import custom_method from stripe.api_resources.abstract import nested_resource_class_methods @@ -33,6 +34,7 @@ class Customer( CreateableAPIResource, DeletableAPIResource, ListableAPIResource, + SearchableAPIResource, UpdateableAPIResource, ): OBJECT_NAME = "customer" @@ -45,6 +47,14 @@ def list_payment_methods(self, idempotency_key=None, **params): stripe_object._retrieve_params = params return stripe_object + @classmethod + def search(cls, *args, **kwargs): + return cls._search(search_url="/v1/customers/search", *args, **kwargs) + + @classmethod + def search_auto_paging_iter(cls, *args, **kwargs): + return cls.search(*args, **kwargs).auto_paging_iter() + def delete_discount(self, **params): requestor = api_requestor.APIRequestor( self.api_key, diff --git a/stripe/api_resources/invoice.py b/stripe/api_resources/invoice.py index cd0e43e6a..25ad9d6ad 100644 --- a/stripe/api_resources/invoice.py +++ b/stripe/api_resources/invoice.py @@ -6,6 +6,7 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import SearchableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import custom_method @@ -19,6 +20,7 @@ class Invoice( CreateableAPIResource, DeletableAPIResource, ListableAPIResource, + SearchableAPIResource, UpdateableAPIResource, ): OBJECT_NAME = "invoice" @@ -53,6 +55,14 @@ def void_invoice(self, idempotency_key=None, **params): self.refresh_from(self.request("post", url, params, headers)) return self + @classmethod + def search(cls, *args, **kwargs): + return cls._search(search_url="/v1/invoices/search", *args, **kwargs) + + @classmethod + def search_auto_paging_iter(cls, *args, **kwargs): + return cls.search(*args, **kwargs).auto_paging_iter() + @classmethod def upcoming( cls, api_key=None, stripe_version=None, stripe_account=None, **params diff --git a/stripe/api_resources/payment_intent.py b/stripe/api_resources/payment_intent.py index 2eabb0283..26b7be1b7 100644 --- a/stripe/api_resources/payment_intent.py +++ b/stripe/api_resources/payment_intent.py @@ -4,6 +4,7 @@ from stripe import util from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import SearchableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import custom_method @@ -15,6 +16,7 @@ class PaymentIntent( CreateableAPIResource, ListableAPIResource, + SearchableAPIResource, UpdateableAPIResource, ): OBJECT_NAME = "payment_intent" @@ -42,3 +44,13 @@ def verify_microdeposits(self, idempotency_key=None, **params): headers = util.populate_headers(idempotency_key) self.refresh_from(self.request("post", url, params, headers)) return self + + @classmethod + def search(cls, *args, **kwargs): + return cls._search( + search_url="/v1/payment_intents/search", *args, **kwargs + ) + + @classmethod + def search_auto_paging_iter(cls, *args, **kwargs): + return cls.search(*args, **kwargs).auto_paging_iter() diff --git a/stripe/api_resources/price.py b/stripe/api_resources/price.py index 132d5db3f..775037f76 100644 --- a/stripe/api_resources/price.py +++ b/stripe/api_resources/price.py @@ -3,8 +3,22 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import SearchableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource -class Price(CreateableAPIResource, ListableAPIResource, UpdateableAPIResource): +class Price( + CreateableAPIResource, + ListableAPIResource, + SearchableAPIResource, + UpdateableAPIResource, +): OBJECT_NAME = "price" + + @classmethod + def search(cls, *args, **kwargs): + return cls._search(search_url="/v1/prices/search", *args, **kwargs) + + @classmethod + def search_auto_paging_iter(cls, *args, **kwargs): + return cls.search(*args, **kwargs).auto_paging_iter() diff --git a/stripe/api_resources/product.py b/stripe/api_resources/product.py index 51c30a4e9..b345b7eeb 100644 --- a/stripe/api_resources/product.py +++ b/stripe/api_resources/product.py @@ -4,6 +4,7 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import SearchableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource @@ -11,6 +12,15 @@ class Product( CreateableAPIResource, DeletableAPIResource, ListableAPIResource, + SearchableAPIResource, UpdateableAPIResource, ): OBJECT_NAME = "product" + + @classmethod + def search(cls, *args, **kwargs): + return cls._search(search_url="/v1/products/search", *args, **kwargs) + + @classmethod + def search_auto_paging_iter(cls, *args, **kwargs): + return cls.search(*args, **kwargs).auto_paging_iter() diff --git a/stripe/api_resources/subscription.py b/stripe/api_resources/subscription.py index afb2386ed..6e93c99df 100644 --- a/stripe/api_resources/subscription.py +++ b/stripe/api_resources/subscription.py @@ -5,6 +5,7 @@ from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import ListableAPIResource +from stripe.api_resources.abstract import SearchableAPIResource from stripe.api_resources.abstract import UpdateableAPIResource from stripe.api_resources.abstract import custom_method @@ -14,10 +15,21 @@ class Subscription( CreateableAPIResource, DeletableAPIResource, ListableAPIResource, + SearchableAPIResource, UpdateableAPIResource, ): OBJECT_NAME = "subscription" + @classmethod + def search(cls, *args, **kwargs): + return cls._search( + search_url="/v1/subscriptions/search", *args, **kwargs + ) + + @classmethod + def search_auto_paging_iter(cls, *args, **kwargs): + return cls.search(*args, **kwargs).auto_paging_iter() + def delete_discount(self, **params): requestor = api_requestor.APIRequestor( self.api_key, From da0ff1f28e9ced3e37e2b60bee7f8abcba268a44 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 28 Mar 2022 10:45:53 -0700 Subject: [PATCH 2/3] test and total_count --- tests/api_resources/test_charge.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/api_resources/test_charge.py b/tests/api_resources/test_charge.py index 978a17cc3..d68b83dc0 100644 --- a/tests/api_resources/test_charge.py +++ b/tests/api_resources/test_charge.py @@ -13,6 +13,20 @@ def test_is_listable(self, request_mock): assert isinstance(resources.data, list) assert isinstance(resources.data[0], stripe.Charge) + def test_is_searchable(self, request_mock): + resources = stripe.Charge.search(query="currency:\"USD\"") + request_mock.assert_requested("get", "/v1/charges/search", {'query': 'currency:"USD"'}) + assert resources.total_count == 1 + assert isinstance(resources.data, list) + assert isinstance(resources.data[0], stripe.Charge) + + cnt = 0 + for c in resources.auto_paging_iter(): + assert isinstance(c, stripe.Charge) + cnt += 1 + + assert cnt == 1 + def test_is_retrievable(self, request_mock): resource = stripe.Charge.retrieve(TEST_RESOURCE_ID) request_mock.assert_requested( From 2bb7fc062c6e5f679e2c0112c803be87b590ab30 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 28 Mar 2022 10:55:24 -0700 Subject: [PATCH 3/3] fmt --- tests/api_resources/test_charge.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/api_resources/test_charge.py b/tests/api_resources/test_charge.py index d68b83dc0..290774358 100644 --- a/tests/api_resources/test_charge.py +++ b/tests/api_resources/test_charge.py @@ -14,8 +14,10 @@ def test_is_listable(self, request_mock): assert isinstance(resources.data[0], stripe.Charge) def test_is_searchable(self, request_mock): - resources = stripe.Charge.search(query="currency:\"USD\"") - request_mock.assert_requested("get", "/v1/charges/search", {'query': 'currency:"USD"'}) + resources = stripe.Charge.search(query='currency:"USD"') + request_mock.assert_requested( + "get", "/v1/charges/search", {"query": 'currency:"USD"'} + ) assert resources.total_count == 1 assert isinstance(resources.data, list) assert isinstance(resources.data[0], stripe.Charge)