diff --git a/localstripe/resources.py b/localstripe/resources.py index 95efb196..3f412555 100644 --- a/localstripe/resources.py +++ b/localstripe/resources.py @@ -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))) diff --git a/test.sh b/test.sh index c8457d54..1a80363a 100755 --- a/test.sh +++ b/test.sh @@ -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" ]