Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion omise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,12 +815,19 @@ def refund(self, **kwargs):
return refund

def list_refunds(self):
"""Return all refund that belongs to the charge
"""Return all refunds that belong to the charge

:rtype: LazyCollection
"""
return LazyCollection(self._nested_object_path(Refund))

def list_events(self):
"""Return all events that belong to the charge

:rtype: LazyCollection
"""
return LazyCollection(self._nested_object_path(Event))

@classmethod
def schedule(cls):
"""Retrieve all charge schedules.
Expand Down
52 changes: 52 additions & 0 deletions omise/test/test_charge.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def _getCollectionClass(self):
from .. import Collection
return Collection

def _getLazyCollectionClass(self):
from .. import LazyCollection
return LazyCollection

def _makeOne(self):
return self._getTargetClass().from_data({
'card': {
Expand Down Expand Up @@ -851,3 +855,51 @@ def test_schedule(self, api_call):
self.assertEqual(schedules[0].start_date, '2017-06-02')
self.assertEqual(schedules[0].end_date, '2018-05-01')
self.assertRequest(api_call, 'https://api.omise.co/charges/schedules')

@mock.patch('requests.get')
def test_list_events(self, api_call):
charge = self._makeOne()
lazy_collection_class_ = self._getLazyCollectionClass()
self.mockResponse(api_call, """{
"object": "list",
"data": [
{
"object": "event",
"id": "evnt_test",
"livemode": false,
"location": "/events/evnt_test",
"webhook_deliveries": [
{
"object": "webhook_delivery",
"id": "whdl_test",
"uri": "https://www.omise.co",
"status": 200
}
],
"data": [
{
"object": "charge",
"id": "chrg_test",
"location": "/charges/chrg_test",
"amount": 100000
}
],
"key": "charge.create",
"created_at": "2021-01-29T02:05:20Z"
}
],
"limit": 20,
"offset": 0,
"total": 2,
"location": null,
"order": "chronological",
"from": "1970-01-01T00:00:00Z",
"to": "2021-02-02T03:16:57Z"
}""")

events = charge.list_events()
self.assertTrue(isinstance(events, lazy_collection_class_))

events = list(events)
self.assertTrue(events[0].id, 'evnt_test')
self.assertTrue(events[0].key, 'charge.create')