-
Notifications
You must be signed in to change notification settings - Fork 58
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -318,6 +318,22 @@ def _attaching_is_declined(self): | |||||||
def _charging_is_declined(self): | ||||||||
return PaymentMethod._charging_is_declined(self) | ||||||||
|
||||||||
@classmethod | ||||||||
def _api_list_all(cls, url, customer=None, limit=10): | ||||||||
try: | ||||||||
if customer is not None: | ||||||||
assert type(customer) is str and customer.startswith('cus_') | ||||||||
except AssertionError: | ||||||||
raise UserError(400, 'Bad request') | ||||||||
|
||||||||
if customer: | ||||||||
Customer._api_retrieve(customer) # to return 404 if not existant | ||||||||
|
||||||||
li = super(Card, cls)._api_list_all(url, limit=limit) | ||||||||
if customer: | ||||||||
li._list = [c for c in li._list if c.customer == customer] | ||||||||
return li | ||||||||
|
||||||||
|
||||||||
class Charge(StripeObject): | ||||||||
object = 'charge' | ||||||||
|
@@ -678,6 +694,28 @@ def _api_delete(cls, id): | |||||||
schedule_webhook(Event('customer.deleted', obj)) | ||||||||
return super()._api_delete(id) | ||||||||
|
||||||||
@classmethod | ||||||||
def _api_list_sources(cls, id, object=None, limit=10): | ||||||||
print(object) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't include this in final code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||||||||
try: | ||||||||
if object is not None: | ||||||||
assert object in ('card', 'bank_account') | ||||||||
except AssertionError: | ||||||||
raise UserError(400, 'Bad request') | ||||||||
|
||||||||
obj = cls._api_retrieve(id) # return 404 if does not exist | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe so because the sources are set here: localstripe/localstripe/resources.py Line 629 in f5a2e0b
And then updated here: localstripe/localstripe/resources.py Line 739 in f5a2e0b
and: localstripe/localstripe/resources.py Line 754 in f5a2e0b
So I'm just returning that value from the customer object |
||||||||
|
||||||||
url = '/v1/customers/' + obj.id + '/sources' | ||||||||
|
||||||||
if object is 'card': | ||||||||
return Card._api_list_all(url, customer=obj.id) | ||||||||
|
||||||||
#TODO: implement bank accounts | ||||||||
if object is 'bank_account': | ||||||||
return List(url, limit=limit) | ||||||||
Comment on lines
+708
to
+715
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose to simplify all this and don't use the |
||||||||
|
||||||||
return obj.sources | ||||||||
|
||||||||
@classmethod | ||||||||
def _api_retrieve_source(cls, id, source_id, **kwargs): | ||||||||
if kwargs: | ||||||||
|
@@ -818,6 +856,9 @@ def _api_update_subscription(cls, id, subscription_id, **data): | |||||||
|
||||||||
|
||||||||
extra_apis.extend(( | ||||||||
# Retrieve list of sources: | ||||||||
('GET', '/v1/customers/{id}/sources', Customer._api_list_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}', | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
super()
is enough.Anyway, if you move this code inside the
Customer
class, you can simply callCard._api_list_all()
which is even clearer 😉