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

API Updates #738

Merged
merged 4 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 12 additions & 0 deletions stripe/api_resources/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"],
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions tests/api_resources/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
7 changes: 7 additions & 0 deletions tests/test_generated_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)