Skip to content

Commit

Permalink
Add date filter on charge list
Browse files Browse the repository at this point in the history
  • Loading branch information
AnasNaouchi committed Feb 2, 2025
1 parent 8fb13c6 commit 7e248c1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions omise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,12 +737,12 @@ def retrieve(cls, charge_id=None):
return _as_object(cls._request('get', cls._collection_path()))

@classmethod
def list(cls):
def list(cls, **kwargs):
"""Return all charges that belongs to your account
:rtype: LazyCollection
"""
return LazyCollection(cls._collection_path())
return LazyCollection(cls._collection_path(), fromDate = kwargs.pop('fromDate', None), toDate = kwargs.pop('toDate', None))

def reload(self):
"""Reload the charge details.
Expand Down Expand Up @@ -1050,9 +1050,12 @@ def schedule(self):

class LazyCollection(object):
"""Proxy class representing a lazy collection of items."""
def __init__(self, collection_path):

def __init__(self, collection_path, **kwargs):
self.collection_path = collection_path
self._exhausted = False
self.fromDate = kwargs.pop('fromDate')
self.toDate = kwargs.pop('toDate')

def __len__(self):
return self._fetch_objects(limit=1, offset=0)['total']
Expand Down Expand Up @@ -1104,14 +1107,18 @@ def _update_listing(self, data):

def _fetch_objects(self, **kwargs):
order = kwargs.pop('order', None)
fromDate = self.fromDate
toDate = self.toDate

return Request(api_secret, api_main, api_version).send(
'get',
self.collection_path,
payload={
'limit': kwargs['limit'],
'offset': kwargs['offset'],
'order': order
'order': order,
'from': fromDate,
'to': toDate
}
)

Expand Down

0 comments on commit 7e248c1

Please sign in to comment.