diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index c2747e4dc..8451b37db 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -62,7 +62,7 @@ jobs: # not fully supported by github actions yet, as of Feb 2021 # https://github.com/actions/cache/issues/81 - name: Start stripe-mock - run: docker run -d -p 12111-12112:12111-12112 stripemock/stripe-mock && sleep 5 + run: docker run -d -p 12111-12112:12111-12112 stripe/stripe-mock && sleep 5 - name: Test with pytest run: make test diff --git a/stripe/api_resources/customer.py b/stripe/api_resources/customer.py index e1fba5790..c0692c494 100644 --- a/stripe/api_resources/customer.py +++ b/stripe/api_resources/customer.py @@ -2,6 +2,7 @@ from __future__ import absolute_import, division, print_function from stripe import api_requestor +from stripe import util from stripe.api_resources.abstract import CreateableAPIResource from stripe.api_resources.abstract import DeletableAPIResource from stripe.api_resources.abstract import ListableAPIResource @@ -11,6 +12,11 @@ @custom_method("delete_discount", http_verb="delete", http_path="discount") +@custom_method( + "list_payment_methods", + http_verb="get", + http_path="payment_methods", +) @nested_resource_class_methods( "balance_transaction", operations=["create", "retrieve", "update", "list"], @@ -31,6 +37,12 @@ class Customer( ): OBJECT_NAME = "customer" + def list_payment_methods(self, idempotency_key=None, **params): + url = self.instance_url() + "/payment_methods" + headers = util.populate_headers(idempotency_key) + self.refresh_from(self.request("get", url, params, headers)) + return self + def delete_discount(self, **params): requestor = api_requestor.APIRequestor( self.api_key, diff --git a/tests/api_resources/test_customer.py b/tests/api_resources/test_customer.py index 49a67f07f..ad11acbe9 100644 --- a/tests/api_resources/test_customer.py +++ b/tests/api_resources/test_customer.py @@ -171,3 +171,11 @@ def test_is_listable(self, request_mock): "get", "/v1/customers/%s/balance_transactions" % TEST_RESOURCE_ID ) assert isinstance(resources.data, list) + + +class TestCustomerPaymentMethods(object): + def test_is_listable(self, request_mock): + stripe.Customer.list_payment_methods(TEST_RESOURCE_ID, type="card") + request_mock.assert_requested( + "get", "/v1/customers/%s/payment_methods" % TEST_RESOURCE_ID + ) diff --git a/tests/test_generated_examples.py b/tests/test_generated_examples.py index d9bff89d7..886548efc 100644 --- a/tests/test_generated_examples.py +++ b/tests/test_generated_examples.py @@ -1019,3 +1019,10 @@ def test_webhookendpoint_delete(self, request_mock): "delete", "/v1/webhook_endpoints/we_xxxxxxxxxxxxx", ) + + def test_customer_list_payment_methods(self, request_mock): + stripe.Customer.list_payment_methods("cus_xyz", type="card") + request_mock.assert_requested( + "get", + "/v1/customers/cus_xyz/payment_methods", + )