Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Charge: Add customer and created to the list API
Browse files Browse the repository at this point in the history
  • Loading branch information
H--o-l committed Jun 2, 2020
1 parent e1a9580 commit 54831f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions localstripe/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,34 @@ def amount_refunded(self):
def refunded(self):
return self.amount <= self.amount_refunded

@classmethod
def _api_list_all(cls, url, customer=None, created=None, limit=10):
try:
assert _type(customer) is str and customer.startswith('cus_')
assert type(created) in (dict, str)
if type(created) is dict:
assert len(created.keys()) == 1 and \
list(created.keys())[0] in ('gt', 'gte', 'lt', 'lte')
date = try_convert_to_int(list(created.values())[0])
elif type(created) is str:
date = try_convert_to_int(created)
assert type(date) is int and date > 1500000000
except AssertionError:
raise UserError(400, 'Bad request')

Customer._api_retrieve(customer) # to return 404 if not existant

if created:
if type(created) is str or not created.get('gt'):
raise UserError(500, 'Not implemented')

li = super(Charge, cls)._api_list_all(url, limit=limit)
li._list = [c for c in li._list if c.customer == customer]
if created.get('gt'):
li._list = [c for c in li._list
if c.created > try_convert_to_int(created['gt'])]
return li


extra_apis.append((
('POST', '/v1/charges/{id}/capture', Charge._api_capture)))
Expand Down
6 changes: 6 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -754,3 +754,9 @@ status=$(
curl -sSf -u $SK: $HOST/v1/charges/$charge \
| grep -oE '"status": "failed"')
[ -n "$status" ]

# list charges
total_count=$(
curl -sSf -u $SK: $HOST/v1/charges?customer=$cus\&created%5Bgt%5D=1588166306 \
| grep -oE '"total_count": 6')
[ -n "$total_count" ]

0 comments on commit 54831f9

Please sign in to comment.