Skip to content

Commit

Permalink
This is one step in fixing issue adrienverge#88
Browse files Browse the repository at this point in the history
It implements the /sources endpoint for a customer
  • Loading branch information
meatherly committed Aug 7, 2020
1 parent f0a9400 commit 7ea29cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions localstripe/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}',
Expand Down
6 changes: 6 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ea29cc

Please sign in to comment.