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

This is one step in fixing issue #88 #148

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions localstripe/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ def _api_delete(cls, id):
schedule_webhook(Event('customer.deleted', obj))
return super()._api_delete(id)

@classmethod
def _api_retrieve_sources(cls, id):
meatherly marked this conversation as resolved.
Show resolved Hide resolved
obj = cls._api_retrieve(id) # return 404 if does not exist
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this code really retrieve a list of sources that belong to a customer?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so because the sources are set here:

self.sources = List('/v1/customers/' + self.id + '/sources')

And then updated here:

obj.sources._list.append(source_obj)

and:
obj.sources._list.remove(source_obj)

So I'm just returning that value from the customer object

return obj.sources

@classmethod
def _api_retrieve_source(cls, id, source_id, **kwargs):
if kwargs:
Expand Down Expand Up @@ -818,6 +823,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" ]
meatherly marked this conversation as resolved.
Show resolved Hide resolved

# delete the card
curl -sSf -u $SK: $HOST/v1/customers/$cus/sources/$card \
-X DELETE
Expand Down