From 7ea29ccd10c7015971440e24381fab6a9f2b3638 Mon Sep 17 00:00:00 2001 From: meatherly Date: Fri, 7 Aug 2020 14:28:58 -0500 Subject: [PATCH] This is one step in fixing issue #88 It implements the /sources endpoint for a customer --- localstripe/resources.py | 11 +++++++++++ test.sh | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/localstripe/resources.py b/localstripe/resources.py index 41743c5e..4a83d8c6 100644 --- a/localstripe/resources.py +++ b/localstripe/resources.py @@ -678,6 +678,14 @@ def _api_delete(cls, id): schedule_webhook(Event('customer.deleted', obj)) return super()._api_delete(id) + @classmethod + def _api_retrieve_sources(cls, id): + # return 404 if does not exist + Customer._api_retrieve(id) + + obj = cls._api_retrieve(id) + return obj.sources + @classmethod def _api_retrieve_source(cls, id, source_id, **kwargs): if kwargs: @@ -818,6 +826,9 @@ def _api_update_subscription(cls, id, subscription_id, **data): extra_apis.extend(( + # Retrieve list of sources: + ('GET', '/v1/customers/{id}/sources', Customer._api_retrieve_sources), + # Add a source ('POST', '/v1/customers/{id}/sources', Customer._api_add_source), # Retrieve single source by id: ('GET', '/v1/customers/{id}/sources/{source_id}', diff --git a/test.sh b/test.sh index ac5d2813..8e851b9f 100755 --- a/test.sh +++ b/test.sh @@ -197,6 +197,12 @@ res=$( | grep -oE $card) [ -n "$res" ] +# observe new card in customer sources response +res=$( + curl -sSf -u $SK: $HOST/v1/customers/$cus/sources \ + | grep -oE $card) +[ -n "$res" ] + # delete the card curl -sSf -u $SK: $HOST/v1/customers/$cus/sources/$card \ -X DELETE